Implemented the new react version of the frontend

This commit is contained in:
Mohammed Abad committed 2026-03-31 01:56:38 +01:00
1 parent 236e6e06fb
commit ffe7e52527
65 files changed
+5228 -177

No files matched your search

@@ -0,0 +1,81 @@
import { useState } from 'react';
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { Checkbox } from '@/components/ui/checkbox';
import { ScrollArea } from '@/components/ui/scroll-area';
import { useCollections } from '@/hooks/useCollections';
import { collectionsApi } from '@/api/collections';
import type { Collection } from '@/types';
interface AddEntryToCollectionDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
entryId: number;
entryCollections?: Collection[];
}
export function AddEntryToCollectionDialog({
open,
onOpenChange,
entryId,
entryCollections = [],
}: AddEntryToCollectionDialogProps) {
const [search, setSearch] = useState('');
const { data: allCollections = [] } = useCollections();
const entryCollectionIds = new Set(entryCollections.map((c) => c.id));
const filtered = allCollections.filter((c) =>
c.name.toLowerCase().includes(search.toLowerCase())
);
const handleToggle = async (collectionId: number, checked: boolean) => {
if (checked) {
await collectionsApi.addEntry(collectionId, entryId);
} else {
await collectionsApi.removeEntry(collectionId, entryId);
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Add to Collection</DialogTitle>
</DialogHeader>
<Input
placeholder="Search collections..."
value={search}
onChange={(e) => setSearch(e.target.value)}
/>
<ScrollArea className="h-64">
<div className="space-y-2 pr-4">
{filtered.map((collection) => (
<label
key={collection.id}
className="flex cursor-pointer items-center gap-3 rounded-lg p-2 hover:bg-accent/50"
>
<Checkbox
checked={entryCollectionIds.has(collection.id)}
onCheckedChange={(checked) =>
handleToggle(collection.id, !!checked)
}
/>
<span className="text-sm">{collection.name}</span>
</label>
))}
{filtered.length === 0 && (
<p className="py-4 text-center text-sm text-muted-foreground">
No collections found.
</p>
)}
</div>
</ScrollArea>
</DialogContent>
</Dialog>
);
}