diff --git a/nextjs/src/app/course/[courseName]/CalendarMonth.tsx b/nextjs/src/app/course/[courseName]/calendarMonth.tsx similarity index 98% rename from nextjs/src/app/course/[courseName]/CalendarMonth.tsx rename to nextjs/src/app/course/[courseName]/calendarMonth.tsx index 1c5c67c..bba1e24 100644 --- a/nextjs/src/app/course/[courseName]/CalendarMonth.tsx +++ b/nextjs/src/app/course/[courseName]/calendarMonth.tsx @@ -1,7 +1,7 @@ import { useState } from "react"; import { CalendarMonthModel } from "./calendarMonthUtils"; import { DayOfWeek, LocalCourse } from "@/models/local/localCourse"; -import Day from "./Day"; +import Day from "./day"; export default function CalendarMonth({ month, diff --git a/nextjs/src/app/course/[courseName]/calendarMonthUtils.ts b/nextjs/src/app/course/[courseName]/calendarMonthUtils.ts index 3223ae4..a2ae318 100644 --- a/nextjs/src/app/course/[courseName]/calendarMonthUtils.ts +++ b/nextjs/src/app/course/[courseName]/calendarMonthUtils.ts @@ -5,7 +5,7 @@ export interface CalendarMonthModel { daysByWeek: (Date | undefined)[][]; } -const weeksInMonth = (year: number, month: number): number => { +function weeksInMonth(year: number, month: number): number { const firstDayOfMonth = new Date(year, month - 1, 1).getDay(); const daysInMonth = new Date(year, month, 0).getDate(); const longDaysInMonth = daysInMonth + firstDayOfMonth; @@ -14,12 +14,9 @@ const weeksInMonth = (year: number, month: number): number => { weeks += 1; } return weeks; -}; +} -const createCalendarMonth = ( - year: number, - month: number -): CalendarMonthModel => { +function createCalendarMonth(year: number, month: number): CalendarMonthModel { const daysByWeek: (Date | undefined)[][] = []; const weeksNumber = weeksInMonth(year, month); const daysInMonth = new Date(year, month, 0).getDate(); @@ -57,12 +54,12 @@ const createCalendarMonth = ( ); return { year, month, weeks, daysByWeek }; -}; +} -export const getMonthsBetweenDates = ( +export function getMonthsBetweenDates( startDate: Date, endDate: Date -): CalendarMonthModel[] => { +): CalendarMonthModel[] { const monthsInTerm = 1 + (endDate.getFullYear() - startDate.getFullYear()) * 12 + @@ -76,4 +73,4 @@ export const getMonthsBetweenDates = ( Math.floor((startDate.getMonth() + monthDiff) / 12); return createCalendarMonth(year, month); }); -}; +} diff --git a/nextjs/src/app/course/[courseName]/Day.tsx b/nextjs/src/app/course/[courseName]/day.tsx similarity index 100% rename from nextjs/src/app/course/[courseName]/Day.tsx rename to nextjs/src/app/course/[courseName]/day.tsx diff --git a/nextjs/src/app/course/[courseName]/page.tsx b/nextjs/src/app/course/[courseName]/page.tsx index 3952112..9fae88b 100644 --- a/nextjs/src/app/course/[courseName]/page.tsx +++ b/nextjs/src/app/course/[courseName]/page.tsx @@ -2,7 +2,7 @@ import { useLocalCourseDetailsQuery } from "@/hooks/localCoursesHooks"; import { getDateFromStringOrThrow } from "@/models/local/timeUtils"; import { getMonthsBetweenDates } from "./calendarMonthUtils"; -import CalendarMonth from "./CalendarMonth"; +import CalendarMonth from "./calendarMonth"; export default function Page({ diff --git a/nextjs/src/app/layout.tsx b/nextjs/src/app/layout.tsx index 528ab33..1c01047 100644 --- a/nextjs/src/app/layout.tsx +++ b/nextjs/src/app/layout.tsx @@ -1,12 +1,10 @@ import type { Metadata } from "next"; -import { Inter } from "next/font/google"; import "./globals.css"; import { dehydrate } from "@tanstack/react-query"; -import { MyQueryClientProvider } from "@/services/utils/MyQueryClientProvider"; import { hydrateCourses } from "@/hooks/hookHydration"; import { createQueryClientForServer } from "@/services/utils/queryClientServer"; +import MyQueryClientProvider from "@/services/utils/MyQueryClientProvider"; -const inter = Inter({ subsets: ["latin"] }); export const metadata: Metadata = { title: "Canvas Manager 2.0", @@ -30,9 +28,7 @@ export default async function RootLayout({ return ( - {/* */} - {children} - {/* */} + {children} ); diff --git a/nextjs/src/app/page.tsx b/nextjs/src/app/page.tsx index be336cb..67f1a01 100644 --- a/nextjs/src/app/page.tsx +++ b/nextjs/src/app/page.tsx @@ -5,7 +5,7 @@ import Link from "next/link"; export default function Home() { const { data: courses } = useLocalCoursesQuery(); return ( -
+
{courses.map((c) => ( {c.settings.name} ))} diff --git a/nextjs/src/components/LoadingAndErrorHandling.tsx b/nextjs/src/components/LoadingAndErrorHandling.tsx deleted file mode 100644 index e52654b..0000000 --- a/nextjs/src/components/LoadingAndErrorHandling.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import { QueryErrorResetBoundary } from "@tanstack/react-query"; -import { FC, ReactNode, Suspense } from "react"; -import { ErrorBoundary } from "react-error-boundary"; - -// not at top level? -export const LoadingAndErrorHandling: FC<{ children: ReactNode }> = ({ - children, -}) => { - return ( - - {({ reset }) => ( - ( -
-
{JSON.stringify(props.error)}
- -
- )} - > - loading...}>{children} -
- )} -
- ); -}; diff --git a/nextjs/src/services/fileStorage/fileStorageService.ts b/nextjs/src/services/fileStorage/fileStorageService.ts index 2783703..3083c2a 100644 --- a/nextjs/src/services/fileStorage/fileStorageService.ts +++ b/nextjs/src/services/fileStorage/fileStorageService.ts @@ -38,8 +38,8 @@ export const fileStorageService = { async directoryExists(directoryPath: string): Promise { try { - const stat = await fs.stat(directoryPath); - return stat.isDirectory(); + await fs.access(directoryPath); + return true; } catch { return false; } diff --git a/nextjs/src/services/utils/MyQueryClientProvider.tsx b/nextjs/src/services/utils/MyQueryClientProvider.tsx index 4e025e7..e771645 100644 --- a/nextjs/src/services/utils/MyQueryClientProvider.tsx +++ b/nextjs/src/services/utils/MyQueryClientProvider.tsx @@ -9,15 +9,18 @@ import React from "react"; import { FC, ReactNode, useState } from "react"; import { createQueryClient } from "./queryClient"; -export const MyQueryClientProvider: FC<{ +export default function MyQueryClientProvider({ + children, + dehydratedState, +}: { children: ReactNode; dehydratedState: DehydratedState; -}> = ({ children, dehydratedState }) => { +}) { const [queryClient] = useState(createQueryClient()); hydrate(queryClient, dehydratedState); - + return ( {children} ); -}; +} diff --git a/nextjs/src/services/utils/queryClient.tsx b/nextjs/src/services/utils/queryClient.tsx index 5fa2fa1..e8f1097 100644 --- a/nextjs/src/services/utils/queryClient.tsx +++ b/nextjs/src/services/utils/queryClient.tsx @@ -123,21 +123,23 @@ export function createSuccessToast(message: string) { ); } -export const createQueryClient = () => new QueryClient({ - defaultOptions: { - queries: { - refetchOnWindowFocus: false, - retry: 0, +export function createQueryClient() { + return new QueryClient({ + defaultOptions: { + queries: { + refetchOnWindowFocus: false, + retry: 0, + }, + mutations: { + onError: addErrorAsToast, + retry: 0, + }, }, - mutations: { + queryCache: new QueryCache({ onError: addErrorAsToast, - retry: 0, - }, - }, - queryCache: new QueryCache({ - onError: addErrorAsToast, - }), - mutationCache: new MutationCache({ - onError: addErrorAsToast, - }), -}); + }), + mutationCache: new MutationCache({ + onError: addErrorAsToast, + }), + }); +} diff --git a/nextjs/src/services/utils/queryClientServer.tsx b/nextjs/src/services/utils/queryClientServer.tsx index 516b1ef..c7ad271 100644 --- a/nextjs/src/services/utils/queryClientServer.tsx +++ b/nextjs/src/services/utils/queryClientServer.tsx @@ -1,20 +1,22 @@ import { MutationCache, QueryCache, QueryClient } from "@tanstack/react-query"; -export const createQueryClientForServer = () => new QueryClient({ - defaultOptions: { - queries: { - refetchOnWindowFocus: false, - retry: 0, +export function createQueryClientForServer() { + return new QueryClient({ + defaultOptions: { + queries: { + refetchOnWindowFocus: false, + retry: 0, + }, + mutations: { + onError: (e) => console.log(e), + retry: 0, + }, }, - mutations: { + queryCache: new QueryCache({ onError: (e) => console.log(e), - retry: 0, - }, - }, - queryCache: new QueryCache({ - onError: (e) => console.log(e), - }), - mutationCache: new MutationCache({ - onError: (e) => console.log(e), - }), -}); + }), + mutationCache: new MutationCache({ + onError: (e) => console.log(e), + }), + }); +}