import { FormEvent, useState } from 'react' import { Folder, Loader2, Plus, Trash2 } from 'lucide-react' import { LocalDirBrowserDialog } from '../components/LocalDirBrowserDialog' import type { RootDraft } from './adminLibraryPanelModel' type CreateFormProps = { name: string type: string coverURL: string roots: RootDraft[] createPerSubfolder: boolean creating: boolean onNameChange: (value: string) => void onTypeChange: (value: string) => void onCoverURLChange: (value: string) => void onCreatePerSubfolderChange: (value: boolean) => void onRootChange: (index: number, patch: Partial) => void onAddRoot: () => void onRemoveRoot: (index: number) => void onSubmit: (e: FormEvent) => void } export function AdminLibraryCreateForm({ name, type, coverURL, roots, createPerSubfolder, creating, onNameChange, onTypeChange, onCoverURLChange, onCreatePerSubfolderChange, onRootChange, onAddRoot, onRemoveRoot, onSubmit, }: CreateFormProps) { const [browsingIndex, setBrowsingIndex] = useState(null) const handleSelectDir = (selectedPath: string) => { if (browsingIndex === null) return const currentRoot = roots[browsingIndex] const segments = selectedPath.split(/[/\\]/).filter(Boolean) const baseName = segments.length > 0 ? segments[segments.length - 1] : '' const patch: Partial = { path: selectedPath } if (!currentRoot?.name?.trim() && baseName) { patch.name = baseName } onRootChange(browsingIndex, patch) setBrowsingIndex(null) } return ( <>
onNameChange(e.target.value)} /> onCoverURLChange(e.target.value)} />
{roots.map((root, index) => ( 1} onChange={onRootChange} onBrowse={() => setBrowsingIndex(index)} onRemove={onRemoveRoot} /> ))} {!createPerSubfolder && ( )}

支持直接点选或手动输入;名称和类型与现有媒体库一致时,会自动把这里填写的路径追加到该媒体库。

{createPerSubfolder && (

批处理模式:仅取上方第一个路径作为父级目录,会为其中每个子文件夹分别创建媒体库,可自选类型用于整体推断。

)}
{browsingIndex !== null && ( setBrowsingIndex(null)} /> )} ) } type CreateRootRowProps = { root: RootDraft index: number canRemove: boolean onChange: (index: number, patch: Partial) => void onBrowse: () => void onRemove: (index: number) => void } function CreateRootRow({ root, index, canRemove, onChange, onBrowse, onRemove }: CreateRootRowProps) { return (
onChange(index, { name: e.target.value })} /> onChange(index, { path: e.target.value })} />
) }