diff --git a/app/src/api.js b/app/src/api.js index 817d3abc..743bc8a1 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -1499,3 +1499,8 @@ export async function postRestart() { } return null } + +export async function postVideoFileFormat(video_file_format) { + const body = {video_file_format}; + return await apiPost(`${API_URI}/videos/file_format`, body); +} \ No newline at end of file diff --git a/app/src/components/Common.js b/app/src/components/Common.js index 5a4a1299..60780617 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -1607,7 +1607,7 @@ export function WarningMessage({children, size = null, icon = 'exclamation'}) { } export function ErrorMessage({children, size = null, icon = 'exclamation'}) { - return + return {children} diff --git a/app/src/components/Videos.js b/app/src/components/Videos.js index 595547b8..47b033c3 100644 --- a/app/src/components/Videos.js +++ b/app/src/components/Videos.js @@ -43,7 +43,7 @@ import {FileRowTagIcon, FilesView} from "./Files"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; import Icon from "semantic-ui-react/dist/commonjs/elements/Icon"; import {Button, Card, Header, Loader, Placeholder, Popup, Segment, Statistic, StatisticGroup} from "./Theme"; -import {deleteVideos, fetchVideoDownloaderConfig, saveVideoDownloaderConfig} from "../api"; +import {deleteVideos, fetchVideoDownloaderConfig, postVideoFileFormat, saveVideoDownloaderConfig} from "../api"; import {Media, QueryContext, ThemeContext} from "../contexts/contexts"; import _ from "lodash"; import {defaultFileOrder, defaultSearchOrder} from "./Vars"; @@ -222,6 +222,29 @@ function VideosPage() { } +function VideoFileNameForm({form}) { + const [message, setMessage] = React.useState(null); + + const onChange = async (value) => { + const response = await postVideoFileFormat(value); + const {error, preview} = await response.json(); + if (error) { + setMessage({content: error, header: 'Invalid File Name', negative: true}); + } else { + setMessage({content: preview, header: 'File Name Preview', positive: true}); + } + } + + return +} + function VideosSettings() { useTitle('Videos Settings'); @@ -255,62 +278,55 @@ function VideosSettings() {
- - + + - - - - + + - - + + - - - + - + - - - + diff --git a/app/src/hooks/useForm.js b/app/src/hooks/useForm.js index d563203e..e6f29dc5 100644 --- a/app/src/hooks/useForm.js +++ b/app/src/hooks/useForm.js @@ -1,7 +1,8 @@ import React from "react"; import _ from "lodash"; import {HelpPopup, RequiredAsterisk, Toggle, validURL, validURLs} from "../components/Common"; -import {FormInput, TextArea} from "../components/Theme"; +import {FormInput, Icon, TextArea} from "../components/Theme"; +import Message from "semantic-ui-react/dist/commonjs/collections/Message"; async function asyncNoOp() { @@ -158,6 +159,8 @@ export function useForm({ // Trigger validation after a delay debouncedValidate(path, value); + + return value; } const addValidator = (path, validator) => { @@ -207,7 +210,7 @@ export function useForm({ return [inputProps, inputAttrs] } - const getInputProps = ({name, validator, path, required = false, type = 'text'}) => { + const getInputProps = ({name, validator, path, required = false, type = 'text', onChange = null}) => { // Props for path = path || name; @@ -218,11 +221,19 @@ export function useForm({ const [customProps, inputAttrs] = getCustomProps({name, validator, path, type, required}); + const localHandleInputEvent = async (e) => { + if (e) e.preventDefault(); + const value = handleInputEvent(e); + if (onChange) { + await onChange(value); + } + } + // Attributes that should be passed as properties to the input. const inputProps = { ...customProps, name: name, - onChange: handleInputEvent, + onChange: localHandleInputEvent, error: errors[path] || null, required: required ? null : undefined, } @@ -280,10 +291,21 @@ export function InputForm({ helpPosition = 'top', extraInputProps = {}, disabled = false, + onChange = null, + message = null, }) { - const [inputProps, inputAttrs] = form.getInputProps({name, path, validator, type, required}); + const [inputProps, inputAttrs] = form.getInputProps({name, path, validator, type, required, onChange}); inputProps.disabled = disabled || inputProps.disabled; + let messageElm = null; + if (message && message.positive) { + messageElm = ; + } else if (message && message.negative) { + messageElm = ; + } else if (message) { + messageElm = ; + } + return <>