Skip to content

Commit 96ebdf3

Browse files
committed
fix: fix ui
1 parent e5875e0 commit 96ebdf3

File tree

3 files changed

+65
-52
lines changed

3 files changed

+65
-52
lines changed

frontend/src/app/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export const FetchAuth = {
3737
// Perform the fetch request with the modified options
3838
const res = await fetch(url, options);
3939
if (!res.ok) {
40-
console.log(res);
41-
throw Error();
40+
// console.log(res);
41+
// throw Error();
4242
}
4343
return res;
4444
},

frontend/src/app/components/code-editor/CodeEditor.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { yCollab } from "y-codemirror.next";
1515
import { SocketIOProvider } from "y-socket.io";
1616
import * as Y from "yjs";
1717
import Tabs from "../tab/Tabs";
18+
import { fetchProfileUrl } from "@/app/api";
1819

1920
const CodeMirror = dynamic(() => import("@uiw/react-codemirror"), {
2021
ssr: false,
@@ -33,19 +34,6 @@ if (typeof window !== "undefined") {
3334
desiredWidth = window.innerWidth >= 1024 ? "50vw" : "90vw";
3435
}
3536

36-
// TODO: idk what FE plan is for this, so i just slapped a random text box thing here.
37-
const UiElementOnClose = () => {
38-
return (
39-
<div className="flex items-center gap-4 bg-slate-800 p-2">
40-
<ExclamationCircleFilled />
41-
Your room has been closed.
42-
<Button className="btn-accent" onClick={() => window.location.reload()}>
43-
Restart
44-
</Button>
45-
</div>
46-
);
47-
};
48-
4937
const codeLangAtomWrapper = atom(
5038
(get) => get(codeLangAtom),
5139
(_get, set, lang: string) => {
@@ -79,6 +67,9 @@ const CodeMirrorEditor = ({
7967
const [extensions, setExtensions] = useState<any>([]);
8068

8169
useEffect(() => {
70+
fetchProfileUrl().then((res) => {
71+
setSelectedLanguage(res.payload.preferredLang || "python");
72+
});
8273
if (!innkeeperUrl) {
8374
console.error(
8475
"NEXT_PUBLIC_PEERPREP_INNKEEPER_SOCKET_URL not set in .env",
@@ -204,7 +195,6 @@ const CodeMirrorEditor = ({
204195
</select>
205196
</div>
206197
</div>
207-
{isMatched !== "MATCHED" && <UiElementOnClose />}
208198
<CodeMirror
209199
className="max-h-[70svw] w-[90svw] lg:w-[50svw]"
210200
height={`${editorHeight}px`}

frontend/src/app/components/status-bar/StatusBar.tsx

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
codeLangAtom,
55
codeMirrorValueAtom,
66
innkeeperWriteAtom,
7+
isMatchedAtom,
78
isQuestionModalOpenAtom,
89
questionIdAtom,
910
resultAtom,
@@ -13,6 +14,7 @@ import { atom, useAtomValue, useSetAtom } from "jotai";
1314
import Button from "../button/Button";
1415
import { message } from "antd";
1516
import UserStateBadge from "./UserStatusBadge";
17+
import { ExclamationCircleFilled } from "@ant-design/icons";
1618

1719
interface StatusBarProps {
1820
exitMethod: () => void;
@@ -34,6 +36,7 @@ const triggerExitRoomRequestAtom = atom(null, (get, set) => {
3436
});
3537

3638
const StatusBar = ({ exitMethod }: StatusBarProps) => {
39+
const isMatched = useAtomValue(isMatchedAtom);
3740
const code = useAtomValue(codeMirrorValueAtom);
3841
const userStates = useAtomValue(userStatesAtom);
3942
const questionId = useAtomValue(questionIdAtom);
@@ -42,6 +45,23 @@ const StatusBar = ({ exitMethod }: StatusBarProps) => {
4245
const setQuestionModalOpen = useSetAtom(isQuestionModalOpenAtom);
4346
const [api, contextHolder] = message.useMessage();
4447

48+
const UiElementOnClose = () => {
49+
return (
50+
<div className="flex items-center gap-2">
51+
<div className="mt-1 flex gap-2 rounded-full bg-error px-2 py-1 font-bold text-white">
52+
<ExclamationCircleFilled />
53+
Your room has been closed.
54+
</div>
55+
<Button
56+
className="btn-accent btn-sm"
57+
onClick={() => window.location.reload()}
58+
>
59+
Back to Matching
60+
</Button>
61+
</div>
62+
);
63+
};
64+
4565
return (
4666
<footer className="fixed bottom-0 left-0 flex w-[100svw] items-center justify-between border-black bg-primary px-4 py-2 shadow-sm lg:static lg:w-full lg:px-12">
4767
{contextHolder}
@@ -51,42 +71,45 @@ const StatusBar = ({ exitMethod }: StatusBarProps) => {
5171
<UserStateBadge userState={userState} key={userState.userId} />
5272
))}
5373
</div>
54-
<div className="flex items-center gap-4">
55-
<Button
56-
className="btn-outline btn-sm"
57-
onClick={() =>
58-
questionId &&
59-
completeQuestion(questionId).then((res) =>
60-
res.statusMessage.type.toLowerCase() === "success"
61-
? api.success({
62-
type: "success",
63-
content: "Successfully completed question!",
64-
})
65-
: api.error({
66-
type: "error",
67-
content: "Failure completing question",
68-
}),
69-
)
70-
}
71-
children={<span>Mark As Complete</span>}
72-
disabled={!questionId}
73-
/>
74-
<Button
75-
className="btn-success btn-sm"
76-
onClick={() => setQuestionModalOpen(true)}
77-
children={<span>Select Question</span>}
78-
/>
79-
<Button
80-
className="btn-sm"
81-
onClick={callExecution}
82-
children={<span>Execute</span>}
83-
/>
84-
<Button
85-
className="btn-error btn-sm"
86-
onClick={callExitRoom}
87-
children={<span>Exit</span>}
88-
/>
89-
</div>
74+
{isMatched === "MATCHED" && (
75+
<div className="flex items-center gap-4">
76+
<Button
77+
className="btn-outline btn-sm"
78+
onClick={() =>
79+
questionId &&
80+
completeQuestion(questionId).then((res) =>
81+
res.statusMessage.type.toLowerCase() === "success"
82+
? api.success({
83+
type: "success",
84+
content: "Successfully completed question!",
85+
})
86+
: api.error({
87+
type: "error",
88+
content: "Failure completing question",
89+
}),
90+
)
91+
}
92+
children={<span>Mark As Complete</span>}
93+
disabled={!questionId}
94+
/>
95+
<Button
96+
className="btn-success btn-sm"
97+
onClick={() => setQuestionModalOpen(true)}
98+
children={<span>Select Question</span>}
99+
/>
100+
<Button
101+
className="btn-sm"
102+
onClick={callExecution}
103+
children={<span>Execute</span>}
104+
/>
105+
<Button
106+
className="btn-error btn-sm"
107+
onClick={callExitRoom}
108+
children={<span>Exit</span>}
109+
/>
110+
</div>
111+
)}
112+
{isMatched !== "MATCHED" && <UiElementOnClose />}
90113
</footer>
91114
);
92115
};

0 commit comments

Comments
 (0)