import { createSignal, createEffect } from 'solid-js'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { TagPicker } from '@/components/ui/TagPicker'; import { ModalPortal } from '@/components/ui/ModalPortal'; import { IconX } from '@tabler/icons-solidjs'; interface BookmarkModalProps { isOpen: boolean; onClose: () => void; onSubmit: (bookmark: any) => void; availableTags?: string[]; } export const BookmarkModal = (props: BookmarkModalProps) => { const [newBookmark, setNewBookmark] = createSignal({ title: '', url: '', description: '' }); const [faviconPreview, setFaviconPreview] = createSignal(''); const [tags, setTags] = createSignal([]); const defaultTags = ['reading', 'article', 'dev', 'tutorial', 'docs', 'tool', 'video', 'personal', 'work']; const availableTags = () => (props.availableTags && props.availableTags.length > 0 ? props.availableTags : defaultTags); // Update favicon preview when URL changes createEffect(() => { const url = newBookmark().url; if (url) { try { const urlObj = new URL(url); const faviconUrl = `https://www.google.com/s2/favicons?domain=${urlObj.hostname}&sz=64`; setFaviconPreview(faviconUrl); } catch { setFaviconPreview(''); } } else { setFaviconPreview(''); } }); const handleSubmit = () => { const bookmark = { title: newBookmark().title || newBookmark().url, url: newBookmark().url, description: newBookmark().description, tags: tags() }; props.onSubmit(bookmark); setNewBookmark({ title: '', url: '', description: '' }); setTags([]); }; return ( <> {/* Backdrop */} {props.isOpen && (
)} {/* Modal */}
{/* Header */}

Add New Bookmark

{/* Content */}
{ const target = e.currentTarget as HTMLInputElement; if (target) setNewBookmark(prev => ({ ...prev, url: target.value })); }} required class="pr-12" /> {faviconPreview() && (
Site favicon { e.currentTarget.style.display = 'none'; }} />
)}
{ const target = e.currentTarget as HTMLInputElement; if (target) setNewBookmark(prev => ({ ...prev, title: target.value })); }} /> { const target = e.currentTarget as HTMLInputElement; if (target) setNewBookmark(prev => ({ ...prev, description: target.value })); }} />
setTags(next)} placeholder="Add tags..." allowNew={true} />
{/* Footer */}
); };