Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
matherg committed Dec 10, 2024
1 parent 915cda9 commit 9615fb9
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 112 deletions.
2 changes: 1 addition & 1 deletion src/components/Group/GroupMemberCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const GroupMembers = (props: GroupMembersProps) => {
return <Spinner />;
}

const handleDelete = (id: string) => {
const handleDelete = () => {
if (driver.carpoolId) {
deleteGroup({ groupId: driver.carpoolId });
} else {
Expand Down
46 changes: 26 additions & 20 deletions src/components/GroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ interface NoGroupInfoProps {
onClose: () => void;
}

const NoGroupInfo = ({ role, onClose }: NoGroupInfoProps) => {
const NoGroupInfo = ({ role }: NoGroupInfoProps) => {
const utils = trpc.useContext();
const { data: user } = trpc.user.me.useQuery();
const [groupMessage, setGroupMessage] = useState(user?.groupMessage ?? "");
const { mutate: updateUserMessage } = trpc.user.groups.updateUserMessage.useMutation({
onSuccess: () => {
// Invalidate and refetch the user.me query
utils.user.me.invalidate();
},
});
const { mutate: updateUserMessage } =
trpc.user.groups.updateUserMessage.useMutation({
onSuccess: () => {
// Invalidate and refetch the user.me query
utils.user.me.invalidate();
},
});

useEffect(() => {
if (user?.groupMessage) {
Expand All @@ -94,9 +95,13 @@ const NoGroupInfo = ({ role, onClose }: NoGroupInfoProps) => {
) : (
<>
{role === "DRIVER" && (
<div className="mx-20 flex flex-col py-1 mb-8">
<div className="mx-20 mb-8 flex flex-col py-1">
<div className="my-1 text-xs italic text-slate-400">
Below, share any information that you would like riders joining you your Carpool to know. You can indicate when you generally like to be leaving your place, what your preferred method of communication is, what your preference is to split gas and what your Carpool vibe will be like.
Below, share any information that you would like riders joining
you your Carpool to know. You can indicate when you generally
like to be leaving your place, what your preferred method of
communication is, what your preference is to split gas and what
your Carpool vibe will be like.
</div>
<div className="flex flex-row gap-2">
<textarea
Expand All @@ -105,10 +110,10 @@ const NoGroupInfo = ({ role, onClose }: NoGroupInfoProps) => {
onChange={(e) => setGroupMessage(e.target.value)}
/>
<button
className="w-[150px] rounded-md bg-red-700 py-2 text-white h-full"
className="h-full w-[150px] rounded-md bg-red-700 py-2 text-white"
onClick={async () => {
await handleMessageSubmit();
toast.success('Group message successfully saved!');
toast.success("Group message successfully saved!");
}}
>
Submit
Expand Down Expand Up @@ -142,12 +147,13 @@ const GroupInfo = ({
utils.user.groups.me.invalidate();
},
});
const { mutate: updateUserMessage } = trpc.user.groups.updateUserMessage.useMutation({
onSuccess: () => {
// Invalidate and refetch the user.me query
utils.user.me.invalidate();
},
});
const { mutate: updateUserMessage } =
trpc.user.groups.updateUserMessage.useMutation({
onSuccess: () => {
// Invalidate and refetch the user.me query
utils.user.me.invalidate();
},
});

useEffect(() => {
if (group?.message !== undefined) {
Expand Down Expand Up @@ -180,7 +186,7 @@ const GroupInfo = ({
className="ml-8 h-full w-[150px] rounded-md bg-red-700 text-white"
onClick={async () => {
await handleMessageSubmit();
toast.success('Group message successfully saved!');
toast.success("Group message successfully saved!");
}}
>
Submit
Expand All @@ -190,7 +196,7 @@ const GroupInfo = ({
) : (
<div className="mx-16 flex flex-col py-1">
<div className="text-center">Carpool Information from Driver</div>
<br/>
<br />
<p className="flex-1 justify-center rounded-md border px-3 py-2 text-center text-sm shadow-sm">
{groupMessage != ""
? groupMessage
Expand All @@ -203,4 +209,4 @@ const GroupInfo = ({
</div>
</>
);
};
};
1 change: 0 additions & 1 deletion src/components/Map/AddressCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ interface AddressComboboxProps {
}

const AddressCombobox = ({
name,
className,
addressSelected,
addressSetter,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Messages/MessageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const MessageHeader = ({
const hasIncomingRequest = !!selectedUser.incomingRequest;
const hasOutgoingRequest = !!selectedUser.outgoingRequest;

const handleClose = (e: React.MouseEvent) => {
const handleClose = () => {
onClose("");
};
const { profileImageUrl, imageLoadError } = useProfileImage(selectedUser.id);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/ConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ConnectModal = (props: ConnectModalProps): JSX.Element => {
setIsOpen(false);
props.onClose(action);
};
const handleViewRequest = (e: React.MouseEvent) => {
const handleViewRequest = () => {
props.onViewRequest(props.otherUser.id);
props.onClose("connect");
};
Expand Down
5 changes: 1 addition & 4 deletions src/components/Profile/CarpoolSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ const CarpoolSection = ({
key={day + index.toString()}
name={`daysWorking.${index}`}
control={control}
render={({
field: { onChange, value },
formState: { defaultValues },
}) => (
render={({ field: { onChange, value } }) => (
<Checkbox
key={day + index.toString()}
sx={{
Expand Down
3 changes: 0 additions & 3 deletions src/components/Profile/ProfilePicture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ const ProfilePicture = ({ onFileSelected }: ProfilePictureProps) => {
},
[zoom, minZoom]
);
interface ModalOverlayProps {
children: ReactNode;
}

return (
<div>
Expand Down
3 changes: 1 addition & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ const Home: NextPage<any> = () => {
const [tempOtherUser, setTempOtherUser] = useState<PublicUser | null>(null);
const [tempOtherUserMarkerActive, setTempOtherUserMarkerActive] =
useState(false);
const [defaultFilters, setDefaultFilters] =
useState<FiltersState>(initialFilters);
const [defaultFilters] = useState<FiltersState>(initialFilters);
const [filters, setFilters] = useState<FiltersState>(initialFilters);
const [sort, setSort] = useState<string>("any");
const [debouncedFilters, setDebouncedFilters] = useState(filters);
Expand Down
4 changes: 2 additions & 2 deletions src/server/router/mapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const mapboxRouter = router({
autocomplete: z.literal(true),
})
)
.query(async ({ ctx, input }): Promise<FeatureCollection> => {
.query(async ({ input }): Promise<FeatureCollection> => {
const endpoint = `https://api.mapbox.com/geocoding/v5/mapbox.places/${input.value}.json?access_token=${serverEnv.NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN}&autocomplete=${input.autocomplete}&country=${input.country}&proximity=${input.proximity}&types=${input.types}`;
const data = await fetch(endpoint)
.then((response) => response.json())
Expand Down Expand Up @@ -144,7 +144,7 @@ export const mapboxRouter = router({
points: z.array(z.tuple([z.number(), z.number()])), // Array of tuples containing longitude and latitude
})
)
.query(async ({ ctx, input }): Promise<DirectionsResponse> => {
.query(async ({ input }): Promise<DirectionsResponse> => {
// Convert input to a string in the format required by the Mapbox API
const coordinates = input.points
.map(([lng, lat]) => `${lng},${lat}`)
Expand Down
4 changes: 2 additions & 2 deletions src/server/router/user/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Role } from "@prisma/client";
// Router for admin dashboard queries, only Managers can edit roles
// User must be Manager or Admin to view user data
export const adminDataRouter = router({
getAllUsers: adminRouter.query(async ({ ctx, input }) => {
getAllUsers: adminRouter.query(async ({ ctx }) => {
return ctx.prisma.user.findMany({
where: {
email: {
Expand All @@ -23,7 +23,7 @@ export const adminDataRouter = router({
},
});
}),
getCarpoolGroups: adminRouter.query(async ({ ctx, input }) => {
getCarpoolGroups: adminRouter.query(async ({ ctx }) => {
return ctx.prisma.carpoolGroup.findMany({
where: {
AND: [
Expand Down
64 changes: 6 additions & 58 deletions src/styles/profile.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,5 @@
import styled from "styled-components";

/**
* Media queries are min-width 1440, 834, and 420.
*/

export const CompleteProfileButton = styled.button`
background: #c8102e;
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
border-radius: 10px;
font-family: "Montserrat", sans-serif;
font-style: normal;
font-weight: 400;
font-size: 20px;
text-align: center;
color: #ffffff;
padding: 5px 7px 5px 7px;
width: 100%;
align-self: flex-end;
@media (min-width: 834px) {
justify-self: flex-end;
margin: 1rem 0 1rem 0;
}
`;

export const ProfileContainer = styled.form`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex: 1 1 auto;
width: 100%;
padding: 1.25rem;
@media (min-width: 834px) {
flex-direction: row;
}
`;

export const ProfileColumn = styled.div`
display: flex;
flex-direction: column;
Expand All @@ -46,17 +9,17 @@ export const ProfileColumn = styled.div`
gap: 6px;
`;

export const MiddleProfileSection = styled(ProfileColumn)`
styled(ProfileColumn)`
width: 100%;
flex: 1 1 auto;
`;

export const BottomProfileSection = styled(ProfileColumn)`
styled(ProfileColumn)`
width: 100%;
flex: 1 1 auto;
`;

export const TopProfileSection = styled(ProfileColumn)`
styled(ProfileColumn)`
width: 100%;
padding: 0 0 1rem 0;
display: flex;
Expand All @@ -65,7 +28,7 @@ export const TopProfileSection = styled(ProfileColumn)`
flex: 0 1 auto;
`;

export const PersonalInfoSection = styled(ProfileColumn)`
styled(ProfileColumn)`
width: 100%;
flex: 1 1 auto;
gap: 4px;
Expand All @@ -77,7 +40,7 @@ export const PersonalInfoSection = styled(ProfileColumn)`
padding-bottom: 12px;
`;

export const CommutingScheduleSection = styled(ProfileColumn)`
styled(ProfileColumn)`
width: 100%;
flex: 1 1 auto;
gap: 6px;
Expand All @@ -99,7 +62,7 @@ export const ProfileHeader = styled.h1`
font-size: 24px;
`;

export const ProfileHeaderNoMB = styled(ProfileHeader)`
styled(ProfileHeader)`
margin-bottom: 0;
`;

Expand All @@ -121,18 +84,3 @@ export const ErrorDisplay = styled.span<{}>`
line-height: 19px;
color: #b12424;
`;

export const LightEntryLabel = styled.label<{
error?: boolean;
}>`
font-family: "Montserrat", sans-serif;
font-style: normal;
font-weight: 400;
line-height: 24.38px;
display: flex;
align-items: center;
color: ${(props) => (props.error ? "#B12424" : "#000000")};
@media (min-width: 420px) {
font-size: 16px;
}
`;
2 changes: 0 additions & 2 deletions src/utils/map/PulsingDot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export default class PulsingDot {
this.map = map;
}

onAdd() {}

render() {
const duration = 3000;
const t = (performance.now() % duration) / duration;
Expand Down
1 change: 0 additions & 1 deletion src/utils/map/addMapEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const addMapEvents = (
function handlePointClick(e: MapLayerMouseEvent) {
if (!e.features) return;
const layers = ["riders", "drivers"];
e;
const pointFeatures = map.queryRenderedFeatures(e.point, { layers });

if (pointFeatures.length === 0) return;
Expand Down
8 changes: 0 additions & 8 deletions src/utils/recommendation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,6 @@ export const generateUser = ({
const [startHours, startMinutes] = startTime
.split(":")
.map((s) => _.toInteger(s));
const startDate = dayjs
.tz(`2022-11-01 ${startHours}:${startMinutes}00`, "UTC")
.toDate();

const [endHours, endMinutes] = endTime.split(":").map((s) => _.toInteger(s));
const endDate = dayjs
.tz(`2022-11-01 ${endHours}:${endMinutes}00`, "UTC")
.toDate();

const updated_obj = {
id: id,
Expand Down
6 changes: 0 additions & 6 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ export type ButtonInfo = {
color: string;
};

export type ResolvedRequest = {
fromUser: PublicUser | null;
toUser: PublicUser | null;
id: string;
};

type Admin = {
iso_3166_1_alpha3: string;
iso_3166_1: string;
Expand Down

0 comments on commit 9615fb9

Please sign in to comment.