import React from "react"; import { Form } from "react-bootstrap"; import { FilterSelect, DurationInput } from "src/components/Shared"; import { DurationUtils } from "."; const renderTextArea = (options: { value: string | undefined; isEditing: boolean; onChange: (value: string) => void; }) => { return ( ) => options.onChange(event.currentTarget.value) } value={options.value} /> ); }; const renderEditableText = (options: { title?: string; value?: string | number; isEditing: boolean; onChange: (value: string) => void; }) => { return ( ) => options.onChange(event.currentTarget.value) } value={ typeof options.value === "number" ? options.value.toString() : options.value } placeholder={options.title} /> ); }; const renderInputGroup = (options: { title?: string; placeholder?: string; value: string | undefined; isEditing: boolean; url?: string; onChange: (value: string) => void; }) => { if (options.url && !options.isEditing) { return ( {options.value} ); } return ( ) => options.onChange(event.currentTarget.value) } /> ); }; const renderDurationInput = (options: { value: string | undefined; isEditing: boolean; url?: string; asString?: boolean; onChange: (value: string | undefined) => void; }) => { let numericValue: number | undefined; if (options.value) { if (!options.asString) { try { numericValue = Number.parseInt(options.value, 10); } catch { // ignore } } else { numericValue = DurationUtils.stringToSeconds(options.value); } } if (!options.isEditing) { let durationString; if (numericValue !== undefined) { durationString = DurationUtils.secondsToString(numericValue); } return ( ); } return ( { let value = valueAsString; if (!options.asString) { value = valueAsNumber !== undefined ? valueAsNumber.toString() : undefined; } options.onChange(value); }} /> ); }; const renderHtmlSelect = (options: { value?: string | number; isEditing: boolean; onChange: (value: string) => void; selectOptions: Array; }) => { if (!options.isEditing) { return ( ); } return ( ) => options.onChange(event.currentTarget.value) } > {options.selectOptions.map((opt) => ( ))} ); }; // TODO: isediting const renderFilterSelect = (options: { type: "performers" | "studios" | "tags"; initialId: string | undefined; onChange: (id: string | undefined) => void; }) => ( options.onChange(items[0]?.id)} initialIds={options.initialId ? [options.initialId] : []} /> ); // TODO: isediting const renderMultiSelect = (options: { type: "performers" | "studios" | "tags"; initialIds: string[] | undefined; onChange: (ids: string[]) => void; }) => ( options.onChange(items.map((i) => i.id))} initialIds={options.initialIds ?? []} /> ); const EditableTextUtils = { renderTextArea, renderEditableText, renderInputGroup, renderDurationInput, renderHtmlSelect, renderFilterSelect, renderMultiSelect, }; export default EditableTextUtils;