Skip to content

Commit

Permalink
feat: dzwoni papuga
Browse files Browse the repository at this point in the history
  • Loading branch information
Rei-x committed Sep 18, 2024
1 parent b99137f commit c02b805
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/app/api/data/[facultyId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function GET(
_request: Request,
{ params }: { params: { facultyId: string } },
) {

const service = createUsosService();
return NextResponse.json(
{
registrations: await Promise.all(
Expand Down
8 changes: 5 additions & 3 deletions src/lib/usePlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { useAtom } from "jotai";

import { type ExtendedCourse, planFamily } from "@/atoms/planFamily";

import type { Course, Registration } from "./types";
import type { Registration } from "./types";

export const usePlan = ({ planId }: { planId: number }) => {
const [plan, setPlan] = useAtom(planFamily({ id: planId }));

return {
...plan,
allGroups: plan.courses.flatMap((c) => c.groups),
allGroups: plan.courses.filter((c) => c.isChecked).flatMap((c) => c.groups),
setPlan,
selectGroup: (groupId: string, isChecked?: boolean) => {
void window.umami?.track("Change group");
Expand Down Expand Up @@ -41,7 +41,9 @@ export const usePlan = ({ planId }: { planId: number }) => {
) => {
setPlan({
...plan,
registrations: [...plan.registrations, registration],
registrations: [...plan.registrations, registration].filter(
(r, i, a) => a.findIndex((t) => t.id === r.id) === i,
),
courses: [...plan.courses, ...courses],
});
},
Expand Down
18 changes: 13 additions & 5 deletions src/pages/app/createplan/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useQuery } from "@tanstack/react-query";
import { useAtom } from "jotai";
import type { GetServerSideProps, InferGetServerSidePropsType } from "next";
import Link from "next/link";
import { useRef, useState } from "react";

import type { ApiFacultyDataGet } from "@/app/api/data/[facultyId]/route";
import { type ExtendedGroup, planFamily } from "@/atoms/planFamily";
import { type ExtendedGroup } from "@/atoms/planFamily";
import { ClassSchedule } from "@/components/ClassSchedule";
import { GroupsAccordion } from "@/components/GroupsAccordion";
import { RegistrationCombobox } from "@/components/RegistrationCombobox";
Expand Down Expand Up @@ -194,8 +193,6 @@ const CreatePlan = ({
})),
})) ?? [];

const allCourses = allRegistrations.flatMap((r) => r.courses);

return (
<>
<Seo
Expand Down Expand Up @@ -302,10 +299,21 @@ const CreatePlan = ({
if (registration === undefined) {
return;
}
plan.addRegistration(registration, registration.courses);

if (
plan.registrations.some((r) => r.id === registration.id)
) {
plan.removeRegistration(registration.id);
} else {
plan.addRegistration(registration, registration.courses);
}
}}
/>
</div>
) : allRegistrations.length === 0 ? (
<div className="w-full items-center justify-center">
<p className="text-center">Brak rejestracji</p>
</div>
) : null}

<div className="w-full items-center justify-center">
Expand Down
39 changes: 0 additions & 39 deletions src/pages/error-page.tsx

This file was deleted.

0 comments on commit c02b805

Please sign in to comment.