import clsx from "clsx"; import { Sidebar } from "./sidebar"; import { ConnectionSettingsModal } from "./connection-settings-modal"; import { SettingsModal } from "./settings-modal"; import { useAppState } from "../contexts/state"; import { useBool } from "@common/hooks/useBool"; import type { Story } from "../contexts/state"; import styles from '../assets/menu-sidebar.module.css'; import { useState } from "preact/hooks"; import { Pencil, X, Plus, Plug, Settings, Copy } from "lucide-preact"; // ─── Story Item ─────────────────────────────────────────────────────────────── interface StoryItemProps { story: Story; active: boolean; onSelect: () => void; onRename: (newTitle: string) => void; onDelete: () => void; onDuplicate: () => void; } const StoryItem = ({ story, active, onSelect, onRename, onDelete, onDuplicate }: StoryItemProps) => { const [isEditing, setIsEditing] = useState(false); const [editTitle, setEditTitle] = useState(story.title); const handleSubmit = () => { if (editTitle.trim()) { onRename(editTitle.trim()); } setIsEditing(false); }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Enter') { handleSubmit(); } else if (e.key === 'Escape') { setEditTitle(story.title); setIsEditing(false); } }; const handleBlur = () => { handleSubmit(); }; if (isEditing) { return (
setEditTitle((e.target as HTMLInputElement).value)} onKeyDown={handleKeyDown} onBlur={handleBlur} autoFocus />
); } return (
); }; // ─── Menu Sidebar ───────────────────────────────────────────────────────────── export const MenuSidebar = () => { const { stories, currentStory, dispatch } = useAppState(); const isConnectionSettingsOpen = useBool(false); const isSettingsOpen = useBool(false); const handleCreate = () => { dispatch({ type: 'CREATE_STORY', title: 'New Story' }); }; const handleSelect = (id: string) => { dispatch({ type: 'SELECT_STORY', id }); }; const handleRename = (id: string, newTitle: string) => { dispatch({ type: 'RENAME_STORY', id, title: newTitle }); }; const handleDelete = (id: string) => { const story = stories.find(s => s.id === id); if (!story) return; if (confirm(`Delete "${story.title}"?`)) { dispatch({ type: 'DELETE_STORY', id }); } }; const handleDuplicate = (id: string) => { dispatch({ type: 'DUPLICATE_STORY', id }); }; return (
{stories.map(story => ( handleSelect(story.id)} onRename={(newTitle) => handleRename(story.id, newTitle)} onDelete={() => handleDelete(story.id)} onDuplicate={() => handleDuplicate(story.id)} /> ))}
{isSettingsOpen.value && ( )} {isConnectionSettingsOpen.value && ( )}
); };