import { LoaderIcon, PencilIcon, XIcon } from "lucide-solid" import { useMutation, useQueryClient } from "@tanstack/solid-query" import { createSignal, Show } from "solid-js" import { client } from "../apiclient.ts" import { Bookmark } from "../../server/utils/bookmarks.ts" import "./BookmarkEditModal.css" import "./ui/button.css" import { useWebHaptics } from "../utils/haptics.ts" interface BookmarkEditModalProps { bookmark: Bookmark & { id: string } } export function BookmarkEditModal(props: BookmarkEditModalProps) { const haptics = useWebHaptics() const queryClient = useQueryClient() const [title, setTitle] = createSignal(props.bookmark.title) const [description, setDescription] = createSignal( props.bookmark.description, ) const editBookmark = useMutation(() => ({ mutationFn: async () => { const res = await client.api.v1.bookmarks[":id"].$put({ param: { id: props.bookmark.id }, json: { title: title().trim(), description: description().trim(), }, }) if (!res.ok) { const data = await res.json() haptics.trigger([ { duration: 40, intensity: 0.7 }, { delay: 40, duration: 40, intensity: 0.7 }, { delay: 40, duration: 40, intensity: 0.9 }, { delay: 40, duration: 50, intensity: 0.6 }, ]) throw new Error( "error" in data ? data.error : "Failed to update bookmark", ) } return await res.json() }, onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: [client.api.v1.bookmarks.all.$url().pathname], }) // Close the modal const dialog = document.getElementById( `edit-${props.bookmark.id}`, ) as HTMLDialogElement | null dialog?.requestClose() }, })) const handleSubmit = (e: SubmitEvent) => { e.preventDefault() const titleValue = title().trim() if (titleValue) { editBookmark.mutate() } } return ( <>

Edit bookmark

setTitle(e.currentTarget.value)} disabled={editBookmark.isPending} maxlength="200" />