Skip to content

Commit

Permalink
update find match logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ong6 committed Nov 2, 2023
1 parent 8afd057 commit 77f3f29
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 165 deletions.
44 changes: 44 additions & 0 deletions bash.exe.stackdump
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 18 additions & 12 deletions frontend/src/firebase-client/useUpdateProfile.ts
Original file line number Diff line number Diff line change
@@ -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 };
};
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 };
};
13 changes: 10 additions & 3 deletions frontend/src/hooks/useUser.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
}
}
};

Expand Down
41 changes: 31 additions & 10 deletions frontend/src/pages/interviews/match-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserInfo>(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();
Expand All @@ -49,14 +70,14 @@ export default function MatchFound() {
<Card className="flex flex-col justify-center items-center gap-y-6">
<div className="flex items-center w-full justify-center gap-x-4 p-16 shadow-2xl shadow-secondary/50">
<Avatar className="h-24 w-24">
<AvatarImage src={defaultUser.avatar} />
<AvatarImage src={otherUser.photoUrl} />
<AvatarFallback>
{defaultUser.name.charAt(0).toUpperCase()}
{defaultUser.displayName.charAt(0).toUpperCase()}
</AvatarFallback>
</Avatar>
<div>
<TypographyH3>{defaultUser?.name}</TypographyH3>
<TypographyCode>@{defaultUser?.username}</TypographyCode>
<TypographyH3>{otherUser?.displayName ?? "Annoymous"}</TypographyH3>
{/* <TypographyCode>@{otherUser?.displayName}</TypographyCode> */}
</div>
</div>
</Card>
Expand Down
48 changes: 30 additions & 18 deletions frontend/src/pages/profile/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attempt[]>([]);
const [user, setUser] = useState<User>();
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 && <Profile selectedUser={user} isCurrentUser={user.uid === currentUser?.uid} loadingState={loadingState} attempts={attempts}/>)
)
user && (
<Profile
selectedUser={user}
isCurrentUser={user.uid === currentUser?.uid}
loadingState={loadingState}
attempts={attempts}
/>
)
);
}
Loading

0 comments on commit 77f3f29

Please sign in to comment.