mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
ignoring assignments that cannot be parsed
This commit is contained in:
@@ -11,12 +11,12 @@ export const GET = async (
|
|||||||
}
|
}
|
||||||
) =>
|
) =>
|
||||||
await withErrorHandling(async () => {
|
await withErrorHandling(async () => {
|
||||||
const settings = await fileStorageService.assignments.getAssignment(
|
const assignment = await fileStorageService.assignments.getAssignment(
|
||||||
courseName,
|
courseName,
|
||||||
moduleName,
|
moduleName,
|
||||||
assignmentName
|
assignmentName
|
||||||
);
|
);
|
||||||
return Response.json(settings);
|
return Response.json(assignment);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const PUT = async (
|
export const PUT = async (
|
||||||
|
|||||||
@@ -6,10 +6,27 @@ export const GET = async (
|
|||||||
{
|
{
|
||||||
params: { courseName, moduleName },
|
params: { courseName, moduleName },
|
||||||
}: { params: { courseName: string; moduleName: string } }
|
}: { params: { courseName: string; moduleName: string } }
|
||||||
) => await withErrorHandling(async () => {
|
) =>
|
||||||
const settings = await fileStorageService.assignments.getAssignmentNames(
|
await withErrorHandling(async () => {
|
||||||
|
const names = await fileStorageService.assignments.getAssignmentNames(
|
||||||
courseName,
|
courseName,
|
||||||
moduleName
|
moduleName
|
||||||
);
|
);
|
||||||
return Response.json(settings);
|
const assignments = (
|
||||||
|
await Promise.all(
|
||||||
|
names.map(async (name) => {
|
||||||
|
try {
|
||||||
|
return await fileStorageService.assignments.getAssignment(
|
||||||
|
courseName,
|
||||||
|
moduleName,
|
||||||
|
name
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
).filter((a) => a !== null);
|
||||||
|
|
||||||
|
return Response.json(assignments);
|
||||||
|
});
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ import { LocalCourse } from "@/models/local/localCourse";
|
|||||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||||
import { withErrorHandling } from "@/services/withErrorHandling";
|
import { withErrorHandling } from "@/services/withErrorHandling";
|
||||||
|
|
||||||
export const GET = async () =>
|
// replace with get all settings
|
||||||
await withErrorHandling(async () => {
|
// export const GET = async () =>
|
||||||
const courses = await fileStorageService.getCourseNames();
|
// await withErrorHandling(async () => {
|
||||||
return Response.json(courses);
|
// const courses = await fileStorageService.getCourseNames();
|
||||||
});
|
// return Response.json(courses);
|
||||||
|
// });
|
||||||
|
|
||||||
export const POST = async (request: Request) =>
|
export const POST = async (request: Request) =>
|
||||||
await withErrorHandling(async () => {
|
await withErrorHandling(async () => {
|
||||||
|
|||||||
@@ -92,23 +92,15 @@ function DayTitle({ day, dayAsDate }: { day: string; dayAsDate: Date }) {
|
|||||||
<Link className="ms-1" href={getLectureUrl(courseName, day)}>
|
<Link className="ms-1" href={getLectureUrl(courseName, day)}>
|
||||||
{dayAsDate.getDate()}
|
{dayAsDate.getDate()}
|
||||||
</Link>
|
</Link>
|
||||||
<Modal buttonText="+" buttonClass="unstyled hover:font-bold px-1 mb-auto mt-0 pt-0">
|
<Modal
|
||||||
|
buttonText="+"
|
||||||
|
buttonClass="unstyled hover:font-bold px-1 mb-auto mt-0 pt-0"
|
||||||
|
>
|
||||||
{({ closeModal }) => (
|
{({ closeModal }) => (
|
||||||
<div>
|
<div>
|
||||||
<NewItemForm
|
<NewItemForm creationDate={day} onCreate={closeModal} />
|
||||||
creationDate={day}
|
|
||||||
onCreate={() => {
|
|
||||||
closeModal();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<br />
|
<br />
|
||||||
<button
|
<button onClick={closeModal}>close</button>
|
||||||
onClick={() => {
|
|
||||||
closeModal();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
close
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import {
|
import {
|
||||||
useAssignmentNamesQuery,
|
|
||||||
useAssignmentsQueries,
|
useAssignmentsQueries,
|
||||||
} from "@/hooks/localCourse/assignmentHooks";
|
} from "@/hooks/localCourse/assignmentHooks";
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import {
|
import { QueryClientProvider } from "@tanstack/react-query";
|
||||||
QueryClientProvider,
|
|
||||||
} from "@tanstack/react-query";
|
|
||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||||
import { getQueryClient } from "./providersQueryClientUtils";
|
import { getQueryClient } from "./providersQueryClientUtils";
|
||||||
|
import { SuspenseAndErrorHandling } from "@/components/SuspenseAndErrorHandling";
|
||||||
|
|
||||||
export default function Providers({ children }: { children: ReactNode }) {
|
export default function Providers({ children }: { children: ReactNode }) {
|
||||||
// NOTE: Avoid useState when initializing the query client if you don't
|
// NOTE: Avoid useState when initializing the query client if you don't
|
||||||
@@ -16,9 +14,11 @@ export default function Providers({ children }: { children: ReactNode }) {
|
|||||||
const queryClient = getQueryClient();
|
const queryClient = getQueryClient();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<SuspenseAndErrorHandling>
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
{/* <ReactQueryDevtools initialIsOpen={false} /> */}
|
{/* <ReactQueryDevtools initialIsOpen={false} /> */}
|
||||||
{children}
|
{children}
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
|
</SuspenseAndErrorHandling>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { isServer, QueryClient } from "@tanstack/react-query";
|
import { isServer, QueryCache, QueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
export function makeQueryClient() {
|
export function makeQueryClient() {
|
||||||
return new QueryClient({
|
return new QueryClient({
|
||||||
@@ -13,6 +13,9 @@ export function makeQueryClient() {
|
|||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
queryCache: new QueryCache({
|
||||||
|
onError: (e) => console.log("error in query client", e),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { isServer } from "@tanstack/react-query";
|
|
||||||
import React, { ReactNode, useEffect, useState } from "react";
|
import React, { ReactNode, useEffect, useState } from "react";
|
||||||
|
|
||||||
export default function ClientOnly({ children }: { children: ReactNode }) {
|
export default function ClientOnly({ children }: { children: ReactNode }) {
|
||||||
@@ -7,7 +6,7 @@ export default function ClientOnly({ children }: { children: ReactNode }) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsClient(true);
|
setIsClient(true);
|
||||||
}, [isServer]);
|
}, []);
|
||||||
|
|
||||||
if (!isClient) return <></>;
|
if (!isClient) return <></>;
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
|
|||||||
@@ -84,14 +84,18 @@ const loadAllModuleData = async (courseName: string, moduleName: string) => {
|
|||||||
|
|
||||||
const [assignments, quizzes, pages] = await Promise.all([
|
const [assignments, quizzes, pages] = await Promise.all([
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
assignmentNames.map(
|
assignmentNames.map(async (assignmentName) => {
|
||||||
async (assignmentName) =>
|
try {
|
||||||
await fileStorageService.assignments.getAssignment(
|
return await fileStorageService.assignments.getAssignment(
|
||||||
courseName,
|
courseName,
|
||||||
moduleName,
|
moduleName,
|
||||||
assignmentName
|
assignmentName
|
||||||
)
|
);
|
||||||
)
|
} catch (error) {
|
||||||
|
console.error(`Error fetching assignment: ${assignmentName}`, error);
|
||||||
|
return null; // or any other placeholder value
|
||||||
|
}
|
||||||
|
})
|
||||||
),
|
),
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
quizNames.map(
|
quizNames.map(
|
||||||
@@ -115,12 +119,12 @@ const loadAllModuleData = async (courseName: string, moduleName: string) => {
|
|||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const assignmentsLoaded = assignments.filter(a => a !== null);
|
||||||
return {
|
return {
|
||||||
moduleName,
|
moduleName,
|
||||||
assignmentNames,
|
|
||||||
pageNames,
|
pageNames,
|
||||||
quizNames,
|
quizNames,
|
||||||
assignments,
|
assignments: assignmentsLoaded,
|
||||||
quizzes,
|
quizzes,
|
||||||
pages,
|
pages,
|
||||||
};
|
};
|
||||||
@@ -129,7 +133,6 @@ const loadAllModuleData = async (courseName: string, moduleName: string) => {
|
|||||||
const hydrateModuleData = async (
|
const hydrateModuleData = async (
|
||||||
{
|
{
|
||||||
moduleName,
|
moduleName,
|
||||||
assignmentNames,
|
|
||||||
pageNames,
|
pageNames,
|
||||||
quizNames,
|
quizNames,
|
||||||
assignments,
|
assignments,
|
||||||
@@ -137,7 +140,6 @@ const hydrateModuleData = async (
|
|||||||
pages,
|
pages,
|
||||||
}: {
|
}: {
|
||||||
moduleName: string;
|
moduleName: string;
|
||||||
assignmentNames: string[];
|
|
||||||
pageNames: string[];
|
pageNames: string[];
|
||||||
quizNames: string[];
|
quizNames: string[];
|
||||||
assignments: LocalAssignment[];
|
assignments: LocalAssignment[];
|
||||||
@@ -148,8 +150,8 @@ const hydrateModuleData = async (
|
|||||||
queryClient: QueryClient
|
queryClient: QueryClient
|
||||||
) => {
|
) => {
|
||||||
await queryClient.prefetchQuery({
|
await queryClient.prefetchQuery({
|
||||||
queryKey: localCourseKeys.assignmentNames(courseName, moduleName),
|
queryKey: localCourseKeys.allAssignments(courseName, moduleName),
|
||||||
queryFn: () => assignmentNames,
|
queryFn: () => assignments,
|
||||||
});
|
});
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
assignments.map(
|
assignments.map(
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import {
|
|||||||
import { useCourseContext } from "@/app/course/[courseName]/context/courseContext";
|
import { useCourseContext } from "@/app/course/[courseName]/context/courseContext";
|
||||||
import { axiosClient } from "@/services/axiosUtils";
|
import { axiosClient } from "@/services/axiosUtils";
|
||||||
|
|
||||||
export const getAssignmentNamesQueryConfig = (
|
export const getAllAssignmentsQueryConfig = (
|
||||||
courseName: string,
|
courseName: string,
|
||||||
moduleName: string
|
moduleName: string
|
||||||
) => ({
|
) => ({
|
||||||
queryKey: localCourseKeys.assignmentNames(courseName, moduleName),
|
queryKey: localCourseKeys.allAssignments(courseName, moduleName),
|
||||||
queryFn: async (): Promise<string[]> => {
|
queryFn: async (): Promise<LocalAssignment[]> => {
|
||||||
const url =
|
const url =
|
||||||
"/api/courses/" +
|
"/api/courses/" +
|
||||||
encodeURIComponent(courseName) +
|
encodeURIComponent(courseName) +
|
||||||
@@ -28,11 +28,9 @@ export const getAssignmentNamesQueryConfig = (
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useAssignmentNamesQuery = (moduleName: string) => {
|
export const useAllAssignmentNamesQuery = (moduleName: string) => {
|
||||||
const { courseName } = useCourseContext();
|
const { courseName } = useCourseContext();
|
||||||
return useSuspenseQuery(
|
return useSuspenseQuery(getAllAssignmentsQueryConfig(courseName, moduleName));
|
||||||
getAssignmentNamesQueryConfig(courseName, moduleName)
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAssignmentQueryConfig = (
|
export const getAssignmentQueryConfig = (
|
||||||
@@ -72,11 +70,11 @@ export const useAssignmentQuery = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useAssignmentsQueries = (moduleName: string) => {
|
export const useAssignmentsQueries = (moduleName: string) => {
|
||||||
const { data: assignmentNames } = useAssignmentNamesQuery(moduleName);
|
const { data: allAssignments } = useAllAssignmentNamesQuery(moduleName);
|
||||||
const { courseName } = useCourseContext();
|
const { courseName } = useCourseContext();
|
||||||
return useSuspenseQueries({
|
return useSuspenseQueries({
|
||||||
queries: assignmentNames.map((name) =>
|
queries: allAssignments.map((assignment) =>
|
||||||
getAssignmentQueryConfig(courseName, moduleName, name)
|
getAssignmentQueryConfig(courseName, moduleName, assignment.name)
|
||||||
),
|
),
|
||||||
combine: (results) => ({
|
combine: (results) => ({
|
||||||
data: results.map((r) => r.data),
|
data: results.map((r) => r.data),
|
||||||
@@ -114,7 +112,7 @@ export const useUpdateAssignmentMutation = () => {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
queryClient.removeQueries({
|
queryClient.removeQueries({
|
||||||
queryKey: localCourseKeys.assignmentNames(
|
queryKey: localCourseKeys.allAssignments(
|
||||||
courseName,
|
courseName,
|
||||||
previousModuleName
|
previousModuleName
|
||||||
),
|
),
|
||||||
@@ -140,7 +138,7 @@ export const useUpdateAssignmentMutation = () => {
|
|||||||
},
|
},
|
||||||
onSuccess: async (_, { moduleName, assignmentName }) => {
|
onSuccess: async (_, { moduleName, assignmentName }) => {
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: localCourseKeys.assignmentNames(courseName, moduleName),
|
queryKey: localCourseKeys.allAssignments(courseName, moduleName),
|
||||||
});
|
});
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: localCourseKeys.assignment(
|
queryKey: localCourseKeys.assignment(
|
||||||
@@ -181,7 +179,7 @@ export const useCreateAssignmentMutation = () => {
|
|||||||
},
|
},
|
||||||
onSuccess: async (_, { moduleName, assignmentName }) => {
|
onSuccess: async (_, { moduleName, assignmentName }) => {
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: localCourseKeys.assignmentNames(courseName, moduleName),
|
queryKey: localCourseKeys.allAssignments(courseName, moduleName),
|
||||||
});
|
});
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: localCourseKeys.assignment(
|
queryKey: localCourseKeys.assignment(
|
||||||
@@ -205,7 +203,6 @@ export const useDeleteAssignmentMutation = () => {
|
|||||||
moduleName: string;
|
moduleName: string;
|
||||||
assignmentName: string;
|
assignmentName: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
queryClient.removeQueries({
|
queryClient.removeQueries({
|
||||||
queryKey: localCourseKeys.assignment(
|
queryKey: localCourseKeys.assignment(
|
||||||
courseName,
|
courseName,
|
||||||
@@ -214,10 +211,7 @@ export const useDeleteAssignmentMutation = () => {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
queryClient.removeQueries({
|
queryClient.removeQueries({
|
||||||
queryKey: localCourseKeys.assignmentNames(
|
queryKey: localCourseKeys.allAssignments(courseName, moduleName),
|
||||||
courseName,
|
|
||||||
moduleName
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
const url =
|
const url =
|
||||||
"/api/courses/" +
|
"/api/courses/" +
|
||||||
@@ -230,7 +224,7 @@ export const useDeleteAssignmentMutation = () => {
|
|||||||
},
|
},
|
||||||
onSuccess: async (_, { moduleName, assignmentName }) => {
|
onSuccess: async (_, { moduleName, assignmentName }) => {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: localCourseKeys.assignmentNames(courseName, moduleName),
|
queryKey: localCourseKeys.allAssignments(courseName, moduleName),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ export const localCourseKeys = {
|
|||||||
"modules",
|
"modules",
|
||||||
{ type: "names" } as const,
|
{ type: "names" } as const,
|
||||||
] as const,
|
] as const,
|
||||||
assignmentNames: (courseName: string, moduleName: string) =>
|
allAssignments: (courseName: string, moduleName: string) =>
|
||||||
[
|
[
|
||||||
"course details",
|
"course details",
|
||||||
courseName,
|
courseName,
|
||||||
"modules",
|
"modules",
|
||||||
moduleName,
|
moduleName,
|
||||||
"assignments",
|
"assignments",
|
||||||
{ type: "names" },
|
{ type: "all assignments" },
|
||||||
] as const,
|
] as const,
|
||||||
quizNames: (courseName: string, moduleName: string) =>
|
quizNames: (courseName: string, moduleName: string) =>
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from "@tanstack/react-query";
|
} from "@tanstack/react-query";
|
||||||
import { localCourseKeys } from "./localCourseKeys";
|
import { localCourseKeys } from "./localCourseKeys";
|
||||||
import {
|
import {
|
||||||
getAssignmentNamesQueryConfig,
|
getAllAssignmentsQueryConfig,
|
||||||
getAssignmentQueryConfig,
|
getAssignmentQueryConfig,
|
||||||
} from "./assignmentHooks";
|
} from "./assignmentHooks";
|
||||||
import { getPageNamesQueryConfig, getPageQueryConfig } from "./pageHooks";
|
import { getPageNamesQueryConfig, getPageQueryConfig } from "./pageHooks";
|
||||||
@@ -77,34 +77,34 @@ export const useAllCourseDataQuery = () => {
|
|||||||
const { courseName } = useCourseContext();
|
const { courseName } = useCourseContext();
|
||||||
const { data: moduleNames } = useModuleNamesQuery();
|
const { data: moduleNames } = useModuleNamesQuery();
|
||||||
|
|
||||||
const { data: assignmentNamesAndModules } = useSuspenseQueries({
|
const { data: assignmentsAndModules } = useSuspenseQueries({
|
||||||
queries: moduleNames.map((moduleName) =>
|
queries: moduleNames.map((moduleName) =>
|
||||||
getAssignmentNamesQueryConfig(courseName, moduleName)
|
getAllAssignmentsQueryConfig(courseName, moduleName)
|
||||||
),
|
),
|
||||||
combine: (results) => ({
|
combine: (results) => ({
|
||||||
data: results.flatMap((r, i) =>
|
data: results.flatMap((r, i) =>
|
||||||
r.data.map((assignmentName) => ({
|
r.data.map((assignment) => ({
|
||||||
moduleName: moduleNames[i],
|
moduleName: moduleNames[i],
|
||||||
assignmentName,
|
assignment,
|
||||||
}))
|
}))
|
||||||
),
|
),
|
||||||
pending: results.some((r) => r.isPending),
|
pending: results.some((r) => r.isPending),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: assignmentsAndModules } = useSuspenseQueries({
|
// const { data: assignmentsAndModules } = useSuspenseQueries({
|
||||||
queries: assignmentNamesAndModules.map(
|
// queries: assignmentsAndModules.map(
|
||||||
({ moduleName, assignmentName }, i) =>
|
// ({ moduleName, assignment }, i) =>
|
||||||
getAssignmentQueryConfig(courseName, moduleName, assignmentName)
|
// getAssignmentQueryConfig(courseName, moduleName, assignment)
|
||||||
),
|
// ),
|
||||||
combine: (results) => ({
|
// combine: (results) => ({
|
||||||
data: results.flatMap((r, i) => ({
|
// data: results.flatMap((r, i) => ({
|
||||||
moduleName: assignmentNamesAndModules[i].moduleName,
|
// moduleName: assignmentsAndModules[i].moduleName,
|
||||||
assignment: r.data,
|
// assignment: r.data,
|
||||||
})),
|
// })),
|
||||||
pending: results.some((r) => r.isPending),
|
// pending: results.some((r) => r.isPending),
|
||||||
}),
|
// }),
|
||||||
});
|
// });
|
||||||
|
|
||||||
const { data: quizNamesAndModules } = useSuspenseQueries({
|
const { data: quizNamesAndModules } = useSuspenseQueries({
|
||||||
queries: moduleNames.map((moduleName) =>
|
queries: moduleNames.map((moduleName) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user