mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
doing more trpc, still working on preloading
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
"@next/env": "^15.0.3",
|
||||
"@tanstack/react-query": "^5.59.20",
|
||||
"@trpc/client": "11.0.0-rc.608",
|
||||
"@trpc/next": "11.0.0-rc.608",
|
||||
"@trpc/react-query": "11.0.0-rc.608",
|
||||
"@trpc/server": "11.0.0-rc.608",
|
||||
"jsdom": "^25.0.0",
|
||||
|
||||
30
nextjs/pnpm-lock.yaml
generated
30
nextjs/pnpm-lock.yaml
generated
@@ -17,9 +17,6 @@ importers:
|
||||
'@trpc/client':
|
||||
specifier: 11.0.0-rc.608
|
||||
version: 11.0.0-rc.608(@trpc/server@11.0.0-rc.608)
|
||||
'@trpc/next':
|
||||
specifier: 11.0.0-rc.608
|
||||
version: 11.0.0-rc.608(@tanstack/react-query@5.59.20(react@18.3.1))(@trpc/client@11.0.0-rc.608(@trpc/server@11.0.0-rc.608))(@trpc/react-query@11.0.0-rc.608(@tanstack/react-query@5.59.20(react@18.3.1))(@trpc/client@11.0.0-rc.608(@trpc/server@11.0.0-rc.608))(@trpc/server@11.0.0-rc.608)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@trpc/server@11.0.0-rc.608)(next@15.0.2(@babel/core@7.26.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
'@trpc/react-query':
|
||||
specifier: 11.0.0-rc.608
|
||||
version: 11.0.0-rc.608(@tanstack/react-query@5.59.20(react@18.3.1))(@trpc/client@11.0.0-rc.608(@trpc/server@11.0.0-rc.608))(@trpc/server@11.0.0-rc.608)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
@@ -721,22 +718,6 @@ packages:
|
||||
peerDependencies:
|
||||
'@trpc/server': 11.0.0-rc.608+f75de97b3
|
||||
|
||||
'@trpc/next@11.0.0-rc.608':
|
||||
resolution: {integrity: sha512-dL+ifSaJIl+21P3LZ1JEl1uzqDD7pZ3iCs9uEnf3tjyZhbCuavnTL7faRDV6wZ6+L6opzKxIzeVNC4e490Ys0Q==}
|
||||
peerDependencies:
|
||||
'@tanstack/react-query': ^5.59.15
|
||||
'@trpc/client': 11.0.0-rc.608+f75de97b3
|
||||
'@trpc/react-query': 11.0.0-rc.608+f75de97b3
|
||||
'@trpc/server': 11.0.0-rc.608+f75de97b3
|
||||
next: 15.0.2
|
||||
react: '>=16.8.0'
|
||||
react-dom: '>=16.8.0'
|
||||
peerDependenciesMeta:
|
||||
'@tanstack/react-query':
|
||||
optional: true
|
||||
'@trpc/react-query':
|
||||
optional: true
|
||||
|
||||
'@trpc/react-query@11.0.0-rc.608':
|
||||
resolution: {integrity: sha512-V0UJltzCfdn3PqePqbB8TK64aNXVBpdoLEC4OdMtTYiZTsAnH1jTwrNOBji3Xwm8Q0n4jaUDrIz5M/5IPjYrGg==}
|
||||
peerDependencies:
|
||||
@@ -3075,17 +3056,6 @@ snapshots:
|
||||
dependencies:
|
||||
'@trpc/server': 11.0.0-rc.608
|
||||
|
||||
'@trpc/next@11.0.0-rc.608(@tanstack/react-query@5.59.20(react@18.3.1))(@trpc/client@11.0.0-rc.608(@trpc/server@11.0.0-rc.608))(@trpc/react-query@11.0.0-rc.608(@tanstack/react-query@5.59.20(react@18.3.1))(@trpc/client@11.0.0-rc.608(@trpc/server@11.0.0-rc.608))(@trpc/server@11.0.0-rc.608)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@trpc/server@11.0.0-rc.608)(next@15.0.2(@babel/core@7.26.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
||||
dependencies:
|
||||
'@trpc/client': 11.0.0-rc.608(@trpc/server@11.0.0-rc.608)
|
||||
'@trpc/server': 11.0.0-rc.608
|
||||
next: 15.0.2(@babel/core@7.26.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
react: 18.3.1
|
||||
react-dom: 18.3.1(react@18.3.1)
|
||||
optionalDependencies:
|
||||
'@tanstack/react-query': 5.59.20(react@18.3.1)
|
||||
'@trpc/react-query': 11.0.0-rc.608(@tanstack/react-query@5.59.20(react@18.3.1))(@trpc/client@11.0.0-rc.608(@trpc/server@11.0.0-rc.608))(@trpc/server@11.0.0-rc.608)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
|
||||
'@trpc/react-query@11.0.0-rc.608(@tanstack/react-query@5.59.20(react@18.3.1))(@trpc/client@11.0.0-rc.608(@trpc/server@11.0.0-rc.608))(@trpc/server@11.0.0-rc.608)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
||||
dependencies:
|
||||
'@tanstack/react-query': 5.59.20(react@18.3.1)
|
||||
|
||||
@@ -4,7 +4,7 @@ import { getCourseUrl } from "@/services/urlUtils";
|
||||
import Link from "next/link";
|
||||
|
||||
export default function CourseList() {
|
||||
const { data: allSettings } = useLocalCoursesSettingsQuery();
|
||||
const [allSettings] = useLocalCoursesSettingsQuery();
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
import { CalendarMonthModel } from "./calendarMonthUtils";
|
||||
import { DayOfWeek } from "@/models/local/localCourse";
|
||||
import { DayOfWeek } from "@/models/local/localCourseSettings";
|
||||
import { Expandable } from "@/components/Expandable";
|
||||
import { CalendarWeek } from "./CalendarWeek";
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from "@/models/local/timeUtils";
|
||||
import { useDraggingContext } from "../../context/drag/draggingContext";
|
||||
import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||
import { getDayOfWeek } from "@/models/local/localCourse";
|
||||
import { getDayOfWeek } from "@/models/local/localCourseSettings";
|
||||
import { ItemInDay } from "./ItemInDay";
|
||||
import { useTodaysItems } from "./useTodaysItems";
|
||||
import { DayTitle } from "./DayTitle";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||
import { getDayOfWeek } from "@/models/local/localCourse";
|
||||
import { getDayOfWeek } from "@/models/local/localCourseSettings";
|
||||
import { getDateFromString } from "@/models/local/timeUtils";
|
||||
import { getLectureWeekName } from "@/services/fileStorage/utils/lectureUtils";
|
||||
import { getCourseUrl, getLecturePreviewUrl } from "@/services/urlUtils";
|
||||
|
||||
@@ -3,11 +3,12 @@ import CourseContextProvider from "../../context/CourseContextProvider";
|
||||
|
||||
export default async function LectureLayout({
|
||||
children,
|
||||
params: { courseName, lectureDay },
|
||||
params,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
params: { courseName: string; lectureDay: string };
|
||||
params: Promise<{ courseName: string; lectureDay: string }>;
|
||||
}) {
|
||||
const { courseName, lectureDay } = await params;
|
||||
const decodedCourseName = decodeURIComponent(courseName);
|
||||
if (courseName.includes(".js.map")) {
|
||||
console.log("cannot load course that is .js.map " + decodedCourseName);
|
||||
|
||||
@@ -4,11 +4,12 @@ import {
|
||||
getDateOnlyMarkdownString,
|
||||
} from "@/models/local/timeUtils";
|
||||
|
||||
export default function page({
|
||||
params: { lectureDay },
|
||||
export default async function page({
|
||||
params,
|
||||
}: {
|
||||
params: { lectureDay: string };
|
||||
params: Promise<{ lectureDay: string }>;
|
||||
}) {
|
||||
const { lectureDay } = await params;
|
||||
const decodedLectureDay = decodeURIComponent(lectureDay);
|
||||
console.log(decodedLectureDay);
|
||||
const lectureDate = getDateFromStringOrThrow(
|
||||
|
||||
@@ -4,11 +4,12 @@ import {
|
||||
} from "@/models/local/timeUtils";
|
||||
import LecturePreviewPage from "./LecturePreviewPage";
|
||||
|
||||
export default function Page({
|
||||
params: { lectureDay },
|
||||
export default async function Page({
|
||||
params,
|
||||
}: {
|
||||
params: { lectureDay: string };
|
||||
params: Promise<{ lectureDay: string }>;
|
||||
}) {
|
||||
const { lectureDay } = await params;
|
||||
const decodedLectureDay = decodeURIComponent(lectureDay);
|
||||
console.log(decodedLectureDay);
|
||||
const lectureDate = getDateFromStringOrThrow(
|
||||
|
||||
@@ -13,7 +13,7 @@ import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHoo
|
||||
import ClientOnly from "@/components/ClientOnly";
|
||||
import { SuspenseAndErrorHandling } from "@/components/SuspenseAndErrorHandling";
|
||||
import { AssignmentSubmissionType } from "@/models/local/assignment/assignmentSubmissionType";
|
||||
import { LocalCourseSettings } from "@/models/local/localCourse";
|
||||
import { LocalCourseSettings } from "@/models/local/localCourseSettings";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { AssignmentButtons } from "./AssignmentButtons";
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import React from "react";
|
||||
import EditAssignment from "./EditAssignment";
|
||||
import ClientOnly from "@/components/ClientOnly";
|
||||
|
||||
export default function Page({
|
||||
params: { moduleName, assignmentName },
|
||||
export default async function Page({
|
||||
params,
|
||||
}: {
|
||||
params: { assignmentName: string; moduleName: string };
|
||||
params: Promise<{ assignmentName: string; moduleName: string }>;
|
||||
}) {
|
||||
const { moduleName, assignmentName } = await params;
|
||||
const decodedAssignmentName = decodeURIComponent(assignmentName);
|
||||
const decodedModuleName = decodeURIComponent(moduleName);
|
||||
return (
|
||||
|
||||
@@ -2,10 +2,11 @@ import React from "react";
|
||||
import EditPage from "./EditPage";
|
||||
|
||||
export default async function Page({
|
||||
params: { moduleName, pageName },
|
||||
params,
|
||||
}: {
|
||||
params: { pageName: string; moduleName: string };
|
||||
params: Promise<{ pageName: string; moduleName: string }>;
|
||||
}) {
|
||||
const { moduleName, pageName } = await params;
|
||||
const decodedPageName = decodeURIComponent(pageName);
|
||||
const decodedModuleName = decodeURIComponent(moduleName);
|
||||
return <EditPage pageName={decodedPageName} moduleName={decodedModuleName} />;
|
||||
|
||||
@@ -2,10 +2,11 @@ import React from "react";
|
||||
import EditQuiz from "./EditQuiz";
|
||||
|
||||
export default async function Page({
|
||||
params: { moduleName, quizName },
|
||||
params,
|
||||
}: {
|
||||
params: { quizName: string; moduleName: string };
|
||||
params: Promise<{ quizName: string; moduleName: string }>;
|
||||
}) {
|
||||
const { moduleName, quizName } = await params;
|
||||
const decodedQuizName = decodeURIComponent(quizName)
|
||||
const decodedModuleName = decodeURIComponent(moduleName)
|
||||
return <EditQuiz quizName={decodedQuizName} moduleName={decodedModuleName} />;
|
||||
|
||||
@@ -13,7 +13,7 @@ import { useEmptyDirectoriesQuery } from "@/hooks/localCourse/storageDirectoryHo
|
||||
import { CanvasCourseModel } from "@/models/canvas/courses/canvasCourseModel";
|
||||
import { CanvasEnrollmentTermModel } from "@/models/canvas/enrollmentTerms/canvasEnrollmentTermModel";
|
||||
import { AssignmentSubmissionType } from "@/models/local/assignment/assignmentSubmissionType";
|
||||
import { DayOfWeek } from "@/models/local/localCourse";
|
||||
import { DayOfWeek } from "@/models/local/localCourseSettings";
|
||||
import { getCourseUrl } from "@/services/urlUtils";
|
||||
import { useRouter } from "next/navigation";
|
||||
import React, { useMemo, useState } from "react";
|
||||
@@ -81,7 +81,6 @@ export default function NewCourseForm() {
|
||||
if (formIsComplete) {
|
||||
createCourse
|
||||
.mutateAsync({
|
||||
modules: [],
|
||||
settings: {
|
||||
name: selectedDirectory,
|
||||
assignmentGroups: [],
|
||||
@@ -96,7 +95,7 @@ export default function NewCourseForm() {
|
||||
],
|
||||
defaultFileUploadTypes: ["pdf", "png", "jpg", "jpeg"],
|
||||
defaultLockHoursOffset: 0,
|
||||
holidays: []
|
||||
holidays: [],
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
@@ -140,7 +139,7 @@ function OtherSettings({
|
||||
setSelectedDaysOfWeek: React.Dispatch<React.SetStateAction<DayOfWeek[]>>;
|
||||
}) {
|
||||
const { data: canvasCourses } = useCourseListInTermQuery(selectedTerm.id);
|
||||
const { data: allSettings } = useLocalCoursesSettingsQuery();
|
||||
const [allSettings] = useLocalCoursesSettingsQuery();
|
||||
const { data: emptyDirectories } = useEmptyDirectoriesQuery();
|
||||
|
||||
const populatedCanvasCourseIds = allSettings.map((s) => s.canvasId);
|
||||
|
||||
@@ -7,7 +7,7 @@ import CourseContextProvider from "../course/[courseName]/context/CourseContextP
|
||||
import { Fragment } from "react";
|
||||
|
||||
export default function TodaysLectures() {
|
||||
const { data: allSettings } = useLocalCoursesSettingsQuery();
|
||||
const [allSettings] = useLocalCoursesSettingsQuery();
|
||||
return (
|
||||
<div className="w-full">
|
||||
{/* <h3 className="text-center text-slate-400">todays lectures</h3> */}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use client";
|
||||
import { SimpleTimeOnly } from "@/models/local/localCourse";
|
||||
import { SimpleTimeOnly } from "@/models/local/localCourseSettings";
|
||||
import { FC, useState, useEffect } from "react";
|
||||
|
||||
export const TimePicker: FC<{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DayOfWeek } from "@/models/local/localCourse";
|
||||
import { DayOfWeek } from "@/models/local/localCourseSettings";
|
||||
|
||||
export function DayOfWeekInput({
|
||||
selectedDays,
|
||||
@@ -15,11 +15,7 @@ export function DayOfWeekInput({
|
||||
<button
|
||||
role="button"
|
||||
key={day}
|
||||
className={
|
||||
hasDay
|
||||
? ""
|
||||
: "unstyled btn-outline "
|
||||
}
|
||||
className={hasDay ? "" : "unstyled btn-outline "}
|
||||
onClick={() => updateSettings(day)}
|
||||
>
|
||||
{day}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { localCourseKeys } from "./localCourse/localCourseKeys";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
import { LocalCourseSettings } from "@/models/local/localCourse";
|
||||
import { LocalCourseSettings } from "@/models/local/localCourseSettings";
|
||||
import { canvasAssignmentService } from "@/services/canvas/canvasAssignmentService";
|
||||
import { canvasAssignmentKeys } from "./canvas/canvasAssignmentHooks";
|
||||
import { LocalAssignment } from "@/models/local/assignment/localAssignment";
|
||||
@@ -32,7 +32,6 @@ export const hydrateCourse = async (
|
||||
queryClient: QueryClient,
|
||||
courseSettings: LocalCourseSettings
|
||||
) => {
|
||||
|
||||
const courseName = courseSettings.name;
|
||||
const moduleNames = await fileStorageService.modules.getModuleNames(
|
||||
courseName
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
getModuleNamesFromServer,
|
||||
} from "./localCourseModuleServerActions";
|
||||
import { trpc } from "@/services/trpc/utils";
|
||||
import { LocalAssignment } from "@/models/local/assignment/localAssignment";
|
||||
|
||||
export const useModuleNamesQuery = () => {
|
||||
const { courseName } = useCourseContext();
|
||||
@@ -38,7 +39,14 @@ export const useCreateModuleMutation = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useAllCourseDataQuery = () => {
|
||||
export const useAllCourseDataQuery = (): {
|
||||
assignmentsAndModules: {
|
||||
moduleName: string;
|
||||
assignment: LocalAssignment;
|
||||
}[];
|
||||
quizzesAndModules: any[];
|
||||
pagesAndModules: any[];
|
||||
} => {
|
||||
const { courseName } = useCourseContext();
|
||||
const { data: moduleNames } = useModuleNamesQuery();
|
||||
|
||||
|
||||
@@ -1,101 +1,34 @@
|
||||
"use client";
|
||||
import { LocalCourse, LocalCourseSettings } from "@/models/local/localCourse";
|
||||
import {
|
||||
useMutation,
|
||||
useQueryClient,
|
||||
useSuspenseQuery,
|
||||
} from "@tanstack/react-query";
|
||||
import { localCourseKeys } from "./localCourseKeys";
|
||||
import { useCourseContext } from "@/app/course/[courseName]/context/courseContext";
|
||||
import {
|
||||
createCourseOnServer,
|
||||
updateCourseSettingsOnServer,
|
||||
} from "./localCoursesServerActions";
|
||||
import { trpc } from "@/services/trpc/utils";
|
||||
|
||||
export const useLocalCoursesSettingsQuery = () =>
|
||||
trpc.settings.allCoursesSettings.useSuspenseQuery();
|
||||
// useSuspenseQuery({
|
||||
// queryKey: localCourseKeys.allCoursesSettings,
|
||||
// queryFn: async () => {
|
||||
// return await getAllCoursesSettingsFromServer();
|
||||
// },
|
||||
// });
|
||||
|
||||
|
||||
export const useLocalCourseSettingsQuery = () => {
|
||||
const { courseName } = useCourseContext();
|
||||
// const { data: settingsList } = useLocalCoursesSettingsQuery();
|
||||
return trpc.settings.courseSettings.useSuspenseQuery({ courseName });
|
||||
// return useSuspenseQuery({
|
||||
// queryKey: localCourseKeys.settings(courseName),
|
||||
// queryFn: async () => {
|
||||
// const settingsList = await getAllCoursesSettingsFromServer();
|
||||
// const s = settingsList.find((s) => s.name === courseName);
|
||||
// if (!s) {
|
||||
// console.log(courseName, settingsList);
|
||||
// throw Error("Could not find settings for course " + courseName);
|
||||
// }
|
||||
// return s;
|
||||
// },
|
||||
// });
|
||||
|
||||
};
|
||||
|
||||
export const useCreateLocalCourseMutation = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (newCourse: LocalCourse) => {
|
||||
await createCourseOnServer({ course: newCourse });
|
||||
},
|
||||
const utils = trpc.useUtils();
|
||||
return trpc.settings.createCourse.useMutation({
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: localCourseKeys.allCoursesSettings,
|
||||
});
|
||||
utils.settings.allCoursesSettings.invalidate();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateLocalCourseSettingsMutation = () => {
|
||||
const { courseName } = useCourseContext();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (updatedSettings: LocalCourseSettings) => {
|
||||
// queryClient.setQueryData(
|
||||
// localCourseKeys.settings(courseName),
|
||||
// updatedSettings
|
||||
// );
|
||||
await updateCourseSettingsOnServer({
|
||||
courseName,
|
||||
settings: updatedSettings,
|
||||
});
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: localCourseKeys.allCoursesSettings,
|
||||
});
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: localCourseKeys.settings(courseName),
|
||||
});
|
||||
const utils = trpc.useUtils();
|
||||
|
||||
return trpc.settings.createCourse.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.settings.allCoursesSettings.invalidate();
|
||||
utils.settings.courseSettings.invalidate({ courseName });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// export const useUpdateCourseMutation = (courseName: string) => {
|
||||
// const queryClient = useQueryClient();
|
||||
// return useMutation({
|
||||
// mutationFn: async (body: {
|
||||
// updatedCourse: LocalCourse;
|
||||
// previousCourse: LocalCourse;
|
||||
// }) => {
|
||||
// const url = `/api/courses/${courseName}`;
|
||||
// await axiosClient.put(url, body);
|
||||
// },
|
||||
// onSuccess: () => {
|
||||
// queryClient.invalidateQueries({
|
||||
// queryKey: localCourseKeys.settings(courseName),
|
||||
// });
|
||||
// },
|
||||
// scope: {
|
||||
// id: "all courses",
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use server";
|
||||
import { LocalCourse, LocalCourseSettings } from "@/models/local/localCourse";
|
||||
import {
|
||||
LocalCourseSettings,
|
||||
} from "@/models/local/localCourseSettings";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
|
||||
export async function getCourseSettingsFromServer({
|
||||
@@ -13,23 +15,23 @@ export async function getAllCoursesSettingsFromServer() {
|
||||
return await fileStorageService.settings.getAllCoursesSettings();
|
||||
}
|
||||
|
||||
export async function createCourseOnServer({
|
||||
course,
|
||||
}: {
|
||||
course: LocalCourse;
|
||||
}) {
|
||||
await fileStorageService.settings.updateCourseSettings(
|
||||
course.settings.name,
|
||||
course.settings
|
||||
);
|
||||
}
|
||||
// export async function createCourseOnServer({
|
||||
// course,
|
||||
// }: {
|
||||
// course: LocalCourse;
|
||||
// }) {
|
||||
// await fileStorageService.settings.updateCourseSettings(
|
||||
// course.settings.name,
|
||||
// course.settings
|
||||
// );
|
||||
// }
|
||||
|
||||
export async function updateCourseSettingsOnServer({
|
||||
courseName,
|
||||
settings,
|
||||
}: {
|
||||
courseName: string;
|
||||
settings: LocalCourseSettings;
|
||||
}) {
|
||||
await fileStorageService.settings.updateCourseSettings(courseName, settings);
|
||||
}
|
||||
// export async function updateCourseSettingsOnServer({
|
||||
// courseName,
|
||||
// settings,
|
||||
// }: {
|
||||
// courseName: string;
|
||||
// settings: LocalCourseSettings;
|
||||
// }) {
|
||||
// await fileStorageService.settings.updateCourseSettings(courseName, settings);
|
||||
// }
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export interface LocalAssignmentGroup {
|
||||
canvasId?: number;
|
||||
id: string;
|
||||
name: string;
|
||||
weight: number;
|
||||
}
|
||||
export const zodLocalAssignmentGroup = z.object({
|
||||
canvasId: z.number().optional(), // canvasId is optional
|
||||
id: z.string(), // id is a required string
|
||||
name: z.string(), // name is a required string
|
||||
weight: z.number(), // weight is a required number
|
||||
});
|
||||
@@ -1,17 +1,48 @@
|
||||
import { AssignmentSubmissionType } from "./assignment/assignmentSubmissionType";
|
||||
import { LocalAssignmentGroup } from "./assignment/localAssignmentGroup";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
AssignmentSubmissionType,
|
||||
zodAssignmentSubmissionType,
|
||||
} from "./assignment/assignmentSubmissionType";
|
||||
import {
|
||||
LocalAssignmentGroup,
|
||||
zodLocalAssignmentGroup,
|
||||
} from "./assignment/localAssignmentGroup";
|
||||
import { LocalModule } from "./localModules";
|
||||
import { parse, stringify } from "yaml";
|
||||
|
||||
export interface LocalCourse {
|
||||
modules: LocalModule[];
|
||||
settings: LocalCourseSettings;
|
||||
}
|
||||
// export interface LocalCourse {
|
||||
// modules: LocalModule[];
|
||||
// settings: LocalCourseSettings;
|
||||
// }
|
||||
|
||||
export interface SimpleTimeOnly {
|
||||
hour: number;
|
||||
minute: number;
|
||||
}
|
||||
export const zodSimpleTimeOnly = z.object({
|
||||
hour: z.number().int().min(0).max(23), // hour should be an integer between 0 and 23
|
||||
minute: z.number().int().min(0).max(59), // minute should be an integer between 0 and 59
|
||||
});
|
||||
|
||||
export enum DayOfWeek {
|
||||
Sunday = "Sunday",
|
||||
Monday = "Monday",
|
||||
Tuesday = "Tuesday",
|
||||
Wednesday = "Wednesday",
|
||||
Thursday = "Thursday",
|
||||
Friday = "Friday",
|
||||
Saturday = "Saturday",
|
||||
}
|
||||
|
||||
export const zodDayOfWeek = z.enum([
|
||||
DayOfWeek.Sunday,
|
||||
DayOfWeek.Monday,
|
||||
DayOfWeek.Tuesday,
|
||||
DayOfWeek.Wednesday,
|
||||
DayOfWeek.Thursday,
|
||||
DayOfWeek.Friday,
|
||||
DayOfWeek.Saturday,
|
||||
]);
|
||||
|
||||
export interface LocalCourseSettings {
|
||||
name: string;
|
||||
@@ -30,15 +61,24 @@ export interface LocalCourseSettings {
|
||||
}[];
|
||||
}
|
||||
|
||||
export enum DayOfWeek {
|
||||
Sunday = "Sunday",
|
||||
Monday = "Monday",
|
||||
Tuesday = "Tuesday",
|
||||
Wednesday = "Wednesday",
|
||||
Thursday = "Thursday",
|
||||
Friday = "Friday",
|
||||
Saturday = "Saturday",
|
||||
}
|
||||
export const zodLocalCourseSettings = z.object({
|
||||
name: z.string(),
|
||||
assignmentGroups: zodLocalAssignmentGroup.array(),
|
||||
daysOfWeek: zodDayOfWeek.array(),
|
||||
canvasId: z.number(),
|
||||
startDate: z.string(),
|
||||
endDate: z.string(),
|
||||
defaultDueTime: zodSimpleTimeOnly,
|
||||
defaultLockHoursOffset: z.number().int().optional(),
|
||||
defaultAssignmentSubmissionTypes: zodAssignmentSubmissionType.array(),
|
||||
defaultFileUploadTypes: z.string().array(),
|
||||
holidays: z
|
||||
.object({
|
||||
name: z.string(),
|
||||
days: z.string().array(),
|
||||
})
|
||||
.array(),
|
||||
});
|
||||
|
||||
export function getDayOfWeek(date: Date): DayOfWeek {
|
||||
const dayIndex = date.getDay(); // Returns 0 for Sunday, 1 for Monday, etc.
|
||||
@@ -9,7 +9,10 @@ import {
|
||||
parseLecture,
|
||||
} from "./utils/lectureUtils";
|
||||
import { Lecture } from "@/models/local/lecture";
|
||||
import { getDayOfWeek, LocalCourseSettings } from "@/models/local/localCourse";
|
||||
import {
|
||||
getDayOfWeek,
|
||||
LocalCourseSettings,
|
||||
} from "@/models/local/localCourseSettings";
|
||||
import { getWeekNumber } from "@/app/course/[courseName]/calendar/calendarMonthUtils";
|
||||
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
LocalCourseSettings,
|
||||
localCourseYamlUtils,
|
||||
} from "@/models/local/localCourse";
|
||||
} from "@/models/local/localCourseSettings";
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { promises as fs } from "fs";
|
||||
import { DayOfWeek, LocalCourseSettings } from "@/models/local/localCourse";
|
||||
import {
|
||||
DayOfWeek,
|
||||
LocalCourseSettings,
|
||||
} from "@/models/local/localCourseSettings";
|
||||
import { fileStorageService } from "../fileStorage/fileStorageService";
|
||||
|
||||
describe("FileStorageTests", () => {
|
||||
|
||||
@@ -2,6 +2,7 @@ import publicProcedure from "../procedures/public";
|
||||
import { z } from "zod";
|
||||
import { router } from "../trpc";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
import { zodLocalCourseSettings } from "@/models/local/localCourseSettings";
|
||||
|
||||
export const settingsRouter = router({
|
||||
allCoursesSettings: publicProcedure.query(async () => {
|
||||
@@ -23,4 +24,29 @@ export const settingsRouter = router({
|
||||
}
|
||||
return s;
|
||||
}),
|
||||
createCourse: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
settings: zodLocalCourseSettings,
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input: { settings } }) => {
|
||||
await fileStorageService.settings.updateCourseSettings(
|
||||
settings.name,
|
||||
settings
|
||||
);
|
||||
}),
|
||||
updateSettings: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
settings: zodLocalCourseSettings,
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input: { settings } }) => {
|
||||
await fileStorageService.settings.updateCourseSettings(
|
||||
settings.name,
|
||||
settings
|
||||
);
|
||||
}),
|
||||
|
||||
});
|
||||
|
||||
@@ -1,50 +1,4 @@
|
||||
import { createTRPCReact, httpBatchLink } from "@trpc/react-query";
|
||||
import { createTRPCNext } from "@trpc/next";
|
||||
import { ssrPrepass } from '@trpc/next/ssrPrepass';
|
||||
import { AppRouter } from "./router/app";
|
||||
import superjson from "superjson";
|
||||
|
||||
export const trpc = createTRPCReact<AppRouter>();
|
||||
// export const trpc = createTRPCNext<AppRouter>({
|
||||
// ssr: true,
|
||||
// ssrPrepass,
|
||||
// transformer: superjson,
|
||||
// config(opts) {
|
||||
// const { ctx } = opts;
|
||||
// if (typeof window !== "undefined") {
|
||||
// // during client requests
|
||||
// return {
|
||||
// links: [
|
||||
// httpBatchLink({
|
||||
// url: "/api/trpc",
|
||||
// transformer: superjson,
|
||||
// }),
|
||||
// ],
|
||||
// };
|
||||
// }
|
||||
// return {
|
||||
// links: [
|
||||
// httpBatchLink({
|
||||
// transformer: superjson,
|
||||
// // The server needs to know your app's full url
|
||||
// url: `http://localhost:3000/api/trpc`,
|
||||
// /**
|
||||
// * Set custom request headers on every request from tRPC
|
||||
// * @see https://trpc.io/docs/v10/header
|
||||
// */
|
||||
// headers() {
|
||||
// if (!ctx?.req?.headers) {
|
||||
// return {};
|
||||
// }
|
||||
// // To use SSR properly, you need to forward client headers to the server
|
||||
// // This is so you can pass through things like cookies when we're server-side rendering
|
||||
// return {
|
||||
// cookie: ctx.req.headers.cookie,
|
||||
// };
|
||||
// },
|
||||
// }),
|
||||
// ],
|
||||
// };
|
||||
// },
|
||||
// });
|
||||
// export const trpcClient = trpc.createClient({ links: [] }); //server only?
|
||||
|
||||
Reference in New Issue
Block a user