import { Plus, RefreshCw, Save, Trash2 } from 'lucide-react' import type { Library, LibraryRoot } from '../types' import type { RootDraft } from './adminLibraryPanelModel' import { fallbackLibraryRoot } from './adminLibraryPanelModel' type LibraryTableProps = { libs: Library[] newRootDraft: (libraryID: string) => RootDraft editableRootDraft: (libraryID: string, root: LibraryRoot) => RootDraft onNewRootChange: (libraryID: string, patch: Partial) => void onEditableRootChange: (libraryID: string, root: LibraryRoot, patch: Partial) => void onAddRoot: (libraryID: string) => void onSaveRoot: (libraryID: string, root: LibraryRoot) => void onScanRoot: (libraryID: string, root: LibraryRoot) => void onToggleRoot: (libraryID: string, root: LibraryRoot) => void onRemoveRoot: (library: Library, root: LibraryRoot) => void onScanLibrary: (library: Library) => void onRemoveLibrary: (library: Library) => void } export function AdminLibraryTable({ libs, ...actions }: LibraryTableProps) { return (
{libs.map((library) => ( ))}
名称 路径 类型 操作
) } type LibraryTableRowProps = Omit & { library: Library } function LibraryTableRow({ library, ...actions }: LibraryTableRowProps) { return ( {library.name} {library.type} ) } function LibraryRootsCell({ library, ...actions }: LibraryTableRowProps) { const roots = library.roots?.length ? library.roots : [fallbackLibraryRoot(library)] return (
{roots.map((root) => ( ))}
) } type RootEditorProps = Omit & { library: Library root: LibraryRoot } function ExistingRootEditor({ library, root, ...actions }: RootEditorProps) { const draft = actions.editableRootDraft(library.id, root) return (
{root.id ? ( ) : ( {root.name ? `${root.name}:${root.path}` : root.path} )}
) } function EditableRootFields({ library, root, draft, onEditableRootChange }: RootEditorProps & { draft: RootDraft }) { return ( <> onEditableRootChange(library.id, root, { name: e.target.value })} /> onEditableRootChange(library.id, root, { path: e.target.value })} /> ) } function RootActionButtons({ library, root, draft, ...actions }: RootEditorProps & { draft: RootDraft }) { return (
{root.id && ( )} {root.id && ( )} {root.id && ( )}
) } function AddRootRow({ library, ...actions }: LibraryTableRowProps) { const draft = actions.newRootDraft(library.id) return (
actions.onNewRootChange(library.id, { name: e.target.value })} /> actions.onNewRootChange(library.id, { path: e.target.value })} />
) } function LibraryActionsCell({ library, onScanLibrary, onRemoveLibrary }: LibraryTableRowProps) { return ( <> ) }