From bee571ed19e77c1cb275c5c9ce3026555b78dcf7 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Fri, 27 Feb 2026 22:59:04 +0100 Subject: [PATCH] Edit --- src/components/view/edit/EditView.tsx | 318 ++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) create mode 100644 src/components/view/edit/EditView.tsx diff --git a/src/components/view/edit/EditView.tsx b/src/components/view/edit/EditView.tsx new file mode 100644 index 0000000..a9b8b4a --- /dev/null +++ b/src/components/view/edit/EditView.tsx @@ -0,0 +1,318 @@ +"use client"; + +import { Tag, TagId, Status } from "@/lib/types"; +import { useState } from "react"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Card } from "@/components/ui/card"; +import { Badge } from "@/components/ui/badge"; +import { Separator } from "@/components/ui/separator"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; +import { X, Plus, GripVertical } from "lucide-react"; + +export type EditViewProps = { + tags: Record; + statuses: Status[]; + setTags: (tags: Record) => void; + setStatuses: (statuses: Status[]) => void; +}; + +const COLOR_OPTIONS = [ + "red", + "orange", + "yellow", + "green", + "blue", + "indigo", + "purple", + "pink", + "gray", +]; + +export default function EditView({ + tags, + statuses, + setTags, + setStatuses, +}: EditViewProps) { + const [newTagName, setNewTagName] = useState(""); + const [newTagColor, setNewTagColor] = useState("blue"); + const [newStatusName, setNewStatusName] = useState(""); + const [newStatusColor, setNewStatusColor] = useState("blue"); + + const handleAddTag = () => { + if (newTagName.trim()) { + const newTagId = `tag-${Date.now()}`; + setTags({ + ...tags, + [newTagId]: { + id: newTagId, + name: newTagName, + color: newTagColor, + }, + }); + setNewTagName(""); + setNewTagColor("blue"); + } + }; + + const handleDeleteTag = (tagId: TagId) => { + const newTags = { ...tags }; + delete newTags[tagId]; + setTags(newTags); + }; + + const handleAddStatus = () => { + if (newStatusName.trim()) { + const newStatus: Status = { + id: `status-${Date.now()}`, + name: newStatusName, + color: newStatusColor, + order: statuses.length, + }; + setStatuses([...statuses, newStatus]); + setNewStatusName(""); + setNewStatusColor("blue"); + } + }; + + const handleDeleteStatus = (statusId: string) => { + setStatuses(statuses.filter((s) => s.id !== statusId)); + }; + + const handleUpdateStatusName = (statusId: string, newName: string) => { + setStatuses( + statuses.map((s) => (s.id === statusId ? { ...s, name: newName } : s)), + ); + }; + + const handleUpdateStatusColor = (statusId: string, newColor: string) => { + setStatuses( + statuses.map((s) => (s.id === statusId ? { ...s, color: newColor } : s)), + ); + }; + + const handleUpdateTagName = (tagId: TagId, newName: string) => { + setTags({ + ...tags, + [tagId]: { ...tags[tagId], name: newName }, + }); + }; + + const handleUpdateTagColor = (tagId: TagId, newColor: string) => { + setTags({ + ...tags, + [tagId]: { ...tags[tagId], color: newColor }, + }); + }; + + return ( +
+ {/* Tags Section */} +
+

Tags

+ + {Object.entries(tags).map(([tagId, tag]) => ( +
+ + +
+ + + + handleUpdateTagName(tagId, e.target.value)} + placeholder="Tag name" + className="flex-1" + /> + + +
+ ))} + + + +
+ + +
+ + + + setNewTagName(e.target.value)} + placeholder="New tag name" + className="flex-1" + onKeyDown={(e) => { + if (e.key === "Enter") { + handleAddTag(); + } + }} + /> + + +
+ + + + {/* Statuses Section */} +
+

Statuses

+ + {statuses.map((status) => ( +
+ + + + +
+ + + + + handleUpdateStatusName(status.id, e.target.value) + } + placeholder="Status name" + className="flex-1" + /> + + +
+ ))} + + + +
+ + +
+ + + + setNewStatusName(e.target.value)} + placeholder="New status name" + className="flex-1" + onKeyDown={(e) => { + if (e.key === "Enter") { + handleAddStatus(); + } + }} + /> + + + + + + + ); +}