import { fireAndForget, makeIconClass } from "@/util/util"; import clsx from "clsx"; import { memo, useEffect, useRef, useState } from "react"; import { Button } from "../element/button"; import { Input } from "../element/input"; import { WorkspaceService } from "../store/services"; import "./workspaceeditor.scss"; interface ColorSelectorProps { colors: string[]; selectedColor?: string; onSelect: (color: string) => void; className?: string; } const ColorSelector = memo(({ colors, selectedColor, onSelect, className }: ColorSelectorProps) => { const handleColorClick = (color: string) => { onSelect(color); }; return (
{colors.map((color) => (
handleColorClick(color)} /> ))}
); }); interface IconSelectorProps { icons: string[]; selectedIcon?: string; onSelect: (icon: string) => void; className?: string; } const IconSelector = memo(({ icons, selectedIcon, onSelect, className }: IconSelectorProps) => { const handleIconClick = (icon: string) => { onSelect(icon); }; return (
{icons.map((icon) => { const iconClass = makeIconClass(icon, true); return ( handleIconClick(icon)} /> ); })}
); }); interface WorkspaceEditorProps { title: string; icon: string; color: string; focusInput: boolean; onTitleChange: (newTitle: string) => void; onColorChange: (newColor: string) => void; onIconChange: (newIcon: string) => void; onDeleteWorkspace: () => void; } const WorkspaceEditorComponent = ({ title, icon, color, focusInput, onTitleChange, onColorChange, onIconChange, onDeleteWorkspace, }: WorkspaceEditorProps) => { const inputRef = useRef(null); const [colors, setColors] = useState([]); const [icons, setIcons] = useState([]); useEffect(() => { fireAndForget(async () => { const colors = await WorkspaceService.GetColors(); const icons = await WorkspaceService.GetIcons(); setColors(colors); setIcons(icons); }); }, []); useEffect(() => { if (focusInput && inputRef.current) { inputRef.current.focus(); inputRef.current.select(); } }, [focusInput]); return (
); }; export const WorkspaceEditor = memo(WorkspaceEditorComponent) as typeof WorkspaceEditorComponent;