diff --git a/bash.exe.stackdump b/bash.exe.stackdump new file mode 100644 index 00000000..08ebf9cf --- /dev/null +++ b/bash.exe.stackdump @@ -0,0 +1,44 @@ +Exception: STATUS_STACK_OVERFLOW at rip=0010040B625 +rax=0000000000000000 rbx=00000000FFE04040 rcx=0000000000000000 +rdx=0000000000000000 rsi=00000001004F73A0 rdi=00000000000000C8 +r8 =0000000000000000 r9 =00000000FFFFDE08 r10=00000000FFFFE458 +r11=0000000100000000 r12=0000000000000000 r13=00000008006429D0 +r14=0000000000000000 r15=00000000FFFFFFFF +rbp=0000000000000000 rsp=00000000FFE03E40 +program=C:\Program Files\Git\usr\bin\bash.exe, pid 2063, thread +cs=0033 ds=002B es=002B fs=0053 gs=002B ss=002B +Stack trace: +Frame Function Args +00000000000 0010040B625 (001004036F5, 00000000010, 00000000000, 000FFE04DB0) +00000000010 00100401FFA (00210199B0B, 00800082CE0, 00800642B60, 008006429D0) +00000000010 0010046ED5C (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +00800642810 00100417AD9 (00210199B0B, 00800082CE0, 00800642100, 00800642810) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +00800641DB0 00100417AD9 (00210199B0B, 00800082CE0, 008006416A0, 00800641DB0) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +00800641350 00100417AD9 (00210199B0B, 00800082CE0, 00800640C40, 00800641350) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +008006408F0 00100417AD9 (00210199B0B, 00800082CE0, 008006401E0, 008006408F0) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063FE90 00100417AD9 (00210199B0B, 00800082CE0, 0080063F780, 0080063FE90) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063F430 00100417AD9 (00210199B0B, 00800082CE0, 0080063ED20, 0080063F430) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063E9D0 00100417AD9 (00210199B0B, 00800082CE0, 0080063E2C0, 0080063E9D0) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063DF70 00100417AD9 (00210199B0B, 00800082CE0, 0080063D860, 0080063DF70) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063D510 00100417AD9 (00210199B0B, 00800082CE0, 0080063CE00, 0080063D510) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063CAB0 00100417AD9 (00210199B0B, 00800082CE0, 0080063C3A0, 0080063CAB0) +End of stack trace (more stack frames may be present) diff --git a/frontend/src/firebase-client/useUpdateProfile.ts b/frontend/src/firebase-client/useUpdateProfile.ts index 98118e2c..a36368e2 100644 --- a/frontend/src/firebase-client/useUpdateProfile.ts +++ b/frontend/src/firebase-client/useUpdateProfile.ts @@ -1,15 +1,21 @@ +import { updateUserByUid } from "@/pages/api/userHandler"; import { getAuth, updateProfile } from "firebase/auth"; export const useUpdateProfile = () => { - - const updateUserProfile = async ({displayName, photoURL}: {displayName?: string, photoURL?: string}) => { - const auth = getAuth(); - try { - await updateProfile(auth.currentUser!, { displayName, photoURL }); - } catch (error) { - console.log(error); - } - }; - - return { updateUserProfile }; -}; \ No newline at end of file + const updateUserProfile = async ({ + displayName, + photoURL, + }: { + displayName?: string; + photoURL?: string; + }) => { + const auth = getAuth(); + try { + await updateProfile(auth.currentUser!, { displayName, photoURL }); + } catch (error) { + console.log(error); + } + }; + + return { updateUserProfile }; +}; diff --git a/frontend/src/hooks/useUser.ts b/frontend/src/hooks/useUser.ts index 18704553..6d09ab38 100644 --- a/frontend/src/hooks/useUser.ts +++ b/frontend/src/hooks/useUser.ts @@ -1,5 +1,8 @@ import { useContext } from "react"; -import { updateUserByUid as updateUserApi, getUserByUid as getUserApi } from "./../pages/api/userHandler"; +import { + updateUserByUid as updateUserApi, + getUserByUid as getUserApi, +} from "./../pages/api/userHandler"; import { AuthContext } from "@/contexts/AuthContext"; import { EditableUser } from "@/types/UserTypes"; @@ -12,9 +15,13 @@ export const useUser = () => { } }; - const getAppUser = async (userId?: string) => { + const getAppUser = async (userId?: string, fetchSelf: boolean = true) => { if (authIsReady) { - return getUserApi(userId || currentUser?.uid || "", currentUser); + if (fetchSelf) { + return getUserApi(currentUser?.uid || "", currentUser); + } else { + return getUserApi(userId || "", currentUser); + } } }; diff --git a/frontend/src/pages/interviews/match-found.tsx b/frontend/src/pages/interviews/match-found.tsx index 0b0f3228..46ff2429 100644 --- a/frontend/src/pages/interviews/match-found.tsx +++ b/frontend/src/pages/interviews/match-found.tsx @@ -6,26 +6,47 @@ import { TypographyH2, TypographyH3, } from "@/components/ui/typography"; +import { AuthContext } from "@/contexts/AuthContext"; import { useMatchmaking } from "@/hooks/useMatchmaking"; +import { useUser } from "@/hooks/useUser"; import { query } from "express"; import Link from "next/link"; import { useRouter } from "next/router"; +import { useContext, useEffect, useState } from "react"; type UserInfo = { - name: string; - username: string; - avatar: string; + displayName: string; + photoUrl: string; }; const defaultUser: UserInfo = { - name: "John Doe", - username: "johndoe", - avatar: "https://github.com/shadcn.png", + displayName: "John Doe", + photoUrl: "https://github.com/shadcn.png", }; export default function MatchFound() { const router = useRouter(); const { match, leaveMatch, joinQueue, cancelLooking } = useMatchmaking(); + const { user, authIsReady } = useContext(AuthContext); + const [otherUser, setOtherUser] = useState(defaultUser); + + const { getAppUser } = useUser(); + + useEffect(() => { + const fetchOtherUser = async () => { + const otherUserId = + match?.userId1 === user?.uid ? match?.userId2 : match?.userId1; + + const other = await getAppUser(otherUserId, false); + setOtherUser(other); + + console.log(other); + }; + + if (user && authIsReady) { + fetchOtherUser(); + } + }, [user, authIsReady, match]); const onClickCancel = () => { leaveMatch(); @@ -49,14 +70,14 @@ export default function MatchFound() {
- + - {defaultUser.name.charAt(0).toUpperCase()} + {defaultUser.displayName.charAt(0).toUpperCase()}
- {defaultUser?.name} - @{defaultUser?.username} + {otherUser?.displayName ?? "Annoymous"} + {/* @{otherUser?.displayName} */}
diff --git a/frontend/src/pages/profile/[id]/index.tsx b/frontend/src/pages/profile/[id]/index.tsx index 7f0bb304..c6fec8c3 100644 --- a/frontend/src/pages/profile/[id]/index.tsx +++ b/frontend/src/pages/profile/[id]/index.tsx @@ -10,35 +10,47 @@ import { useUser } from "@/hooks/useUser"; export default function Page() { const router = useRouter(); const id = router.query.id; + const { user: authUser, authIsReady } = useContext(AuthContext); const { getAppUser } = useUser(); const { user: currentUser } = useContext(AuthContext); const { fetchAttempts } = useHistory(); const [attempts, setAttempts] = useState([]); const [user, setUser] = useState(); - const [loadingState, setLoadingState] = useState<"loading" | "error" | "success">("loading"); + const [loadingState, setLoadingState] = useState< + "loading" | "error" | "success" + >("loading"); useEffect(() => { - if (currentUser && (typeof id === "string")) { - Promise.all([getAppUser(id), fetchAttempts(id)]).then(([user, attempts]) => { - if (user && attempts) { - user["photoURL"] = user["photoUrl"]; - console.log(user); - setUser(user); - setAttempts(attempts); - setLoadingState("success"); - } else { - throw new Error("User or attempts not found"); - } - }).catch((err: any) => { - setLoadingState("error"); - console.log(err); - }); + if (currentUser && typeof id === "string") { + Promise.all([getAppUser(id), fetchAttempts(id)]) + .then(([user, attempts]) => { + if (user && attempts) { + user["photoURL"] = user["photoUrl"]; + console.log(user); + setUser(user); + setAttempts(attempts); + setLoadingState("success"); + } else { + throw new Error("User or attempts not found"); + } + }) + .catch((err: any) => { + setLoadingState("error"); + console.log(err); + }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentUser]); return ( - (user && ) - ) + user && ( + + ) + ); } diff --git a/frontend/src/pages/profile/_profile.tsx b/frontend/src/pages/profile/_profile.tsx index 95be55ed..7ed93154 100644 --- a/frontend/src/pages/profile/_profile.tsx +++ b/frontend/src/pages/profile/_profile.tsx @@ -1,36 +1,47 @@ -import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" +import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; -import { TypographyBody, TypographyH3, TypographyH2 } from "@/components/ui/typography"; +import { + TypographyBody, + TypographyH3, + TypographyH2, +} from "@/components/ui/typography"; import { Attempt } from "@/types/UserTypes"; import { User } from "firebase/auth"; import Link from "next/link"; import ActivityCalendar, { Activity } from "react-activity-calendar"; -import { Tooltip as MuiTooltip } from '@mui/material'; +import { Tooltip as MuiTooltip } from "@mui/material"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { DataTable } from "@/components/profile/data-table"; import { columns } from "@/components/profile/columns"; import { DotWave } from "@uiball/loaders"; type ProfileProps = { - selectedUser: User, - loadingState: "loading" | "error" | "success", - attempts?: Attempt[], - isCurrentUser: boolean, -} + selectedUser: User; + loadingState: "loading" | "error" | "success"; + attempts?: Attempt[]; + isCurrentUser: boolean; +}; -export default function Profile({ selectedUser, attempts, isCurrentUser, loadingState }: ProfileProps) { +export default function Profile({ + selectedUser, + attempts, + isCurrentUser, + loadingState, +}: ProfileProps) { + console.log(selectedUser); const getInitials = (name: string) => { + if (!name) return "Annonymous"; const names = name.split(" "); let initials = ""; names.forEach((n) => { initials += n[0].toUpperCase(); }); return initials; - } + }; const date = new Date(); const dateTodayString = date.toISOString().slice(0, 10); - date.setFullYear(date.getFullYear() - 1) + date.setFullYear(date.getFullYear() - 1); const dateLastYearString = date.toISOString().slice(0, 10); // We need a date from last year to make sure the calendar is styled properly @@ -55,7 +66,10 @@ export default function Profile({ selectedUser, attempts, isCurrentUser, loading countsByDate[date].level = 1; } else if (countsByDate[date].count > 1 && countsByDate[date].count < 5) { countsByDate[date].level = 2; - } else if (countsByDate[date].count >= 5 && countsByDate[date].count < 10) { + } else if ( + countsByDate[date].count >= 5 && + countsByDate[date].count < 10 + ) { countsByDate[date].level = 3; } else if (countsByDate[date].count >= 10) { countsByDate[date].level = 4; @@ -63,30 +77,33 @@ export default function Profile({ selectedUser, attempts, isCurrentUser, loading }); } - // Extract the values from the dictionary to get the final activities array - const activities = Object.values(countsByDate).sort((a, b) => a.date.localeCompare(b.date)); + const activities = Object.values(countsByDate).sort((a, b) => + a.date.localeCompare(b.date) + ); return (
- - {getInitials(selectedUser?.displayName ?? '')} + + + {getInitials(selectedUser?.displayName ?? "")} +
{selectedUser?.displayName} {selectedUser?.email}
- {isCurrentUser && + {isCurrentUser && ( - } + )}
@@ -99,7 +116,7 @@ export default function Profile({ selectedUser, attempts, isCurrentUser, loading ( )} labels={{ - totalCount: '{{count}} activities in 2023', + totalCount: "{{count}} activities in 2023", }} /> - - Attempts - + Attempts - {loadingState === "loading" ?
- -
: loadingState === "error" ?
- Something went wrong. Please try again later. -
: - } + {loadingState === "loading" ? ( +
+ +
+ ) : loadingState === "error" ? ( +
+ + Something went wrong. Please try again later. + +
+ ) : ( + + )}
- ) + ); } diff --git a/frontend/src/pages/settings/_account.tsx b/frontend/src/pages/settings/_account.tsx index 4c870075..a994337a 100644 --- a/frontend/src/pages/settings/_account.tsx +++ b/frontend/src/pages/settings/_account.tsx @@ -1,4 +1,10 @@ -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@radix-ui/react-dropdown-menu"; import { useDeleteOwnAccount } from "@/firebase-client/useDeleteOwnAccount"; @@ -18,19 +24,19 @@ import { AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, -} from "@/components/ui/alert-dialog" +} from "@/components/ui/alert-dialog"; import { useUpdateProfile } from "../../firebase-client/useUpdateProfile"; - export default function AccountSettingsCard() { const { user: currentUser } = useContext(AuthContext); const { deleteOwnAccount } = useDeleteOwnAccount(); const { updateUserProfile } = useUpdateProfile(); const saveButtonRef = useRef(null); const [showSuccess, setShowSuccess] = useState(false); - - console.log(currentUser); - const [updatedUser, setUpdatedUser] = useState({ uid: currentUser?.uid ?? '' } as EditableUser); + const { updateUser } = useUser(); + const [updatedUser, setUpdatedUser] = useState({ + uid: currentUser?.uid ?? "", + } as EditableUser); useEffect(() => { console.log(updatedUser); @@ -47,9 +53,15 @@ export default function AccountSettingsCard() { - setUpdatedUser((prev: any) => ({ ...prev, displayName: event.target.value } as EditableUser)) + setUpdatedUser( + (prev: any) => + ({ + ...prev, + displayName: event.target.value, + } as EditableUser) + ) } className="max-w-sm" /> @@ -58,39 +70,51 @@ export default function AccountSettingsCard() { - console.log(event.target.value) - } + onChange={(event) => console.log(event.target.value)} className="max-w-sm" />
- + updateUser(updatedUser); + updateUserProfile({ + displayName: updatedUser.displayName, + }).then(() => { + if (saveButtonRef.current) { + saveButtonRef.current.removeAttribute("disabled"); + } + setShowSuccess(true); + }); + }} + > + Save Changes + {showSuccess && ( - Successfully updated user profile! + + Successfully updated user profile! + )}
- +
Danger Zone - @@ -98,13 +122,16 @@ export default function AccountSettingsCard() { Are you absolutely sure? - This action cannot be undone. This will permanently delete your account - and remove your data from our servers. Please log in to GitHub again to continue. + This action cannot be undone. This will permanently delete + your account and remove your data from our servers. Please + log in to GitHub again to continue. Cancel - Delete Account + + Delete Account + @@ -112,5 +139,5 @@ export default function AccountSettingsCard() { - ) -} \ No newline at end of file + ); +} diff --git a/frontend/src/pages/settings/_match.tsx b/frontend/src/pages/settings/_match.tsx index a48fb2a8..0d4c794a 100644 --- a/frontend/src/pages/settings/_match.tsx +++ b/frontend/src/pages/settings/_match.tsx @@ -1,4 +1,10 @@ -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; import { Label } from "@radix-ui/react-dropdown-menu"; import { useUser } from "@/hooks/useUser"; import { AuthContext } from "@/contexts/AuthContext"; @@ -6,11 +12,16 @@ import { useContext, useEffect, useRef, useState } from "react"; import { Button } from "@/components/ui/button"; import { EditableUser } from "@/types/UserTypes"; import DifficultySelector from "@/components/common/difficulty-selector"; -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; import { Difficulty } from "@/types/QuestionTypes"; import { DotWave } from "@uiball/loaders"; - export default function MatchSettingsCard() { const { user: currentUser } = useContext(AuthContext); const { updateUser, getAppUser } = useUser(); @@ -18,9 +29,12 @@ export default function MatchSettingsCard() { const [showSuccess, setShowSuccess] = useState(false); const submitButtonRef = useRef(null); - const [updatedUser, setUpdatedUser] = useState({ uid: currentUser?.uid ?? '' } as EditableUser); - const [selectedDifficulty, setSelectedDifficulty] = useState('medium'); - const [selectedLanguage, setSelectedLanguage] = useState('c++'); + const [updatedUser, setUpdatedUser] = useState({ + uid: currentUser?.uid ?? "", + } as EditableUser); + const [selectedDifficulty, setSelectedDifficulty] = + useState("medium"); + const [selectedLanguage, setSelectedLanguage] = useState("c++"); useEffect(() => { if (currentUser) { @@ -32,15 +46,21 @@ export default function MatchSettingsCard() { setIsLoading(false); }); } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [currentUser]) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [currentUser]); useEffect(() => { - setUpdatedUser((prev) => ({ ...prev, matchDifficulty: selectedDifficulty })); + setUpdatedUser((prev) => ({ + ...prev, + matchDifficulty: selectedDifficulty, + })); }, [selectedDifficulty]); useEffect(() => { - setUpdatedUser((prev) => ({ ...prev, matchProgrammingLanguage: selectedLanguage })); + setUpdatedUser((prev) => ({ + ...prev, + matchProgrammingLanguage: selectedLanguage, + })); }, [selectedLanguage]); return ( @@ -51,54 +71,67 @@ export default function MatchSettingsCard() { {isLoading ? (
- +
) : ( - -
- - -
-
- - { - setShowSuccess(false); - setSelectedDifficulty(value); - }} /> -
-
- - {showSuccess && ( - Successfully updated match preferences! - )} -
-
+ +
+ + +
+
+ + { + setShowSuccess(false); + setSelectedDifficulty(value); + }} + /> +
+
+ + {showSuccess && ( + + Successfully updated match preferences! + + )} +
+
)} -
- ) -} \ No newline at end of file + ); +}