mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
group by semester
This commit is contained in:
@@ -1,26 +1,66 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useLocalCoursesSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
import { useLocalCoursesSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||||
|
import { LocalCourseSettings } from "@/models/local/localCourseSettings";
|
||||||
import { getCourseUrl } from "@/services/urlUtils";
|
import { getCourseUrl } from "@/services/urlUtils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
|
function getDateKey(dateString: string) {
|
||||||
|
return dateString.split("T")[0];
|
||||||
|
}
|
||||||
|
function groupByStartDate(courses: LocalCourseSettings[]): {
|
||||||
|
[key: string]: LocalCourseSettings[];
|
||||||
|
} {
|
||||||
|
return courses.reduce(
|
||||||
|
(acc, course) => {
|
||||||
|
const { startDate } = course;
|
||||||
|
const key = getDateKey(startDate);
|
||||||
|
if (!acc[key]) {
|
||||||
|
acc[key] = [];
|
||||||
|
}
|
||||||
|
acc[key].push(course);
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{} as {
|
||||||
|
[key: string]: LocalCourseSettings[];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTermName(startDate: string) {
|
||||||
|
const [year, month, ...rest] = startDate.split("-");
|
||||||
|
if (month < "04") return "Spring " + year;
|
||||||
|
if (month < "07") return "Summer " + year;
|
||||||
|
return "Fall " + year;
|
||||||
|
}
|
||||||
|
|
||||||
export default function CourseList() {
|
export default function CourseList() {
|
||||||
const [allSettings] = useLocalCoursesSettingsQuery();
|
const [allSettings] = useLocalCoursesSettingsQuery();
|
||||||
|
|
||||||
|
const coursesByStartDate = groupByStartDate(allSettings);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="flex flex-row ">
|
||||||
{allSettings.map((settings) => (
|
{Object.keys(coursesByStartDate).map((startDate) => (
|
||||||
<div key={settings.name}>
|
<div
|
||||||
<Link
|
key={startDate}
|
||||||
href={getCourseUrl(settings.name)}
|
className=" border-4 border-slate-800 rounded p-3 m-3"
|
||||||
shallow={true}
|
>
|
||||||
className="
|
<div className="text-center">{getTermName(startDate)}</div>
|
||||||
|
{coursesByStartDate[getDateKey(startDate)].map((settings) => (
|
||||||
|
<div key={settings.name}>
|
||||||
|
<Link
|
||||||
|
href={getCourseUrl(settings.name)}
|
||||||
|
shallow={true}
|
||||||
|
className="
|
||||||
font-bold text-xl block
|
font-bold text-xl block
|
||||||
transition-all hover:scale-105 hover:underline hover:text-slate-200
|
transition-all hover:scale-105 hover:underline hover:text-slate-200
|
||||||
mb-3
|
mb-3
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
{settings.name}
|
{settings.name}
|
||||||
</Link>
|
</Link>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ import { useCourseContext } from "./context/courseContext"
|
|||||||
export default function CourseTitle() {
|
export default function CourseTitle() {
|
||||||
const {courseName}= useCourseContext()
|
const {courseName}= useCourseContext()
|
||||||
return (
|
return (
|
||||||
<title>{courseName}</title>
|
<title>{process.env.NEXT_PUBLIC_TITLE_PREFIX}{courseName}</title>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { ClientCacheInvalidation } from "../components/realtime/ClientCacheInval
|
|||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Canvas Manager 2.0",
|
title: process.env.NEXT_PUBLIC_TITLE_PREFIX + "Canvas Manager 2.0",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function RootLayout({
|
export default async function RootLayout({
|
||||||
|
|||||||
Reference in New Issue
Block a user