From 34c44850bcb03432dcee728a72870e2e8879ae36 Mon Sep 17 00:00:00 2001 From: Bartosz Gotowski Date: Sun, 1 Sep 2024 23:11:24 +0200 Subject: [PATCH] fix: a lot of small changes --- src/components/{plan.tsx => Plan.tsx} | 4 +- src/components/{schedule.tsx => Schedule.tsx} | 0 .../{selectGroups.tsx => SelectGroups.tsx} | 0 src/pages/createplan/[id].tsx | 85 ++++++++----------- src/pages/index.tsx | 56 ++++++------ src/pages/plans.tsx | 22 +++-- 6 files changed, 81 insertions(+), 86 deletions(-) rename src/components/{plan.tsx => Plan.tsx} (87%) rename src/components/{schedule.tsx => Schedule.tsx} (100%) rename src/components/{selectGroups.tsx => SelectGroups.tsx} (100%) diff --git a/src/components/plan.tsx b/src/components/Plan.tsx similarity index 87% rename from src/components/plan.tsx rename to src/components/Plan.tsx index 44ec9e9..d3ba882 100644 --- a/src/components/plan.tsx +++ b/src/components/Plan.tsx @@ -4,9 +4,7 @@ import React from "react"; export const Plan = ({ id, name }: { id: number; name: string }) => { return (
{name}
diff --git a/src/components/schedule.tsx b/src/components/Schedule.tsx similarity index 100% rename from src/components/schedule.tsx rename to src/components/Schedule.tsx diff --git a/src/components/selectGroups.tsx b/src/components/SelectGroups.tsx similarity index 100% rename from src/components/selectGroups.tsx rename to src/components/SelectGroups.tsx diff --git a/src/pages/createplan/[id].tsx b/src/pages/createplan/[id].tsx index 641272d..986e95c 100644 --- a/src/pages/createplan/[id].tsx +++ b/src/pages/createplan/[id].tsx @@ -8,14 +8,12 @@ import { CiEdit } from "react-icons/ci"; import { IoMdArrowBack } from "react-icons/io"; import { IoCheckmarkOutline } from "react-icons/io5"; +import { ScheduleTest } from "@/components/Schedule"; +import { SelectGroups } from "@/components/SelectGroups"; import { SolvroLogo } from "@/components/SolvroLogo"; -import { ScheduleTest } from "@/components/schedule"; -import { SelectGroups } from "@/components/selectGroups"; import type { ClassBlockProps, Course, Registration } from "@/lib/types"; import { cn } from "@/lib/utils"; -import { plansAtom } from "../plans"; - const mockRegistration1 = { name: "Registration 1", } satisfies Registration; @@ -211,18 +209,23 @@ export interface ExtendedGroup extends ClassBlockProps { export const planFamily = atomFamily( ({ id }: { id: number }) => - atomWithStorage(`${id}-plan`, { - id, - name: `Nowy plan - ${id}`, - courses: mockCourses.map((mockCourse) => ({ - ...mockCourse, - isChecked: false, - })), - groups: mockGroups.map((mockGroup) => ({ - ...mockGroup, - isChecked: false, - })), - }), + atomWithStorage( + `${id}-plan`, + { + id, + name: `Nowy plan - ${id}`, + courses: mockCourses.map((mockCourse) => ({ + ...mockCourse, + isChecked: false, + })), + groups: mockGroups.map((mockGroup) => ({ + ...mockGroup, + isChecked: false, + })), + }, + undefined, + { getOnInit: true }, + ), (a, b) => a.id === b.id, ); @@ -244,35 +247,15 @@ const CreatePlan = ({ }: InferGetServerSidePropsType) => { const [plan, setPlan] = useAtom(planFamily({ id: planId })); - //tutaj używam atomu z widoku planow, zeby poprawnie aktualizowaly się nazwy - const [plansTitles, setPlansTitles] = useAtom(plansAtom); - const [isEditing, setIsEditing] = useState(false); const inputRef = useRef(null); - const handleNameInputIcon = (isClicked: boolean) => { - if (isClicked) { - return ; - } - return ; - }; - const changePlanName = (newName: string) => { setPlan({ ...plan, name: newName, }); - setPlansTitles( - plansTitles.map((openedPlan) => - openedPlan.id === planId - ? { - ...openedPlan, - name: newName, - } - : openedPlan, - ), - ); }; const checkCourse = (id: string) => { @@ -296,7 +279,6 @@ const CreatePlan = ({ return (
- {/* */}
@@ -306,8 +288,8 @@ const CreatePlan = ({ className="flex items-center justify-center" onSubmit={(e) => { e.preventDefault(); - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - changePlanName(e.currentTarget.elements.name.value); + const formData = new FormData(e.currentTarget); + changePlanName(formData.get("name")?.toString() ?? ""); inputRef.current?.blur(); }} > @@ -318,23 +300,26 @@ const CreatePlan = ({ "w-full truncate border-mainbutton5 bg-transparent outline-none duration-100 ease-in-out before:transition-all focus:border-b-2 focus:font-normal", )} name="name" - defaultValue={plan.name} + id="name" + defaultValue={typeof window === "undefined" ? "" : plan.name} onFocus={() => { setIsEditing(true); }} - onBlur={() => { + onBlur={(e) => { setIsEditing(false); + changePlanName(e.currentTarget.value); }} /> - + {isEditing ? ( + + ) : ( + + )}
diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 5ee4dfd..6cb736f 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -6,7 +6,7 @@ import type React from "react"; import { type ComponentProps, useState } from "react"; import { twMerge } from "tailwind-merge"; -import { buttonVariants } from "@/components/ui/button"; +import { Button, buttonVariants } from "@/components/ui/button"; const Navbar = () => { const [isMenuOpen, setIsMenuOpen] = useState(false); @@ -21,20 +21,17 @@ const Navbar = () => { {/* Desktop Navigation */}