mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Video page: Edit > Edit to change a video's title
PUT /api/videos/<file_group_id> writes the title (and fulltitle) into the Video's info json, creating the file when the video has none, then validates the Video again so its title and search text follow. Files stay the source of truth: the edit survives a refresh, and a re-download of the metadata replaces it (the modal says so). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
712d89c424
commit
cc25e342d4
8 changed files with 282 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React, {useEffect, useRef, useState} from 'react';
|
||||
import {cancelJob, fetchVideoDownloadDefaults, getJob, transcodeVideo} from '../api';
|
||||
import {cancelJob, fetchVideoDownloadDefaults, getJob, transcodeVideo, updateVideo} from '../api';
|
||||
import {useWROLMode} from '../hooks/customHooks';
|
||||
import {Button, Confirm, Group, Icon, Menu, Modal, Progress, Select, Stack, Status, Text, toast} from './ui';
|
||||
import {Button, Confirm, Group, Icon, Menu, Modal, Progress, Select, Stack, Status, Text, TextInput, toast} from './ui';
|
||||
import {
|
||||
TRANSCODE_COPY,
|
||||
transcodeAudioCodecOptions,
|
||||
|
|
@ -268,6 +268,73 @@ export function TranscodeModal({open, onClose, fileGroupId, video, onComplete})
|
|||
</Modal>
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a Video's details. The change is written to the Video's info json, so it survives a
|
||||
* refresh; a re-download of the Video's metadata will overwrite it.
|
||||
*/
|
||||
export function EditVideoModal({open, onClose, fileGroupId, videoFile, onSaved}) {
|
||||
const [title, setTitle] = useState('');
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
// Start from the current details on every open, discarding an abandoned edit.
|
||||
setTitle(videoFile?.title || '');
|
||||
}
|
||||
}, [open, videoFile?.title]);
|
||||
|
||||
const trimmed = title.trim();
|
||||
const unchanged = trimmed === (videoFile?.title || '');
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
const updated = await updateVideo(fileGroupId, {title: trimmed});
|
||||
toast({type: 'success', title: 'Saved', description: 'The video was updated.', time: 3000});
|
||||
if (onSaved) await onSaved(updated);
|
||||
onClose();
|
||||
} catch (e) {
|
||||
// updateVideo already toasted.
|
||||
console.error(e);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return <Modal open={open} onClose={onClose} size='small'>
|
||||
<Modal.Header>Edit Video</Modal.Header>
|
||||
<Modal.Content>
|
||||
<form onSubmit={e => {
|
||||
e.preventDefault();
|
||||
if (trimmed && !unchanged && !saving) handleSave();
|
||||
}}>
|
||||
<TextInput
|
||||
label='Title'
|
||||
value={title}
|
||||
onChange={e => setTitle(e.currentTarget.value)}
|
||||
error={!trimmed ? 'A title is required' : null}
|
||||
data-autofocus
|
||||
/>
|
||||
<Text size='sm' c='var(--muted)' mt='sm'>
|
||||
Saved to the video's info json. Refreshing the video from its source will replace it.
|
||||
</Text>
|
||||
</form>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button role='cancel' onClick={onClose}>Cancel</Button>
|
||||
<Button
|
||||
role='save'
|
||||
icon='save'
|
||||
onClick={handleSave}
|
||||
loading={saving}
|
||||
disabled={saving || !trimmed || unchanged}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
}
|
||||
|
||||
/**
|
||||
* The "Edit" dropdown on the Video page: Refresh (re-download metadata), Transcode, and Delete.
|
||||
*
|
||||
|
|
@ -275,8 +342,9 @@ export function TranscodeModal({open, onClose, fileGroupId, video, onComplete})
|
|||
* page can fetch the Video again (its path and codecs changed). `onDelete` is awaited after the
|
||||
* user confirms; the page decides what happens next (navigate away, or the tagged-files prompt).
|
||||
*/
|
||||
export function VideoEditMenu({videoFile, video, onRefresh, onTranscodeComplete, onDelete}) {
|
||||
export function VideoEditMenu({videoFile, video, onRefresh, onTranscodeComplete, onDelete, onSaved}) {
|
||||
const wrolModeEnabled = useWROLMode();
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [transcodeOpen, setTranscodeOpen] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
|
@ -309,6 +377,13 @@ export function VideoEditMenu({videoFile, video, onRefresh, onTranscodeComplete,
|
|||
<Button role='primary' icon='edit' iconAfter='dropdown' loading={refreshing}>Edit</Button>
|
||||
</Menu.Target>
|
||||
<Menu.Dropdown>
|
||||
<Menu.Item
|
||||
leftSection={<Icon name='edit'/>}
|
||||
onClick={() => setEditOpen(true)}
|
||||
disabled={!!wrolModeEnabled}
|
||||
>
|
||||
Edit...
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
leftSection={<Icon name='refresh'/>}
|
||||
onClick={handleRefresh}
|
||||
|
|
@ -334,6 +409,13 @@ export function VideoEditMenu({videoFile, video, onRefresh, onTranscodeComplete,
|
|||
</Menu.Item>
|
||||
</Menu.Dropdown>
|
||||
</Menu>
|
||||
<EditVideoModal
|
||||
open={editOpen}
|
||||
onClose={() => setEditOpen(false)}
|
||||
fileGroupId={videoFile?.id}
|
||||
videoFile={videoFile}
|
||||
onSaved={onSaved}
|
||||
/>
|
||||
<Confirm
|
||||
open={deleteOpen}
|
||||
title='Delete video?'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue