From 5f788f5a16a95651acdce6b6d351faa47ae61b7f Mon Sep 17 00:00:00 2001 From: ppc Date: Wed, 21 Aug 2024 21:01:28 +0100 Subject: [PATCH] handle */add routes --- .../src/components/card-creation-form.tsx | 10 +++- aimenet-web/src/pages/server-listing.tsx | 60 ++++++++++++++----- 2 files changed, 55 insertions(+), 15 deletions(-) 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 = (