diff --git a/aimenet-web/src/components/card-creation-form.tsx b/aimenet-web/src/components/card-creation-form.tsx index b88c1ab..583c696 100644 --- a/aimenet-web/src/components/card-creation-form.tsx +++ b/aimenet-web/src/components/card-creation-form.tsx @@ -1,12 +1,12 @@ import {z} from "zod"; import React from "react"; -import {Check, X} from "lucide-react"; +import {Check, Plus, X} from "lucide-react"; import {FormProvider, useForm} from "react-hook-form"; import {useMediaQuery} from "@/hooks/use-media-query"; import {zodResolver} from "@hookform/resolvers/zod"; -import {AimeCard, db} from "@/lib/database"; +import {AimeCard, CARD_LIMIT, db} from "@/lib/database"; import {generateAimeCardId, validateAimeCardId} from "@/lib/aime-card"; import {Button} from "@/components/ui/button"; @@ -36,6 +36,8 @@ import { DrawerTitle, DrawerTrigger } from "@/components/ui/drawer"; +import {useLiveQuery} from "dexie-react-hooks"; +import {cn} from "@/lib/utils.ts"; const schema = z.object({ name: z.string().min(1, { @@ -115,15 +117,24 @@ function AimeCardCreationForm(props: { callback?: () => void }) { ); } -export function CardCreationDialog(props: { children: Readonly }) { +export function CardCreationDialog(props: { className?: string }) { const [open, setOpen] = React.useState(false); + + const cardCount = useLiveQuery(() => db.cards.count()); const isDesktop = useMediaQuery("(min-width: 768px)"); + const disableCreation = (cardCount !== undefined && cardCount >= CARD_LIMIT) ?? false; + const creationComponent = ( + + ); + if (isDesktop) { return ( - - {props.children} + + {creationComponent} @@ -137,8 +148,8 @@ export function CardCreationDialog(props: { children: Readonly return ( - - {props.children} + + {creationComponent} diff --git a/aimenet-web/src/lib/database.ts b/aimenet-web/src/lib/database.ts index 937eb34..274c5f9 100644 --- a/aimenet-web/src/lib/database.ts +++ b/aimenet-web/src/lib/database.ts @@ -2,6 +2,8 @@ import Dexie, { type EntityTable } from 'dexie'; import {AimeServerInfo} from "@/lib/aime-net.ts"; +export const CARD_LIMIT = 15; + interface AimeServer extends AimeServerInfo { id: number; address: string;