diff --git a/web/src/pages/ProfileFormModal.tsx b/web/src/pages/ProfileFormModal.tsx index a4d0348..e22cdb4 100644 --- a/web/src/pages/ProfileFormModal.tsx +++ b/web/src/pages/ProfileFormModal.tsx @@ -1,9 +1,14 @@ -import { FormEvent, useState, type ReactNode } from 'react' -import { Loader2 } from 'lucide-react' +import { FormEvent, useState } from 'react' import toast from 'react-hot-toast' import { playProfilesAPI, type PlayProfileInput } from '../api/play_profiles' import type { Library, PlayProfile } from '../types' +import { + ProfileFormActions, + ProfileIdentityFields, + ProfileLibraryAccessField, + ProfilePreferenceFields, +} from './ProfileFormSections' type ProfileFormModalProps = { editing: PlayProfile | null @@ -72,178 +77,12 @@ export function ProfileFormModal({ {editing ? '编辑 Profile' : '创建 Profile'}
- - update({ name: event.target.value })} - /> - - - update({ is_default: value })} - /> - - - - - - update({ allow_adult: value })} - /> - - update({ require_pin: value })} - /> - {form.require_pin && ( - - update({ pin: event.target.value })} - /> - - )} - -
- - - - - - -
- - update({ autoplay_next: value })} - /> - update({ skip_intro: value })} - /> - - -
- {libraries.map((library) => ( - - ))} - {libraries.length === 0 && ( - 暂无媒体库 - )} -
-
- -
- - -
+ + + + ) } - -function Field({ label, children }: { label: string; children: ReactNode }) { - return ( - - ) -} - -function Toggle({ - label, - hint, - checked, - onChange, -}: { - label: string - hint?: string - checked: boolean - onChange: (value: boolean) => void -}) { - return ( - - ) -} diff --git a/web/src/pages/ProfileFormSections.tsx b/web/src/pages/ProfileFormSections.tsx new file mode 100644 index 0000000..66b49d0 --- /dev/null +++ b/web/src/pages/ProfileFormSections.tsx @@ -0,0 +1,226 @@ +import type { ReactNode } from 'react' +import { Loader2 } from 'lucide-react' + +import type { PlayProfileInput } from '../api/play_profiles' +import type { Library, PlayProfile } from '../types' + +type ProfileFormUpdate = (patch: Partial) => void + +export function ProfileIdentityFields({ + form, + editing, + update, +}: { + form: PlayProfileInput + editing: PlayProfile | null + update: ProfileFormUpdate +}) { + return ( + <> + + update({ name: event.target.value })} + /> + + + update({ is_default: value })} + /> + + + + + + update({ allow_adult: value })} + /> + + update({ require_pin: value })} + /> + {form.require_pin && ( + + update({ pin: event.target.value })} + /> + + )} + + ) +} + +export function ProfilePreferenceFields({ + form, + update, +}: { + form: PlayProfileInput + update: ProfileFormUpdate +}) { + return ( + <> +
+ + + + + + +
+ + update({ autoplay_next: value })} + /> + update({ skip_intro: value })} + /> + + ) +} + +export function ProfileLibraryAccessField({ + form, + libraries, + onToggleLibrary, +}: { + form: PlayProfileInput + libraries: Library[] + onToggleLibrary: (id: string) => void +}) { + return ( + +
+ {libraries.map((library) => ( + + ))} + {libraries.length === 0 && ( + 暂无媒体库 + )} +
+
+ ) +} + +export function ProfileFormActions({ + saving, + onClose, +}: { + saving: boolean + onClose: () => void +}) { + return ( +
+ + +
+ ) +} + +function Field({ label, children }: { label: string; children: ReactNode }) { + return ( + + ) +} + +function Toggle({ + label, + hint, + checked, + onChange, +}: { + label: string + hint?: string + checked: boolean + onChange: (value: boolean) => void +}) { + return ( + + ) +}