From e6fa830d1076e5a5c57ce5001cb64d1652ce7393 Mon Sep 17 00:00:00 2001 From: Brendan Tan Date: Thu, 7 Nov 2024 23:08:20 +0800 Subject: [PATCH 1/4] Update batch interval for matching service --- .../controllers/matchingController.js | 4 +- .../app/(authenticated)/questions/page.tsx | 38 +++++++++---------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/backend/matching-service/controllers/matchingController.js b/backend/matching-service/controllers/matchingController.js index 2a14a88aca..cd0344b1af 100644 --- a/backend/matching-service/controllers/matchingController.js +++ b/backend/matching-service/controllers/matchingController.js @@ -4,7 +4,7 @@ const EventEmitter = require('events'); const uuid = require("uuid"); const QUEUE_TIME = 30000; -const BATCH_INTERVAL = 10000; +const BATCH_INTERVAL = 3000; // Kafka setup const kafka = new Kafka({ @@ -92,6 +92,8 @@ const matchmakeUser = async (userId, userName, questions) => { } const dequeueUser = async (userId) => { + userQueueMap.delete(userId); + dequeued.set(userId, true); eventEmitter.emit(`dequeue-${userId}`); } diff --git a/frontend/app/(authenticated)/questions/page.tsx b/frontend/app/(authenticated)/questions/page.tsx index a87e1ca1ba..a60da39c99 100644 --- a/frontend/app/(authenticated)/questions/page.tsx +++ b/frontend/app/(authenticated)/questions/page.tsx @@ -301,34 +301,30 @@ export default function Questions() { }; }, []); - const ws1 = useRef(null); // WebSocket reference const handleCancel = useCallback(() => { setIsMatching(false); - if (ws1.current === null || ws1.current.readyState === WebSocket.CLOSED || ws1.current.readyState === WebSocket.CLOSING) { - console.log("Connecting to web socket for matching service ...") - // Initialize WebSocket connection if not already matching - ws1.current = new WebSocket(process.env.NEXT_PUBLIC_MATCHING_API_URL || 'ws://localhost:3002/matching'); - console.log(ws1.current.readyState) - } - ws1.current.onopen = () => { - console.log("WebSocket connection opened"); + + if (ws.current && ws.current.readyState === WebSocket.OPEN) { const message = { event: "dequeue", - userId: userInfo.current.id, + userId: getUserId(), }; + + ws.current.send(JSON.stringify(message)); + console.log("Sent dequeue request:", message); - ws.current?.send(JSON.stringify(message)); - }; + ws.current.close(); + ws.current = null; + } + }, []); - ws1.current.onmessage = (event) => { - if (event.data == "Welcome to websocket server") { - console.log("receive welcome msg from websocket server") - return; + useEffect(() => { + return () => { + if (isMatching) { + handleCancel(); } - const message = JSON.parse(event.data); - console.log("message receive from websocket", message); - } - }, []) + }; + }, [handleCancel, isMatching]); useEffect(() => { timeout.current = false; @@ -497,7 +493,7 @@ export default function Questions() { filteredQuestions.map((question) => (
setSelectedViewQuestion(question)} >
From 02d5966f698c77c08edb4423c7f5dff596006757 Mon Sep 17 00:00:00 2001 From: Brendan Tan Date: Fri, 8 Nov 2024 02:06:27 +0800 Subject: [PATCH 2/4] Fix frontend compile errors --- .../controllers/matchingController.js | 14 +--- .../profile/question-history/code/page.tsx | 73 +++++++++++-------- .../profile/question-history/columns.tsx | 8 +- .../profile/question-history/page.tsx | 2 +- .../app/(authenticated)/session/[id]/page.tsx | 12 +-- .../session/code-editor/code-editor.tsx | 2 +- .../code-editor/themes/theme-loader.tsx | 5 +- .../(authenticated)/session/text-editor.tsx | 2 +- frontend/app/page.tsx | 2 +- 9 files changed, 60 insertions(+), 60 deletions(-) diff --git a/backend/matching-service/controllers/matchingController.js b/backend/matching-service/controllers/matchingController.js index cd0344b1af..87c5022642 100644 --- a/backend/matching-service/controllers/matchingController.js +++ b/backend/matching-service/controllers/matchingController.js @@ -143,19 +143,7 @@ const batchProcess = () => { let questionDict = new Map(); let unmatchedUsers = new Map(); - // Remove duplicate users, keeping only the most recent instance - let uniqueUsers = new Map(); - for (const user of batch) { - if (uniqueUsers.has(user.userId)) { - if (user.enqueueTime > uniqueUsers.get(user.userId).enqueueTime) { - uniqueUsers.set(user.userId, user); - } - } else { - uniqueUsers.set(user.userId, user); - } - } - - batch = Array.from(uniqueUsers.values()); + batch.forEach((user) => { if (!dequeued.has(user.userId)) { diff --git a/frontend/app/(authenticated)/profile/question-history/code/page.tsx b/frontend/app/(authenticated)/profile/question-history/code/page.tsx index 7bab4bc42d..00070f3559 100644 --- a/frontend/app/(authenticated)/profile/question-history/code/page.tsx +++ b/frontend/app/(authenticated)/profile/question-history/code/page.tsx @@ -1,16 +1,17 @@ "use client"; -import { useEffect, useRef, useState } from 'react'; +import { Suspense, useEffect, useRef, useState } from 'react'; import { Copy, Flag, MessageSquareText } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Toaster } from "@/components/ui/sonner" import { useSearchParams } from 'next/navigation'; import { getCookie, setCookie } from '@/app/utils/cookie-manager'; import { ScrollArea } from "@/components/ui/scroll-area" -import { Badge } from '@/components/ui/badge'; +import { Badge, BadgeProps } from '@/components/ui/badge'; import Editor from "@monaco-editor/react"; import { toast } from "sonner" import Markdown from 'react-markdown' +import SessionLoading from '@/app/(authenticated)/session/loading'; type Question = { id: number; @@ -22,9 +23,10 @@ type Question = { } function getTimeAgo(attemptDate: Date | null) { + if (!attemptDate) return "N/A"; const now = new Date(); - const diffInMs = now - attemptDate; // Difference in milliseconds + const diffInMs = now.getTime() - attemptDate.getTime(); // Difference in milliseconds const diffInMinutes = Math.floor(diffInMs / (1000 * 60)); const diffInHours = Math.floor(diffInMs / (1000 * 60 * 60)); const diffInDays = Math.floor(diffInMs / (1000 * 60 * 60 * 24)); @@ -40,7 +42,7 @@ function getTimeAgo(attemptDate: Date | null) { } } -export default function CodeViewer() { +function CodeViewerContent() { const searchParams = useSearchParams(); const questionId = searchParams.get("questionId"); const [attemptDate, setAttemptDate] = useState(null); @@ -103,7 +105,8 @@ export default function CodeViewer() { setCode(JSON.parse(data.code)) setLanguage(data.language) } catch (err) { - console.error(err.message); + const errorMessage = err instanceof Error ? err.message : 'An unknown error occurred'; + console.error(errorMessage); toast.dismiss(); toast.error("Failed to load the code. Please try again later."); } @@ -112,24 +115,24 @@ export default function CodeViewer() { fetchAttemptDetails(); }, [questionId]); - const handleEditorDidMount = (editor) => { - editor.getDomNode().classList.add("my-custom-editor"); - - // Insert scoped tooltip styles - const style = document.createElement("style"); - style.textContent = ` - .my-custom-editor .monaco-tooltip { - z-index: 1000 !important; - position: absolute; - } - `; - document.head.appendChild(style); - - // Cleanup on component unmount - return () => { - document.head.removeChild(style); - }; -}; +// const handleEditorDidMount = (editor: ) => { +// editor.getDomNode().classList.add("my-custom-editor"); + +// // Insert scoped tooltip styles +// const style = document.createElement("style"); +// style.textContent = ` +// .my-custom-editor .monaco-tooltip { +// z-index: 1000 !important; +// position: absolute; +// } +// `; +// document.head.appendChild(style); + +// // Cleanup on component unmount +// return () => { +// document.head.removeChild(style); +// }; +// }; const copyToClipboard = () => { navigator.clipboard.writeText(code).then(() => { @@ -139,13 +142,13 @@ export default function CodeViewer() { }; return ( -
+
{/* Left Panel: Question Details */} - -

+ +

{questionDetails?.title || ""}

-
+
{questionDetails?.category?.length > 0 && - questionDetails?.category.map((category) => ( + questionDetails?.category.map((category) => (
-

- {questionDetails?.description || ""} -

- + {questionDetails?.description || ""} @@ -199,6 +199,7 @@ export default function CodeViewer() { readOnly: true, minimap: { enabled: false }, lineNumbers: "on", + fontFamily: 'monospace', fontSize: 14, padding: { top: 10, bottom: 10 }, scrollBeyondLastLine: false, @@ -215,3 +216,11 @@ export default function CodeViewer() {
); } + +export default function CodeViewer() { + return ( + }> + + + ); +} diff --git a/frontend/app/(authenticated)/profile/question-history/columns.tsx b/frontend/app/(authenticated)/profile/question-history/columns.tsx index 26d731d98f..b330005904 100644 --- a/frontend/app/(authenticated)/profile/question-history/columns.tsx +++ b/frontend/app/(authenticated)/profile/question-history/columns.tsx @@ -1,6 +1,6 @@ "use client" -import { Badge } from "@/components/ui/badge"; +import { Badge, BadgeProps } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/ui/hover-card"; import { ColumnDef } from "@tanstack/react-table" @@ -98,7 +98,7 @@ export const columns : ColumnDef[]= [ const rowCategories = row.getValue(id); console.log(selectedCategories); console.log(rowCategories); - return selectedCategories.every(category => rowCategories.includes(category)); + return selectedCategories.every((category: string) => (rowCategories as string[]).includes(category)); }, }, { @@ -153,7 +153,7 @@ export const columns : ColumnDef[]= [ ) }, accessorKey: "attemptTime", - cell: ({ row }) =>
{ Math.ceil(row.getValue("attemptTime")/60)}
, + cell: ({ row }) =>
{ Math.ceil(row.original.attemptTime/60)}
, // Cell: ({ value }) => Math.floor(value / 60), // Convert time spent in seconds to minutes }, { @@ -170,7 +170,7 @@ export const columns : ColumnDef[]= [ }, accessorKey: "attemptDate", cell: ({ row }) => { - const attemptDate = row.getValue("attemptDate"); + const attemptDate = row.original.attemptDate; return new Date(attemptDate).toLocaleString("en-GB", { day: "2-digit", month: "2-digit", diff --git a/frontend/app/(authenticated)/profile/question-history/page.tsx b/frontend/app/(authenticated)/profile/question-history/page.tsx index 00029a61a1..7582e4159e 100644 --- a/frontend/app/(authenticated)/profile/question-history/page.tsx +++ b/frontend/app/(authenticated)/profile/question-history/page.tsx @@ -24,7 +24,7 @@ export default function UserQuestionHistory() { const router = useRouter(); const [history, setHistory] = useState([]); const [loading, setLoading] = useState(true); - const userId = useRef(null); + const userId = useRef(null); // Fetch questions history from backend API useEffect(() => { diff --git a/frontend/app/(authenticated)/session/[id]/page.tsx b/frontend/app/(authenticated)/session/[id]/page.tsx index 106606897a..405375108b 100644 --- a/frontend/app/(authenticated)/session/[id]/page.tsx +++ b/frontend/app/(authenticated)/session/[id]/page.tsx @@ -48,7 +48,7 @@ export default function Session() { const [isEndDialogOpen, setIsEndDialogOpen] = useState(false); const [language, setLanguage] = useState("javascript"); - const codeDocRef = useRef(); + const codeDocRef = useRef(); const codeProviderRef = useRef(null); const notesProviderRef = useRef(null); @@ -92,8 +92,8 @@ export default function Session() { setController(abortController); setIsEndingSession(true); - const codeText = codeDocRef.current.getText(`monaco`); - const code = codeText.toString(); + const codeText = codeDocRef.current?.getText(`monaco`); + const code = codeText?.toString(); console.log("languge: ", language) try { await fetch(`${process.env.NEXT_PUBLIC_USER_API_HISTORY_URL}/${getCookie('userId')}`, { @@ -118,7 +118,7 @@ export default function Session() { setIsEndingSession(false); setController(null); } - }, [isHistoryApiCalled, timeElapsed]); + }, [isHistoryApiCalled, language, questionId, timeElapsed]); useEffect(() => { if (isSessionEnded && !isHistoryApiCalled) { @@ -331,7 +331,7 @@ export default function Session() { ))}

- + {question.description} @@ -371,7 +371,7 @@ export default function Session() {

Your session has ended.

-

Redirecting you back to the question page...

+

Redirecting you to the Questions page...

diff --git a/frontend/app/(authenticated)/session/code-editor/code-editor.tsx b/frontend/app/(authenticated)/session/code-editor/code-editor.tsx index 009a139853..00bd963e60 100644 --- a/frontend/app/(authenticated)/session/code-editor/code-editor.tsx +++ b/frontend/app/(authenticated)/session/code-editor/code-editor.tsx @@ -202,7 +202,7 @@ export default function CodeEditor({ sessionId, provider, setLanguage }: CodeEdi onMount={handleEditorDidMount} theme={theme} options={{ - fontSize: 13, + fontSize: 14, fontFamily: 'monospace', bracketPairColorization: { enabled: true diff --git a/frontend/app/(authenticated)/session/code-editor/themes/theme-loader.tsx b/frontend/app/(authenticated)/session/code-editor/themes/theme-loader.tsx index b4fb607312..858c9aada7 100644 --- a/frontend/app/(authenticated)/session/code-editor/themes/theme-loader.tsx +++ b/frontend/app/(authenticated)/session/code-editor/themes/theme-loader.tsx @@ -12,7 +12,10 @@ export async function loadThemes(monacoInstance: typeof monaco) { for (const [key, label] of Object.entries(themeGroup)) { await import(`./${label}.json`).then(data => { monacoInstance.editor.defineTheme(key, data); - themes.push({ value: key, label }); + const themeExists = themes.some(theme => theme.value === key); + if (!themeExists) { + themes.push({ value: key, label }); + } }); } } diff --git a/frontend/app/(authenticated)/session/text-editor.tsx b/frontend/app/(authenticated)/session/text-editor.tsx index 9ca19b8981..c6984c0a39 100644 --- a/frontend/app/(authenticated)/session/text-editor.tsx +++ b/frontend/app/(authenticated)/session/text-editor.tsx @@ -24,7 +24,7 @@ export default function TextEditor({ sessionId, provider }: TextEditorProps) { }), CollaborationCursor.configure({ provider: provider, - user: { name: getUsername(), color: '#' + Math.floor(Math.random() * 16777215).toString(16) }, + user: { name: getUsername(), color: '#E9D7FE' }, }), ] diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 0a1441cf04..ba0e53b060 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -14,7 +14,7 @@ export default function Landing() {

Prep for your next interview with your Peers

-
+
From 5fc09538fa7eef6c3a8cb8b11f3d12c2321b3752 Mon Sep 17 00:00:00 2001 From: Brendan Tan Date: Fri, 8 Nov 2024 02:44:25 +0800 Subject: [PATCH 3/4] Update cookie handling and layout for session --- frontend/app/(authenticated)/layout.tsx | 5 +-- .../profile/question-history/code/page.tsx | 2 +- .../app/(authenticated)/questions/page.tsx | 4 +-- frontend/app/auth/login/page.tsx | 16 +++++---- .../session/[id]/page.tsx | 8 +++-- .../session/code-editor/code-editor.tsx | 0 .../session/code-editor/lang-loader.tsx | 0 .../session/code-editor/themes/Active4D.json | 0 .../code-editor/themes/All Hallows Eve.json | 0 .../session/code-editor/themes/Amy.json | 0 .../code-editor/themes/Birds of Paradise.json | 0 .../code-editor/themes/Blackboard.json | 0 .../code-editor/themes/Brilliance Black.json | 0 .../code-editor/themes/Brilliance Dull.json | 0 .../code-editor/themes/Chrome DevTools.json | 0 .../code-editor/themes/Clouds Midnight.json | 0 .../session/code-editor/themes/Clouds.json | 0 .../session/code-editor/themes/Cobalt.json | 0 .../session/code-editor/themes/Cobalt2.json | 0 .../session/code-editor/themes/Dawn.json | 0 .../code-editor/themes/Dominion Day.json | 0 .../session/code-editor/themes/Dracula.json | 0 .../code-editor/themes/Dreamweaver.json | 0 .../session/code-editor/themes/Eiffel.json | 0 .../code-editor/themes/Espresso Libre.json | 0 .../code-editor/themes/GitHub Dark.json | 0 .../code-editor/themes/GitHub Light.json | 0 .../session/code-editor/themes/IDLE.json | 0 .../code-editor/themes/Katzenmilch.json | 0 .../code-editor/themes/Kuroir Theme.json | 0 .../session/code-editor/themes/LAZY.json | 0 .../code-editor/themes/MagicWB (Amiga).json | 0 .../code-editor/themes/Merbivore Soft.json | 0 .../session/code-editor/themes/Merbivore.json | 0 .../code-editor/themes/Monokai Bright.json | 0 .../session/code-editor/themes/Monokai.json | 0 .../session/code-editor/themes/Night Owl.json | 0 .../session/code-editor/themes/Nord.json | 0 .../code-editor/themes/Oceanic Next.json | 0 .../themes/One Dark Pro Darker.json | 0 .../code-editor/themes/One Dark Pro.json | 0 .../code-editor/themes/Pastels on Dark.json | 0 .../code-editor/themes/Slush and Poppies.json | 0 .../code-editor/themes/Solarized-dark.json | 0 .../code-editor/themes/Solarized-light.json | 0 .../code-editor/themes/SpaceCadet.json | 0 .../session/code-editor/themes/Sunburst.json | 0 .../themes/Textmate (Mac Classic).json | 0 .../themes/Tomorrow-Night-Blue.json | 0 .../themes/Tomorrow-Night-Bright.json | 0 .../themes/Tomorrow-Night-Eighties.json | 0 .../code-editor/themes/Tomorrow-Night.json | 0 .../session/code-editor/themes/Tomorrow.json | 0 .../session/code-editor/themes/Twilight.json | 0 .../code-editor/themes/Upstream Sunburst.json | 0 .../code-editor/themes/Vibrant Ink.json | 0 .../themes/Xcode Classic Dark.json | 0 .../themes/Xcode Classic Light.json | 0 .../themes/Xcode Default Dark.json | 0 .../code-editor/themes/Zenburnesque.json | 0 .../session/code-editor/themes/iPlastic.json | 0 .../code-editor/themes/idleFingers.json | 0 .../session/code-editor/themes/krTheme.json | 0 .../code-editor/themes/monoindustrial.json | 0 .../code-editor/themes/theme-list.json | 0 .../code-editor/themes/theme-loader.tsx | 0 frontend/app/session/layout.tsx | 35 +++++++++++++++++++ .../{(authenticated) => }/session/loading.tsx | 0 .../session/text-editor.tsx | 0 69 files changed, 55 insertions(+), 15 deletions(-) rename frontend/app/{(authenticated) => }/session/[id]/page.tsx (98%) rename frontend/app/{(authenticated) => }/session/code-editor/code-editor.tsx (100%) rename frontend/app/{(authenticated) => }/session/code-editor/lang-loader.tsx (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Active4D.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/All Hallows Eve.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Amy.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Birds of Paradise.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Blackboard.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Brilliance Black.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Brilliance Dull.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Chrome DevTools.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Clouds Midnight.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Clouds.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Cobalt.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Cobalt2.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Dawn.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Dominion Day.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Dracula.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Dreamweaver.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Eiffel.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Espresso Libre.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/GitHub Dark.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/GitHub Light.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/IDLE.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Katzenmilch.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Kuroir Theme.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/LAZY.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/MagicWB (Amiga).json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Merbivore Soft.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Merbivore.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Monokai Bright.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Monokai.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Night Owl.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Nord.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Oceanic Next.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/One Dark Pro Darker.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/One Dark Pro.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Pastels on Dark.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Slush and Poppies.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Solarized-dark.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Solarized-light.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/SpaceCadet.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Sunburst.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Textmate (Mac Classic).json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Tomorrow-Night-Blue.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Tomorrow-Night-Bright.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Tomorrow-Night-Eighties.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Tomorrow-Night.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Tomorrow.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Twilight.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Upstream Sunburst.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Vibrant Ink.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Xcode Classic Dark.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Xcode Classic Light.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Xcode Default Dark.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/Zenburnesque.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/iPlastic.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/idleFingers.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/krTheme.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/monoindustrial.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/theme-list.json (100%) rename frontend/app/{(authenticated) => }/session/code-editor/themes/theme-loader.tsx (100%) create mode 100644 frontend/app/session/layout.tsx rename frontend/app/{(authenticated) => }/session/loading.tsx (100%) rename frontend/app/{(authenticated) => }/session/text-editor.tsx (100%) diff --git a/frontend/app/(authenticated)/layout.tsx b/frontend/app/(authenticated)/layout.tsx index d7d1120460..585810caf8 100644 --- a/frontend/app/(authenticated)/layout.tsx +++ b/frontend/app/(authenticated)/layout.tsx @@ -55,13 +55,14 @@ export default function AuthenticatedLayout({ const authenticateUser = async () => { const token = getCookie('token'); if (!token || await isTokenExpired(token)) { + deleteAllCookies(); router.push('/auth/login'); return; } - // if non-admin user tries to access repo, redirect user to question page + // if non-admin user tries to access repo, redirect user to question page if (pathname.includes('/question-repo') && !isUserAdmin()) { - router.push('/questions'); + router.replace('/questions'); return; } }; diff --git a/frontend/app/(authenticated)/profile/question-history/code/page.tsx b/frontend/app/(authenticated)/profile/question-history/code/page.tsx index 00070f3559..59b31146dd 100644 --- a/frontend/app/(authenticated)/profile/question-history/code/page.tsx +++ b/frontend/app/(authenticated)/profile/question-history/code/page.tsx @@ -11,7 +11,7 @@ import { Badge, BadgeProps } from '@/components/ui/badge'; import Editor from "@monaco-editor/react"; import { toast } from "sonner" import Markdown from 'react-markdown' -import SessionLoading from '@/app/(authenticated)/session/loading'; +import SessionLoading from '@/app/session/loading'; type Question = { id: number; diff --git a/frontend/app/(authenticated)/questions/page.tsx b/frontend/app/(authenticated)/questions/page.tsx index a60da39c99..9f50a818ec 100644 --- a/frontend/app/(authenticated)/questions/page.tsx +++ b/frontend/app/(authenticated)/questions/page.tsx @@ -611,7 +611,7 @@ export default function Questions() { )}
-
+ {/*
Past attempts @@ -628,7 +628,7 @@ export default function Questions() { -
+
*/}
diff --git a/frontend/app/auth/login/page.tsx b/frontend/app/auth/login/page.tsx index 6c418a76d0..6f18bc8ade 100644 --- a/frontend/app/auth/login/page.tsx +++ b/frontend/app/auth/login/page.tsx @@ -87,14 +87,16 @@ export default function Login() { const { accessToken, id, username, email, isAdmin, ...other } = responseData.data; // set token - setCookie('token', accessToken, { 'max-age': '86400', 'path': '/', 'SameSite': 'Strict' }); + const setCookiesAsync = async () => { + setCookie('token', accessToken, { 'max-age': '86400', 'path': '/', 'SameSite': 'Strict' }); + setCookie('userId', id, { 'max-age': '86400', 'path': '/', 'SameSite': 'Strict' }); + setCookie('username', username, { 'max-age': '86400', 'path': '/', 'SameSite': 'Strict' }); + setCookie('isAdmin', isAdmin.toString(), { 'max-age': '86400', 'path': '/', 'SameSite': 'Strict' }); + }; - // set user info - setCookie('userId', id, { 'max-age': '86400', 'path': '/', 'SameSite': 'Strict' }); - setCookie('username', username, { 'max-age': '86400', 'path': '/', 'SameSite': 'Strict' }); - setCookie('isAdmin', isAdmin.toString(), { 'max-age': '86400', 'path': '/', 'SameSite': 'Strict' }); - - router.push("/questions"); + await setCookiesAsync().then(() => { + router.push('/questions'); + }); } catch (error) { if (!isErrorSet) { setError("Something went wrong. Please retry shortly."); diff --git a/frontend/app/(authenticated)/session/[id]/page.tsx b/frontend/app/session/[id]/page.tsx similarity index 98% rename from frontend/app/(authenticated)/session/[id]/page.tsx rename to frontend/app/session/[id]/page.tsx index 405375108b..1c3be975a8 100644 --- a/frontend/app/(authenticated)/session/[id]/page.tsx +++ b/frontend/app/session/[id]/page.tsx @@ -19,7 +19,7 @@ import Markdown from 'react-markdown' const DynamicCodeEditor = dynamic(() => import('../code-editor/code-editor'), { ssr: false }); const DynamicTextEditor = dynamic( - () => import('@/app/(authenticated)/session/text-editor'), + () => import('@/app/session/text-editor'), { ssr: false, loading: () =>
@@ -57,7 +57,9 @@ export default function Session() { setTimeElapsed((prevTime) => prevTime + 1); }, 1000); - return () => clearInterval(timerInterval); + return () => { + clearInterval(timerInterval); + }; }, []); const minutes = Math.floor(timeElapsed / 60); @@ -242,7 +244,7 @@ export default function Session() { return (
-
+
{minutes}:{seconds < 10 ? `0${seconds}` : seconds}
with diff --git a/frontend/app/(authenticated)/session/code-editor/code-editor.tsx b/frontend/app/session/code-editor/code-editor.tsx similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/code-editor.tsx rename to frontend/app/session/code-editor/code-editor.tsx diff --git a/frontend/app/(authenticated)/session/code-editor/lang-loader.tsx b/frontend/app/session/code-editor/lang-loader.tsx similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/lang-loader.tsx rename to frontend/app/session/code-editor/lang-loader.tsx diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Active4D.json b/frontend/app/session/code-editor/themes/Active4D.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Active4D.json rename to frontend/app/session/code-editor/themes/Active4D.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/All Hallows Eve.json b/frontend/app/session/code-editor/themes/All Hallows Eve.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/All Hallows Eve.json rename to frontend/app/session/code-editor/themes/All Hallows Eve.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Amy.json b/frontend/app/session/code-editor/themes/Amy.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Amy.json rename to frontend/app/session/code-editor/themes/Amy.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Birds of Paradise.json b/frontend/app/session/code-editor/themes/Birds of Paradise.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Birds of Paradise.json rename to frontend/app/session/code-editor/themes/Birds of Paradise.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Blackboard.json b/frontend/app/session/code-editor/themes/Blackboard.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Blackboard.json rename to frontend/app/session/code-editor/themes/Blackboard.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Brilliance Black.json b/frontend/app/session/code-editor/themes/Brilliance Black.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Brilliance Black.json rename to frontend/app/session/code-editor/themes/Brilliance Black.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Brilliance Dull.json b/frontend/app/session/code-editor/themes/Brilliance Dull.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Brilliance Dull.json rename to frontend/app/session/code-editor/themes/Brilliance Dull.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Chrome DevTools.json b/frontend/app/session/code-editor/themes/Chrome DevTools.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Chrome DevTools.json rename to frontend/app/session/code-editor/themes/Chrome DevTools.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Clouds Midnight.json b/frontend/app/session/code-editor/themes/Clouds Midnight.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Clouds Midnight.json rename to frontend/app/session/code-editor/themes/Clouds Midnight.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Clouds.json b/frontend/app/session/code-editor/themes/Clouds.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Clouds.json rename to frontend/app/session/code-editor/themes/Clouds.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Cobalt.json b/frontend/app/session/code-editor/themes/Cobalt.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Cobalt.json rename to frontend/app/session/code-editor/themes/Cobalt.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Cobalt2.json b/frontend/app/session/code-editor/themes/Cobalt2.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Cobalt2.json rename to frontend/app/session/code-editor/themes/Cobalt2.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Dawn.json b/frontend/app/session/code-editor/themes/Dawn.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Dawn.json rename to frontend/app/session/code-editor/themes/Dawn.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Dominion Day.json b/frontend/app/session/code-editor/themes/Dominion Day.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Dominion Day.json rename to frontend/app/session/code-editor/themes/Dominion Day.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Dracula.json b/frontend/app/session/code-editor/themes/Dracula.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Dracula.json rename to frontend/app/session/code-editor/themes/Dracula.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Dreamweaver.json b/frontend/app/session/code-editor/themes/Dreamweaver.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Dreamweaver.json rename to frontend/app/session/code-editor/themes/Dreamweaver.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Eiffel.json b/frontend/app/session/code-editor/themes/Eiffel.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Eiffel.json rename to frontend/app/session/code-editor/themes/Eiffel.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Espresso Libre.json b/frontend/app/session/code-editor/themes/Espresso Libre.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Espresso Libre.json rename to frontend/app/session/code-editor/themes/Espresso Libre.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/GitHub Dark.json b/frontend/app/session/code-editor/themes/GitHub Dark.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/GitHub Dark.json rename to frontend/app/session/code-editor/themes/GitHub Dark.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/GitHub Light.json b/frontend/app/session/code-editor/themes/GitHub Light.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/GitHub Light.json rename to frontend/app/session/code-editor/themes/GitHub Light.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/IDLE.json b/frontend/app/session/code-editor/themes/IDLE.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/IDLE.json rename to frontend/app/session/code-editor/themes/IDLE.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Katzenmilch.json b/frontend/app/session/code-editor/themes/Katzenmilch.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Katzenmilch.json rename to frontend/app/session/code-editor/themes/Katzenmilch.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Kuroir Theme.json b/frontend/app/session/code-editor/themes/Kuroir Theme.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Kuroir Theme.json rename to frontend/app/session/code-editor/themes/Kuroir Theme.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/LAZY.json b/frontend/app/session/code-editor/themes/LAZY.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/LAZY.json rename to frontend/app/session/code-editor/themes/LAZY.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/MagicWB (Amiga).json b/frontend/app/session/code-editor/themes/MagicWB (Amiga).json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/MagicWB (Amiga).json rename to frontend/app/session/code-editor/themes/MagicWB (Amiga).json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Merbivore Soft.json b/frontend/app/session/code-editor/themes/Merbivore Soft.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Merbivore Soft.json rename to frontend/app/session/code-editor/themes/Merbivore Soft.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Merbivore.json b/frontend/app/session/code-editor/themes/Merbivore.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Merbivore.json rename to frontend/app/session/code-editor/themes/Merbivore.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Monokai Bright.json b/frontend/app/session/code-editor/themes/Monokai Bright.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Monokai Bright.json rename to frontend/app/session/code-editor/themes/Monokai Bright.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Monokai.json b/frontend/app/session/code-editor/themes/Monokai.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Monokai.json rename to frontend/app/session/code-editor/themes/Monokai.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Night Owl.json b/frontend/app/session/code-editor/themes/Night Owl.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Night Owl.json rename to frontend/app/session/code-editor/themes/Night Owl.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Nord.json b/frontend/app/session/code-editor/themes/Nord.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Nord.json rename to frontend/app/session/code-editor/themes/Nord.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Oceanic Next.json b/frontend/app/session/code-editor/themes/Oceanic Next.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Oceanic Next.json rename to frontend/app/session/code-editor/themes/Oceanic Next.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/One Dark Pro Darker.json b/frontend/app/session/code-editor/themes/One Dark Pro Darker.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/One Dark Pro Darker.json rename to frontend/app/session/code-editor/themes/One Dark Pro Darker.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/One Dark Pro.json b/frontend/app/session/code-editor/themes/One Dark Pro.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/One Dark Pro.json rename to frontend/app/session/code-editor/themes/One Dark Pro.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Pastels on Dark.json b/frontend/app/session/code-editor/themes/Pastels on Dark.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Pastels on Dark.json rename to frontend/app/session/code-editor/themes/Pastels on Dark.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Slush and Poppies.json b/frontend/app/session/code-editor/themes/Slush and Poppies.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Slush and Poppies.json rename to frontend/app/session/code-editor/themes/Slush and Poppies.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Solarized-dark.json b/frontend/app/session/code-editor/themes/Solarized-dark.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Solarized-dark.json rename to frontend/app/session/code-editor/themes/Solarized-dark.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Solarized-light.json b/frontend/app/session/code-editor/themes/Solarized-light.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Solarized-light.json rename to frontend/app/session/code-editor/themes/Solarized-light.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/SpaceCadet.json b/frontend/app/session/code-editor/themes/SpaceCadet.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/SpaceCadet.json rename to frontend/app/session/code-editor/themes/SpaceCadet.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Sunburst.json b/frontend/app/session/code-editor/themes/Sunburst.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Sunburst.json rename to frontend/app/session/code-editor/themes/Sunburst.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Textmate (Mac Classic).json b/frontend/app/session/code-editor/themes/Textmate (Mac Classic).json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Textmate (Mac Classic).json rename to frontend/app/session/code-editor/themes/Textmate (Mac Classic).json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Tomorrow-Night-Blue.json b/frontend/app/session/code-editor/themes/Tomorrow-Night-Blue.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Tomorrow-Night-Blue.json rename to frontend/app/session/code-editor/themes/Tomorrow-Night-Blue.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Tomorrow-Night-Bright.json b/frontend/app/session/code-editor/themes/Tomorrow-Night-Bright.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Tomorrow-Night-Bright.json rename to frontend/app/session/code-editor/themes/Tomorrow-Night-Bright.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Tomorrow-Night-Eighties.json b/frontend/app/session/code-editor/themes/Tomorrow-Night-Eighties.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Tomorrow-Night-Eighties.json rename to frontend/app/session/code-editor/themes/Tomorrow-Night-Eighties.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Tomorrow-Night.json b/frontend/app/session/code-editor/themes/Tomorrow-Night.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Tomorrow-Night.json rename to frontend/app/session/code-editor/themes/Tomorrow-Night.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Tomorrow.json b/frontend/app/session/code-editor/themes/Tomorrow.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Tomorrow.json rename to frontend/app/session/code-editor/themes/Tomorrow.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Twilight.json b/frontend/app/session/code-editor/themes/Twilight.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Twilight.json rename to frontend/app/session/code-editor/themes/Twilight.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Upstream Sunburst.json b/frontend/app/session/code-editor/themes/Upstream Sunburst.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Upstream Sunburst.json rename to frontend/app/session/code-editor/themes/Upstream Sunburst.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Vibrant Ink.json b/frontend/app/session/code-editor/themes/Vibrant Ink.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Vibrant Ink.json rename to frontend/app/session/code-editor/themes/Vibrant Ink.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Xcode Classic Dark.json b/frontend/app/session/code-editor/themes/Xcode Classic Dark.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Xcode Classic Dark.json rename to frontend/app/session/code-editor/themes/Xcode Classic Dark.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Xcode Classic Light.json b/frontend/app/session/code-editor/themes/Xcode Classic Light.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Xcode Classic Light.json rename to frontend/app/session/code-editor/themes/Xcode Classic Light.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Xcode Default Dark.json b/frontend/app/session/code-editor/themes/Xcode Default Dark.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Xcode Default Dark.json rename to frontend/app/session/code-editor/themes/Xcode Default Dark.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/Zenburnesque.json b/frontend/app/session/code-editor/themes/Zenburnesque.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/Zenburnesque.json rename to frontend/app/session/code-editor/themes/Zenburnesque.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/iPlastic.json b/frontend/app/session/code-editor/themes/iPlastic.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/iPlastic.json rename to frontend/app/session/code-editor/themes/iPlastic.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/idleFingers.json b/frontend/app/session/code-editor/themes/idleFingers.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/idleFingers.json rename to frontend/app/session/code-editor/themes/idleFingers.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/krTheme.json b/frontend/app/session/code-editor/themes/krTheme.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/krTheme.json rename to frontend/app/session/code-editor/themes/krTheme.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/monoindustrial.json b/frontend/app/session/code-editor/themes/monoindustrial.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/monoindustrial.json rename to frontend/app/session/code-editor/themes/monoindustrial.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/theme-list.json b/frontend/app/session/code-editor/themes/theme-list.json similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/theme-list.json rename to frontend/app/session/code-editor/themes/theme-list.json diff --git a/frontend/app/(authenticated)/session/code-editor/themes/theme-loader.tsx b/frontend/app/session/code-editor/themes/theme-loader.tsx similarity index 100% rename from frontend/app/(authenticated)/session/code-editor/themes/theme-loader.tsx rename to frontend/app/session/code-editor/themes/theme-loader.tsx diff --git a/frontend/app/session/layout.tsx b/frontend/app/session/layout.tsx new file mode 100644 index 0000000000..46235ac12c --- /dev/null +++ b/frontend/app/session/layout.tsx @@ -0,0 +1,35 @@ +"use client" + +import { usePathname, useRouter } from "next/navigation"; +import { useEffect, useState } from "react"; +import { deleteAllCookies, getCookie } from "../utils/cookie-manager"; +import { isTokenExpired } from "../utils/token-utils"; + +export default function SessionLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + const pathname = usePathname(); + + const router = useRouter(); + + useEffect(() => { + const authenticateUser = async () => { + const token = getCookie('token'); + if (!token || await isTokenExpired(token)) { + deleteAllCookies(); + router.push('/auth/login'); + return; + } + }; + + authenticateUser(); + }, [pathname, router]); + + return ( +
+ {children} +
+ ); +} diff --git a/frontend/app/(authenticated)/session/loading.tsx b/frontend/app/session/loading.tsx similarity index 100% rename from frontend/app/(authenticated)/session/loading.tsx rename to frontend/app/session/loading.tsx diff --git a/frontend/app/(authenticated)/session/text-editor.tsx b/frontend/app/session/text-editor.tsx similarity index 100% rename from frontend/app/(authenticated)/session/text-editor.tsx rename to frontend/app/session/text-editor.tsx From a91dbbe6e9a2636cf2ac7db07c210caecad1f5fe Mon Sep 17 00:00:00 2001 From: Brendan Tan Date: Fri, 8 Nov 2024 02:48:37 +0800 Subject: [PATCH 4/4] Sort question history by date descending --- frontend/app/(authenticated)/profile/question-history/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/(authenticated)/profile/question-history/page.tsx b/frontend/app/(authenticated)/profile/question-history/page.tsx index 7582e4159e..b6fbe7de79 100644 --- a/frontend/app/(authenticated)/profile/question-history/page.tsx +++ b/frontend/app/(authenticated)/profile/question-history/page.tsx @@ -104,7 +104,7 @@ export default function UserQuestionHistory() { }) ); - setHistory(mappedQuestions); + setHistory(mappedQuestions.reverse()); } catch (err) { console.log("Error fetching questions from server:", err) } finally {