Skip to content

Commit 54d3256

Browse files
committed
Run prettier
1 parent d851b8d commit 54d3256

19 files changed

Lines changed: 566 additions & 405 deletions

app/courses/[courseId]/uml/[umlId]/lecturer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ export default function LecturerUmlAssignment() {
4646
) || [];
4747

4848
// Defensive: filter out empty values and duplicates before querying user infos.
49-
return Array.from(new Set(ids.filter((id: any) => typeof id === "string" && id.length > 0)));
49+
return Array.from(
50+
new Set(ids.filter((id: any) => typeof id === "string" && id.length > 0))
51+
);
5052
}, [data?.getUmlExerciseByAssessmentId?.studentSubmissions]);
5153

5254
// Fetch user infos for all students

app/courses/[courseId]/uml/[umlId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ export default function UMLAssignmentPage() {
3030
default:
3131
return <PageError message="Unauthorized or unknown view state." />;
3232
}
33-
}
33+
}

components/EditContentModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,4 @@ export function EditContentModal({
499499
)}
500500
</>
501501
);
502-
}
502+
}

components/Navbar.tsx

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ type XpLevelInfo = {
123123
xpInLevel: number;
124124
xpRequiredForLevelUp: number;
125125
};
126-
const xpLevelCache = new Map<string, { value: XpLevelInfo; timestamp: number }>();
126+
const xpLevelCache = new Map<
127+
string,
128+
{ value: XpLevelInfo; timestamp: number }
129+
>();
127130

128131
/** ---------------- Utilities ---------------- */
129132
function useIsTutor(_frag: NavbarIsTutor$key) {
@@ -573,68 +576,74 @@ function UserInfo({ tutor, userId }: { tutor: boolean; userId: string }) {
573576

574577
// central XP fetcher (Relay)
575578
const relayEnv = useRelayEnvironment();
576-
const fetchXP = useCallback(async (force = false) => {
577-
if (!userId) return;
578-
579-
const now = Date.now();
580-
const cached = xpLevelCache.get(userId);
581-
if (!force && cached && now - cached.timestamp < XP_CACHE_TTL_MS) {
582-
setLevelInfo(cached.value);
583-
return;
584-
}
585-
if (!force && xpFetchInFlightRef.current) return;
586-
if (!force && now - xpLastFetchAtRef.current < 1500) return;
587-
588-
xpFetchInFlightRef.current = true;
589-
xpLastFetchAtRef.current = now;
590-
591-
try {
592-
const query = graphql`
593-
query NavbarGetUserXPQuery($userID: ID!) {
594-
getUser(userID: $userID) {
595-
refUserID
596-
name
597-
email
598-
xpValue
599-
requiredXP
600-
exceedingXP
601-
level
579+
const fetchXP = useCallback(
580+
async (force = false) => {
581+
if (!userId) return;
582+
583+
const now = Date.now();
584+
const cached = xpLevelCache.get(userId);
585+
if (!force && cached && now - cached.timestamp < XP_CACHE_TTL_MS) {
586+
setLevelInfo(cached.value);
587+
return;
588+
}
589+
if (!force && xpFetchInFlightRef.current) return;
590+
if (!force && now - xpLastFetchAtRef.current < 1500) return;
591+
592+
xpFetchInFlightRef.current = true;
593+
xpLastFetchAtRef.current = now;
594+
595+
try {
596+
const query = graphql`
597+
query NavbarGetUserXPQuery($userID: ID!) {
598+
getUser(userID: $userID) {
599+
refUserID
600+
name
601+
email
602+
xpValue
603+
requiredXP
604+
exceedingXP
605+
level
606+
}
602607
}
608+
`;
609+
const levelData = await fetchQuery(relayEnv, query, {
610+
userID: userId,
611+
}).toPromise();
612+
613+
const rawUser = (levelData as any)?.getUser;
614+
const payload: any = Array.isArray(rawUser)
615+
? rawUser[0] ?? null
616+
: rawUser ?? null;
617+
618+
if (!payload) {
619+
const fallback = { level: 0, xpInLevel: 0, xpRequiredForLevelUp: 1 };
620+
setLevelInfo(fallback);
621+
xpLevelCache.set(userId, { value: fallback, timestamp: Date.now() });
622+
return;
603623
}
604-
`;
605-
const levelData = await fetchQuery(relayEnv, query, {
606-
userID: userId,
607-
}).toPromise();
608-
609-
const rawUser = (levelData as any)?.getUser;
610-
const payload: any = Array.isArray(rawUser)
611-
? rawUser[0] ?? null
612-
: rawUser ?? null;
613-
614-
if (!payload) {
615-
const fallback = { level: 0, xpInLevel: 0, xpRequiredForLevelUp: 1 };
616-
setLevelInfo(fallback);
617-
xpLevelCache.set(userId, { value: fallback, timestamp: Date.now() });
618-
return;
624+
const requiredXP = Number(payload.requiredXP ?? 0);
625+
const exceedingXP = Number(payload.exceedingXP ?? 0);
626+
const level = Number(payload.level ?? 0);
627+
const nextLevelInfo = {
628+
level: Number.isFinite(level) ? level : 0,
629+
xpInLevel: Number.isFinite(exceedingXP) ? exceedingXP : 0,
630+
xpRequiredForLevelUp:
631+
Number.isFinite(requiredXP) && requiredXP > 0 ? requiredXP : 1,
632+
};
633+
setLevelInfo(nextLevelInfo);
634+
xpLevelCache.set(userId, {
635+
value: nextLevelInfo,
636+
timestamp: Date.now(),
637+
});
638+
} catch (e) {
639+
console.error("[Navbar XP] fetch failed", e);
640+
setLevelInfo({ level: 0, xpInLevel: 0, xpRequiredForLevelUp: 1 });
641+
} finally {
642+
xpFetchInFlightRef.current = false;
619643
}
620-
const requiredXP = Number(payload.requiredXP ?? 0);
621-
const exceedingXP = Number(payload.exceedingXP ?? 0);
622-
const level = Number(payload.level ?? 0);
623-
const nextLevelInfo = {
624-
level: Number.isFinite(level) ? level : 0,
625-
xpInLevel: Number.isFinite(exceedingXP) ? exceedingXP : 0,
626-
xpRequiredForLevelUp:
627-
Number.isFinite(requiredXP) && requiredXP > 0 ? requiredXP : 1,
628-
};
629-
setLevelInfo(nextLevelInfo);
630-
xpLevelCache.set(userId, { value: nextLevelInfo, timestamp: Date.now() });
631-
} catch (e) {
632-
console.error("[Navbar XP] fetch failed", e);
633-
setLevelInfo({ level: 0, xpInLevel: 0, xpRequiredForLevelUp: 1 });
634-
} finally {
635-
xpFetchInFlightRef.current = false;
636-
}
637-
}, [relayEnv, userId]);
644+
},
645+
[relayEnv, userId]
646+
);
638647

639648
// initial fetch and on identity changes
640649
useEffect(() => {

components/content-link/ContentLink.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function ContentLink({
141141
content.__typename === "MediaContent"
142142
? "Media"
143143
: content.__typename === "UmlAssessment"
144-
? "UML"
144+
? "UML"
145145
: content.__typename === "FlashcardSetAssessment"
146146
? "Flashcard"
147147
: content.__typename === "QuizAssessment"
@@ -181,12 +181,11 @@ export function ContentLink({
181181

182182
let icon =
183183
content.__typename === "UmlAssessment" ? (
184-
<SchemaIcon
185-
className="!w-1/2 !h-1/2"
186-
sx={{ color: disabled ? "text.disabled" : "text.secondary" }}
187-
/>
188-
) :
189-
content.__typename === "MediaContent" ? (
184+
<SchemaIcon
185+
className="!w-1/2 !h-1/2"
186+
sx={{ color: disabled ? "text.disabled" : "text.secondary" }}
187+
/>
188+
) : content.__typename === "MediaContent" ? (
190189
<div
191190
className={
192191
content.mediaRecords && content.mediaRecords.length > 1

components/hylimo/DownloadDigram.tsx

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ interface DiagramDownloadProps {
1919
variant?: "button" | "icon";
2020
}
2121

22-
export function DiagramDownload({ diagram, fileName, sourceCode, variant = "button" }: DiagramDownloadProps) {
22+
export function DiagramDownload({
23+
diagram,
24+
fileName,
25+
sourceCode,
26+
variant = "button",
27+
}: DiagramDownloadProps) {
2328
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
2429
const isOpen = Boolean(anchorEl);
2530

@@ -42,7 +47,7 @@ export function DiagramDownload({ diagram, fileName, sourceCode, variant = "butt
4247
try {
4348
const svgContent = await svgRenderer.render(diagram, textAsPath);
4449
const svgBlob = new Blob([svgContent], {
45-
type: "image/svg+xml;charset=utf-8"
50+
type: "image/svg+xml;charset=utf-8",
4651
});
4752
saveAs(svgBlob, `${fileName}.svg`);
4853
handleClose();
@@ -53,20 +58,17 @@ export function DiagramDownload({ diagram, fileName, sourceCode, variant = "butt
5358
[diagram, fileName, svgRenderer]
5459
);
5560

56-
const downloadPDF = useCallback(
57-
async () => {
58-
if (!diagram) return;
61+
const downloadPDF = useCallback(async () => {
62+
if (!diagram) return;
5963

60-
try {
61-
const pdf = await pdfRenderer.render(diagram, "#ffffff");
62-
saveAs(new Blob(pdf, { type: "application/pdf" }), `${fileName}.pdf`);
63-
handleClose();
64-
} catch (error) {
65-
console.error("Error downloading PDF:", error);
66-
}
67-
},
68-
[diagram, fileName, pdfRenderer]
69-
);
64+
try {
65+
const pdf = await pdfRenderer.render(diagram, "#ffffff");
66+
saveAs(new Blob(pdf, { type: "application/pdf" }), `${fileName}.pdf`);
67+
handleClose();
68+
} catch (error) {
69+
console.error("Error downloading PDF:", error);
70+
}
71+
}, [diagram, fileName, pdfRenderer]);
7072

7173
const downloadSource = useCallback(() => {
7274
if (!sourceCode) return;
@@ -104,34 +106,25 @@ export function DiagramDownload({ diagram, fileName, sourceCode, variant = "butt
104106
onClose={handleClose}
105107
anchorOrigin={{
106108
vertical: "bottom",
107-
horizontal: "left"
109+
horizontal: "left",
108110
}}
109111
transformOrigin={{
110112
vertical: "top",
111-
horizontal: "left"
113+
horizontal: "left",
112114
}}
113115
>
114-
<MenuItem
115-
onClick={() => downloadSVG(false)}
116-
disabled={!diagram}
117-
>
116+
<MenuItem onClick={() => downloadSVG(false)} disabled={!diagram}>
118117
SVG
119118
</MenuItem>
120119
<Tooltip
121120
title="Powerpoint and many others do not support embedded fonts, so the text is converted to a path instead"
122121
placement="right"
123122
>
124-
<MenuItem
125-
onClick={() => downloadSVG(true)}
126-
disabled={!diagram}
127-
>
123+
<MenuItem onClick={() => downloadSVG(true)} disabled={!diagram}>
128124
SVG (text as path)
129125
</MenuItem>
130126
</Tooltip>
131-
<MenuItem
132-
onClick={downloadPDF}
133-
disabled={!diagram}
134-
>
127+
<MenuItem onClick={downloadPDF} disabled={!diagram}>
135128
PDF
136129
</MenuItem>
137130
<MenuItem onClick={downloadSource} disabled={!sourceCode}>
@@ -140,4 +133,4 @@ export function DiagramDownload({ diagram, fileName, sourceCode, variant = "butt
140133
</Menu>
141134
</>
142135
);
143-
}
136+
}

components/hylimo/FullscreenEditorDialog.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Slide,
1010
Stack,
1111
Toolbar,
12-
Typography
12+
Typography,
1313
} from "@mui/material";
1414
import React from "react";
1515

@@ -68,7 +68,7 @@ export default function FullscreenEditorDialog({
6868
width: "100%",
6969
overflow: "auto",
7070
display: "flex",
71-
flexDirection: "column"
71+
flexDirection: "column",
7272
}}
7373
>
7474
{infoContent && (
@@ -85,7 +85,9 @@ export default function FullscreenEditorDialog({
8585
</Paper>
8686
</Slide>
8787
)}
88-
<Box sx={{ flex: 1, minHeight: 0, width: "100%" }}>{open ? children : null}</Box>
88+
<Box sx={{ flex: 1, minHeight: 0, width: "100%" }}>
89+
{open ? children : null}
90+
</Box>
8991
</Box>
9092
</Dialog>
9193
);

0 commit comments

Comments
 (0)