Skip to content

Commit dfe7977

Browse files
Merge pull request #155 from PeerPrep/kevin/table
Kevin/table
2 parents d2cf336 + a02f591 commit dfe7977

File tree

3 files changed

+78
-24
lines changed

3 files changed

+78
-24
lines changed

frontend/src/app/api/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,19 @@ export const fetchQuestionDescriptionUrl = async (qnId: string) => {
5454
};
5555

5656
export const fetchAllQuestionsDoneByUser = async () => {
57-
const { payload } = (await FetchAuth.fetch(`${API_URL}/users/activity/`).then(
57+
const { payload } = await FetchAuth.fetch(`${API_URL}/users/activity/`).then(
5858
(res) => {
59-
res.json();
59+
return res.json();
6060
},
61-
)) as any;
62-
const questionIds = payload.join("-");
61+
);
62+
63+
const questionIds = payload.map((ele: any) => ele.questionId).join("-");
64+
console.log({ questionIds });
6365
// console.log({ res });
64-
return await FetchAuth.fetch(
66+
const questions = await FetchAuth.fetch(
6567
`${API_URL}/questions/group/${questionIds}`,
66-
).then((res) => {
67-
res.json();
68-
});
68+
).then((res) => res.json());
69+
return questions.payload.map((k: any, i: any) => ({ ...k, ...payload[i] }));
6970
};
7071

7172
export const fetchAllQuestionsUrl = async () => {

frontend/src/app/components/matching/MatchingPage.tsx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { innkeeperWriteAtom, isQueuingAtom } from "@/libs/room-jotai";
77
import { fetchAllQuestionsDoneByUser } from "@/app/api";
88
import { useQuery } from "@tanstack/react-query";
99
import { Skeleton, Table, notification } from "antd";
10+
import { EyeOutlined } from "@ant-design/icons";
11+
import ReactMarkdown from "react-markdown";
1012

1113
const sendMatchRequestAtom = atom(
1214
null,
@@ -19,6 +21,8 @@ const sendMatchRequestAtom = atom(
1921
);
2022

2123
const MatchingPage = () => {
24+
const [currQn, setCurrQn] = useState<QuestionType | null>(null);
25+
2226
const sendMatchRequest: (
2327
questionDifficulty: "EASY" | "MEDIUM" | "HARD",
2428
) => void = useAtom(sendMatchRequestAtom)[1];
@@ -96,12 +100,37 @@ const MatchingPage = () => {
96100
},
97101
{
98102
title: "Submitted Date",
99-
dataIndex: "date",
103+
dataIndex: "submitted",
100104
sortDirections: ["descend"],
101-
render: (date: string) => <>{date}</>,
105+
render: (date: string) => {
106+
return new Date(date).toLocaleDateString();
107+
},
108+
},
109+
{
110+
title: "Actions",
111+
dataIndex: "actions",
112+
align: "center",
113+
width: 10,
114+
render: (text: string, record: QuestionType, index: number) => (
115+
<div className="flex justify-center gap-2">
116+
<EyeOutlined
117+
className="p-2 text-xl hover:cursor-pointer hover:rounded-full hover:bg-primary-focus"
118+
onClick={() => {
119+
onClickModal("my_modal_2");
120+
setCurrQn(record);
121+
}}
122+
/>
123+
</div>
124+
),
102125
},
103126
];
104127

128+
const onClickModal = (modalId: string) => {
129+
if (document) {
130+
(document.getElementById(modalId) as HTMLFormElement).showModal();
131+
}
132+
};
133+
105134
const {
106135
data: allQuestions,
107136
isLoading: allQuestionsLoading,
@@ -115,6 +144,18 @@ const MatchingPage = () => {
115144
return (
116145
<>
117146
<main className="flex h-full flex-col items-center justify-center">
147+
<dialog id="my_modal_2" className="modal">
148+
<div className="modal-box max-w-4xl p-6">
149+
<form method="dialog" className="pb">
150+
<button className="btn btn-circle btn-ghost btn-sm absolute right-2 top-2">
151+
152+
</button>
153+
</form>
154+
<ReactMarkdown className="prose min-w-[40svh] max-w-none rounded-b-md bg-secondary p-6">
155+
{currQn?.description || ""}
156+
</ReactMarkdown>
157+
</div>
158+
</dialog>
118159
<section className="flex items-center gap-4">
119160
<label>
120161
<span>Difficulty Setting:</span>

frontend/src/app/settings/page.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@ import {
1010
import useLogin from "../hooks/useLogin";
1111
import { message } from "antd";
1212
import { useMutation } from "@tanstack/react-query";
13+
import { getAuth, signOut } from "firebase/auth";
14+
import { useRouter } from "next/navigation";
1315

1416
const SettingPage = () => {
1517
const user = useLogin();
18+
const router = useRouter();
1619

1720
const deleteProfileMutation = useMutation(async () => deleteProfileUrl(), {
1821
onSuccess: () => {
1922
closeModal("delete_modal");
2023
api.open({
2124
type: "success",
22-
content: "Successfully deleted profile!",
25+
content: "Successfully deleted profile! Logging you out...",
2326
});
27+
const auth = getAuth();
28+
setTimeout(() => {
29+
signOut(auth);
30+
router.push("/");
31+
}, 2000);
2432
},
2533
onError: (e) => {
2634
api.open({
@@ -55,19 +63,23 @@ const SettingPage = () => {
5563

5664
const onFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {
5765
e.preventDefault();
58-
updateProfileUrl(name, preferredLang, selectedImage).then((res) => {
59-
if (res.statusMessage.type.toLowerCase() === "success") {
60-
api.success({
61-
type: "success",
62-
content: "Successfully updated profile!",
63-
});
64-
} else {
65-
api.error({
66-
type: "error",
67-
content: "Failed to update profile :(",
68-
});
69-
}
70-
});
66+
updateProfileUrl(name, preferredLang, selectedImage)
67+
.then((res) => {
68+
if (res.statusMessage.type.toLowerCase() === "success") {
69+
api.success({
70+
type: "success",
71+
content: "Successfully updated profile!",
72+
});
73+
} else {
74+
api.error({
75+
type: "error",
76+
content: "Failed to update profile :(",
77+
});
78+
}
79+
})
80+
.then(() => {
81+
window.location.reload();
82+
});
7183
};
7284

7385
const onEscKeyDown = (e: React.KeyboardEvent<HTMLDialogElement>) => {

0 commit comments

Comments
 (0)