diff --git a/aimenet-web/src/components/card-creation-form.tsx b/aimenet-web/src/components/card-creation-form.tsx index 583c696..ac645ee 100644 --- a/aimenet-web/src/components/card-creation-form.tsx +++ b/aimenet-web/src/components/card-creation-form.tsx @@ -1,5 +1,5 @@ import {z} from "zod"; -import React from "react"; +import React, {useEffect} from "react"; import {Check, Plus, X} from "lucide-react"; import {FormProvider, useForm} from "react-hook-form"; @@ -38,6 +38,7 @@ import { } from "@/components/ui/drawer"; import {useLiveQuery} from "dexie-react-hooks"; import {cn} from "@/lib/utils.ts"; +import {useLocation} from "react-router-dom"; const schema = z.object({ name: z.string().min(1, { @@ -118,11 +119,18 @@ function AimeCardCreationForm(props: { callback?: () => void }) { } export function CardCreationDialog(props: { className?: string }) { + const location = useLocation(); const [open, setOpen] = React.useState(false); const cardCount = useLiveQuery(() => db.cards.count()); const isDesktop = useMediaQuery("(min-width: 768px)"); + useEffect(() => { + if (location.pathname === "/cards/add") { + setOpen(true); + } + }, [location]); + const disableCreation = (cardCount !== undefined && cardCount >= CARD_LIMIT) ?? false; const creationComponent = (