mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
can remove courses from main page now
This commit is contained in:
@@ -9,19 +9,7 @@ courses:
|
|||||||
name: UX
|
name: UX
|
||||||
- path: ./1425/2025-fall-alex/modules/
|
- path: ./1425/2025-fall-alex/modules/
|
||||||
name: "1425"
|
name: "1425"
|
||||||
- path: ./1405/2025_spring_alex/
|
|
||||||
name: 1405_old
|
|
||||||
- path: ./3840_Telemetry/2025_spring_alex/modules/
|
- path: ./3840_Telemetry/2025_spring_alex/modules/
|
||||||
name: Telem and Ops
|
name: Telem and Ops
|
||||||
- path: ./4850_AdvancedFE/2024-fall-alex/modules/
|
|
||||||
name: Old Adv Frontend
|
|
||||||
- path: ./1430/2025-spring-jonathan/Modules/
|
|
||||||
name: Jonathan UX
|
|
||||||
- path: ./1400/2025_spring_alex/modules/
|
|
||||||
name: 1400-spring
|
|
||||||
- path: ./1420/2024-fall/Modules/
|
|
||||||
name: 1420_old
|
|
||||||
- path: ./3820_BackEnd/2025-fall/Modules/
|
|
||||||
name: jonathan-backend
|
|
||||||
- path: ./4850_AdvancedFE/2026-spring-alex/modules
|
- path: ./4850_AdvancedFE/2026-spring-alex/modules
|
||||||
name: Adv Frontend Spring
|
name: Adv Frontend Spring
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
import { Toggle } from "@/components/form/Toggle";
|
||||||
import { useLocalCoursesSettingsQuery } from "@/features/local/course/localCoursesHooks";
|
import { useLocalCoursesSettingsQuery } from "@/features/local/course/localCoursesHooks";
|
||||||
|
import {
|
||||||
|
useGlobalSettingsQuery,
|
||||||
|
useUpdateGlobalSettingsMutation,
|
||||||
|
} from "@/features/local/globalSettings/globalSettingsHooks";
|
||||||
import {
|
import {
|
||||||
getDateKey,
|
getDateKey,
|
||||||
getTermName,
|
getTermName,
|
||||||
@@ -7,17 +12,25 @@ import {
|
|||||||
} from "@/features/local/utils/timeUtils";
|
} from "@/features/local/utils/timeUtils";
|
||||||
import { getCourseUrl } from "@/services/urlUtils";
|
import { getCourseUrl } from "@/services/urlUtils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useState } from "react";
|
||||||
|
import Modal, { useModal } from "@/components/Modal";
|
||||||
|
import { Spinner } from "@/components/Spinner";
|
||||||
|
|
||||||
export default function CourseList() {
|
export default function CourseList() {
|
||||||
const { data: allSettings } = useLocalCoursesSettingsQuery();
|
const { data: allSettings } = useLocalCoursesSettingsQuery();
|
||||||
|
const [isDeleting, setIsDeleting] = useState(false);
|
||||||
|
|
||||||
const coursesByStartDate = groupByStartDate(allSettings);
|
const coursesByStartDate = groupByStartDate(allSettings);
|
||||||
|
|
||||||
const sortedDates = Object.keys(coursesByStartDate).sort();
|
const sortedDates = Object.keys(coursesByStartDate).sort();
|
||||||
|
|
||||||
console.log(allSettings, coursesByStartDate);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div>
|
||||||
|
<Toggle
|
||||||
|
label={"Delete Mode"}
|
||||||
|
value={isDeleting}
|
||||||
|
onChange={(set) => setIsDeleting(set)}
|
||||||
|
/>
|
||||||
<div className="flex flex-row ">
|
<div className="flex flex-row ">
|
||||||
{sortedDates.map((startDate) => (
|
{sortedDates.map((startDate) => (
|
||||||
<div
|
<div
|
||||||
@@ -26,9 +39,34 @@ export default function CourseList() {
|
|||||||
>
|
>
|
||||||
<div className="text-center">{getTermName(startDate)}</div>
|
<div className="text-center">{getTermName(startDate)}</div>
|
||||||
{coursesByStartDate[getDateKey(startDate)].map((settings) => (
|
{coursesByStartDate[getDateKey(startDate)].map((settings) => (
|
||||||
<div key={settings.name}>
|
<CourseItem
|
||||||
|
key={settings.name}
|
||||||
|
courseName={settings.name}
|
||||||
|
isDeleting={isDeleting}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CourseItem({
|
||||||
|
courseName,
|
||||||
|
isDeleting,
|
||||||
|
}: {
|
||||||
|
courseName: string;
|
||||||
|
isDeleting: boolean;
|
||||||
|
}) {
|
||||||
|
const { data: globalSettings } = useGlobalSettingsQuery();
|
||||||
|
const updateSettingsMutation = useUpdateGlobalSettingsMutation();
|
||||||
|
const modal = useModal();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
<Link
|
<Link
|
||||||
href={getCourseUrl(settings.name)}
|
href={getCourseUrl(courseName)}
|
||||||
shallow={true}
|
shallow={true}
|
||||||
prefetch={true}
|
prefetch={true}
|
||||||
className="
|
className="
|
||||||
@@ -37,12 +75,59 @@ export default function CourseList() {
|
|||||||
mb-3
|
mb-3
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
{settings.name}
|
{courseName}
|
||||||
</Link>
|
</Link>
|
||||||
|
{isDeleting && (
|
||||||
|
<Modal
|
||||||
|
modalControl={modal}
|
||||||
|
buttonText="−"
|
||||||
|
buttonClass="
|
||||||
|
unstyled
|
||||||
|
text-red-200 hover:text-red-400
|
||||||
|
bg-red-950
|
||||||
|
font-bold text-2xl
|
||||||
|
transition-all hover:scale-110
|
||||||
|
mb-3
|
||||||
|
"
|
||||||
|
modalWidth="w-1/3"
|
||||||
|
>
|
||||||
|
{({ closeModal }) => (
|
||||||
|
<div>
|
||||||
|
<div className="text-center">
|
||||||
|
Are you sure you want to remove {courseName} from global
|
||||||
|
settings?
|
||||||
</div>
|
</div>
|
||||||
))}
|
<br />
|
||||||
|
<div className="flex justify-around gap-3">
|
||||||
|
<button
|
||||||
|
onClick={async () => {
|
||||||
|
await updateSettingsMutation.mutateAsync({
|
||||||
|
globalSettings: {
|
||||||
|
...globalSettings,
|
||||||
|
courses: globalSettings.courses.filter(
|
||||||
|
(course) => course.name !== courseName
|
||||||
|
),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
closeModal();
|
||||||
|
}}
|
||||||
|
disabled={updateSettingsMutation.isPending}
|
||||||
|
className="btn-danger"
|
||||||
|
>
|
||||||
|
Yes
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={closeModal}
|
||||||
|
disabled={updateSettingsMutation.isPending}
|
||||||
|
>
|
||||||
|
No
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
))}
|
{updateSettingsMutation.isPending && <Spinner />}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Modal>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
37
src/components/form/Toggle.tsx
Normal file
37
src/components/form/Toggle.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import type { FC } from "react";
|
||||||
|
|
||||||
|
export const Toggle: FC<{
|
||||||
|
label: string;
|
||||||
|
value: boolean;
|
||||||
|
onChange: (checked: boolean) => void;
|
||||||
|
}> = ({ label, value, onChange }) => {
|
||||||
|
return (
|
||||||
|
<label
|
||||||
|
className="
|
||||||
|
flex align-middle p-2 cursor-pointer
|
||||||
|
text-gray-300
|
||||||
|
hover:text-blue-400
|
||||||
|
transition-colors duration-200 ease-in-out
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="appearance-none peer"
|
||||||
|
checked={value}
|
||||||
|
onChange={(e) => onChange(e.target.checked)}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
className={`
|
||||||
|
w-12 h-6 flex items-center flex-shrink-0 mx-3 p-1
|
||||||
|
bg-gray-600 rounded-full
|
||||||
|
duration-300 ease-in-out
|
||||||
|
peer-checked:bg-blue-600
|
||||||
|
after:w-4 after:h-4 after:bg-white after:rounded-full after:shadow-md
|
||||||
|
after:duration-300 peer-checked:after:translate-x-6
|
||||||
|
group-hover:after:translate-x-1
|
||||||
|
`}
|
||||||
|
></span>
|
||||||
|
<span className="">{label}</span>
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user