import * as Y from "yjs"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "~/components/ui/dialog"; import { Input } from "~/components/ui/input"; import { Button } from "~/components/ui/button"; import { ColorPicker } from "../form/color_picker"; import { Label } from "~/components/ui/label"; import { IconPicker } from "../form/icon_picker"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "~/components/ui/alert-dialog"; import { useCollection, useCollections } from "~/hooks/use-metadata"; import { type CollectionId, type CollectionProperty, deleteCollection } from "~/lib/metadata"; import Icon from "@mdi/react"; import { mdiPin, mdiPinOff, mdiPlus, mdiTrashCan } from "@mdi/js"; import { createCollectionProperty, deleteCollectionProperty } from "~/lib/property"; import { useEffect } from "react"; import { PropertyTypeCombobox } from "../form/property_type_combobox"; type CollectionSettingsDialogProps = { name?: string; collectionId: CollectionId; children: React.ReactNode; }; export function CollectionSettingsDialog(props: CollectionSettingsDialogProps) { return ( {props.children} {props.name} settings Settings for the {props.name} collection.
); } function SettingsSection(props: { collectionId: CollectionId }) { const collection = useCollection(props.collectionId) if (!collection) { return null; } return (
collection.set("icon", icon ?? "")} />
collection.set("name", name.currentTarget.value)} />
collection.set("color", color)} />
); } function PropertiesSection(props: { collectionId: CollectionId }) { const collection = useCollection(props.collectionId) if (!collection) { return null; } // Ensure that the properties array exists on the collection useEffect(() => { if (!collection.has("properties")) { collection.set("properties", new Y.Array() as any) } }, [collection]) const properties = collection.get("properties"); return (
{properties?.map((property) => deleteCollectionProperty(properties, property.get("id"))} /> )}
); } type PropertyItemProps = { property: CollectionProperty, onDelete: () => void, } function PropertyItem(props: PropertyItemProps) { const { property: prop } = props; return (
prop.set("name", event.target.value)} /> prop.set("type", type)} />
); } function DangerSection(props: { collectionId: CollectionId }) { const collections = useCollections(); return (
Delete collection Delete the collection and all items contained within. WARNING: This action is irreversible!
Are you absolutely sure? This action cannot be undone. This will permanently delete the collection and ALL items contained in it. Cancel
); } type HeaderProps = { label: string, children?: React.ReactNode, } function Header(props: HeaderProps) { return (

{props.label}

{props.children}
); }