diff --git a/app/src/api.js b/app/src/api.js index b56dfcae..fc80cfe1 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -236,9 +236,10 @@ export async function getVideo(fileGroupId) { return [data['file_group'], data['prev'], data['next']]; } -export async function updateVideo(fileGroupId, {title}) { - // Edits the Video's details (written to its info json). Returns the updated video file group. - const response = await apiPut(`${VIDEOS_API}/${fileGroupId}`, {title}); +export async function updateVideo(fileGroupId, {title, description}) { + // Edits the Video's details (written to its info json). Only the fields given are changed. + // Returns the updated video file group. + const response = await apiPut(`${VIDEOS_API}/${fileGroupId}`, {title, description}); if (!response.ok) { const message = await getErrorMessage(response, 'Unable to save the video. See server logs.'); toast({type: 'error', title: 'Failed to save', description: message, time: 5000}); diff --git a/app/src/components/VideoEditMenu.js b/app/src/components/VideoEditMenu.js index 2020cf3f..d8244cef 100644 --- a/app/src/components/VideoEditMenu.js +++ b/app/src/components/VideoEditMenu.js @@ -1,7 +1,7 @@ import React, {useEffect, useRef, useState} from 'react'; 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, TextInput, toast} from './ui'; +import {Button, Confirm, Group, Icon, Menu, Modal, Progress, Select, Stack, Status, Text, Textarea, TextInput, toast} from './ui'; import { TRANSCODE_COPY, transcodeAudioCodecOptions, @@ -272,24 +272,32 @@ export function TranscodeModal({open, onClose, fileGroupId, video, onComplete}) * 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}) { +export function EditVideoModal({open, onClose, fileGroupId, videoFile, description: currentDescription, onSaved}) { const [title, setTitle] = useState(''); + const [description, setDescription] = useState(''); const [saving, setSaving] = useState(false); useEffect(() => { if (open) { // Start from the current details on every open, discarding an abandoned edit. setTitle(videoFile?.title || ''); + setDescription(currentDescription || ''); } - }, [open, videoFile?.title]); + }, [open, videoFile?.title, currentDescription]); const trimmed = title.trim(); - const unchanged = trimmed === (videoFile?.title || ''); + const titleChanged = trimmed !== (videoFile?.title || ''); + const descriptionChanged = description !== (currentDescription || ''); + const unchanged = !titleChanged && !descriptionChanged; const handleSave = async () => { setSaving(true); try { - const updated = await updateVideo(fileGroupId, {title: trimmed}); + // Send only what changed, so an untouched field is never rewritten. + const changes = {}; + if (titleChanged) changes.title = trimmed; + if (descriptionChanged) changes.description = description; + const updated = await updateVideo(fileGroupId, changes); toast({type: 'success', title: 'Saved', description: 'The video was updated.', time: 3000}); if (onSaved) await onSaved(updated); onClose(); @@ -304,10 +312,8 @@ export function EditVideoModal({open, onClose, fileGroupId, videoFile, onSaved}) return Edit Video -
{ - e.preventDefault(); - if (trimmed && !unchanged && !saving) handleSave(); - }}> + {/* No submit-on-Enter: Enter belongs to the description's new lines. */} + e.preventDefault()}> +