Exam generation rework, batch user tables, fastapi endpoint switch
This commit is contained in:
20
src/utils/popout.ts
Normal file
20
src/utils/popout.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NextRouter } from "next/router";
|
||||
|
||||
const openDetachedTab = (uri: string, router: NextRouter, name = 'ExamPreview', width = 1000, height = 600) => {
|
||||
const left = (window.screen.width - width) / 2;
|
||||
const top = (window.screen.height - height) / 2;
|
||||
|
||||
const features = `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes,status=yes`;
|
||||
const url = router.basePath + `/${uri}`;
|
||||
const newWindow = window.open(url, name, features);
|
||||
|
||||
if (newWindow) {
|
||||
newWindow.focus();
|
||||
} else {
|
||||
alert('Pop-up blocker may have prevented opening the new window. Please check your browser settings.');
|
||||
}
|
||||
|
||||
return newWindow;
|
||||
}
|
||||
|
||||
export default openDetachedTab;
|
||||
15
src/utils/query.to.url.params.ts
Normal file
15
src/utils/query.to.url.params.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { NextApiRequest } from "next";
|
||||
|
||||
export default function queryToURLSearchParams(req: NextApiRequest): URLSearchParams {
|
||||
const queryEntries = Object.entries(req.query);
|
||||
const searchParams = new URLSearchParams();
|
||||
for (const [key, value] of queryEntries) {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(v => searchParams.append(key, v));
|
||||
} else if (value !== undefined) {
|
||||
searchParams.append(key, value as string);
|
||||
}
|
||||
}
|
||||
|
||||
return searchParams;
|
||||
}
|
||||
5
src/utils/type.check.ts
Normal file
5
src/utils/type.check.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { FillBlanksMCOption } from "@/interfaces/exam";
|
||||
|
||||
export const typeCheckWordsMC = (words: any[]): words is FillBlanksMCOption[] => {
|
||||
return Array.isArray(words) && words.every((word) => word && typeof word === "object" && "id" in word && "options" in word);
|
||||
};
|
||||
Reference in New Issue
Block a user