From 40c017fb349df5587c86e12d16ad9c25ee8ffffe Mon Sep 17 00:00:00 2001 From: Angelo Date: Sun, 24 Sep 2023 07:57:51 +0100 Subject: [PATCH] update --- .../components/Scenes/EditScenesDialog.tsx | 99 +++++++++++++------ ui/v2.5/src/components/Shared/Modal.tsx | 2 - 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/ui/v2.5/src/components/Scenes/EditScenesDialog.tsx b/ui/v2.5/src/components/Scenes/EditScenesDialog.tsx index 184b899d283..85976a6b5a5 100644 --- a/ui/v2.5/src/components/Scenes/EditScenesDialog.tsx +++ b/ui/v2.5/src/components/Scenes/EditScenesDialog.tsx @@ -10,7 +10,6 @@ import { } from "react-bootstrap"; import { FormattedMessage, useIntl } from "react-intl"; import isEqual from "lodash-es/isEqual"; -import { useBulkSceneUpdate } from "src/core/StashService"; import * as GQL from "src/core/generated-graphql"; import * as yup from "yup"; import { StudioSelect } from "../Shared/Select"; @@ -39,6 +38,7 @@ import { import { queryScrapeScene, queryScrapeSceneURL, + useBulkSceneUpdate, useListSceneScrapers, mutateReloadScrapers, queryScrapeSceneQueryFragment, @@ -50,6 +50,7 @@ import { faTrashAlt, } from "@fortawesome/free-solid-svg-icons"; import { objectTitle } from "src/core/files"; +import { Performer } from "src/components/Performers/PerformerSelect"; import { lazyComponent } from "src/utils/lazyComponent"; @@ -61,7 +62,7 @@ const SceneQueryModal = lazyComponent( ); interface IListOperationProps { - selected: GQL.SceneDataFragment[]; + selected: GQL.SlimSceneDataFragment[]; onClose: (applied: boolean) => void; } @@ -118,6 +119,7 @@ export const EditScenesDialog: React.FC = ( const [studioId, setStudioId] = useState(); const [performerMode, setPerformerMode] = React.useState(GQL.BulkUpdateIdMode.Add); + const [performers, setPerformers] = useState([]); const [performerIds, setPerformerIds] = useState(); const [existingPerformerIds, setExistingPerformerIds] = useState(); const [tagMode, setTagMode] = React.useState( @@ -209,6 +211,25 @@ export const EditScenesDialog: React.FC = ( cover_image: yup.string().nullable().optional(), }); + useEffect(() => { + if ( + props.selected && + props.selected.length > 0 && + props.selected[0].performers + ) { + const selectedPerformers = props.selected[0].performers; + // Transform 'SelectObject' to match 'Performer' type + const filterPerformers: Performer[] = selectedPerformers.map( + (performer) => ({ + id: performer.id, + name: performer.name, + alias_list: [], + }) + ); + setPerformers(filterPerformers); + } + }, [props.selected]); + async function onScrapeClicked(s: GQL.ScraperSourceInput) { setIsLoading(true); try { @@ -340,6 +361,7 @@ export const EditScenesDialog: React.FC = ( return ( onScrapeDialogClosed(s)} @@ -544,8 +566,8 @@ export const EditScenesDialog: React.FC = ( if (updatedScene.remote_site_id && endpoint) { let found = false; - setStashIds((stashIds) => - stashIds.map((s) => { + setStashIds((prevStashIds) => + prevStashIds.map((s) => { if (s.endpoint === endpoint) { found = true; return { @@ -558,8 +580,8 @@ export const EditScenesDialog: React.FC = ( ); if (!found) { - setStashIds((stashIds) => [ - ...stashIds, + setStashIds((prevStashIds) => [ + ...prevStashIds, { endpoint, stash_id: updatedScene.remote_site_id }, ]); } @@ -687,7 +709,7 @@ export const EditScenesDialog: React.FC = ( let updateCoverImage: string | undefined; let updatestashIds: { stash_id: string; endpoint: string }[] = []; - state.forEach((scene: GQL.SceneDataFragment) => { + state.forEach((scene: GQL.SlimSceneDataFragment) => { if (state.length === 1) { const sceneTitle = scene.title; const sceneStudioCode = scene.code; @@ -800,7 +822,7 @@ export const EditScenesDialog: React.FC = ( } return null; - }, [coverImage]); + }, [props.selected, isSingleScene, coverImage]); function onImageLoad(imageData: string) { setCoverImage(imageData); @@ -835,7 +857,7 @@ export const EditScenesDialog: React.FC = ( // Return null or a default component when not a single scene is selected return null; - }, [encodingImage, coverImagePreview, intl]); + }, [isSingleScene, encodingImage, coverImagePreview, intl]); function renderMultiSelect( type: "galleries" | "performers" | "tags" | "movies", @@ -942,13 +964,20 @@ export const EditScenesDialog: React.FC = ( } } - const variableMap: Record = { + const variableMap: Record = { title: title, code: studioCode, date: date, director: director, }; + class CustomError extends Error { + constructor(message: string) { + super(message); + this.name = "CustomError"; + } + } + async function handleUrlInputChange(value: string[]) { // Update the URL input values setUrls({ @@ -964,24 +993,28 @@ export const EditScenesDialog: React.FC = ( ...prevErrors, ["urls"]: undefined, })); - } catch (error: any) { - setUrlsErrorMsg( - intl.formatMessage({ id: "validation.urls_must_be_unique" }) - ); - const errorIndices = error.message - .split(" ") - .map((e: string) => parseInt(e)); - setUrlsErrorIdx(errorIndices); - setValidationErrors((prevErrors) => ({ - ...prevErrors, - ["urls"]: error.message, - })); + } catch (error: unknown) { + if (error instanceof CustomError) { + const customError = error as CustomError; + setUrlsErrorMsg( + intl.formatMessage({ id: "validation.urls_must_be_unique" }) + ); + const errorIndices = customError.message + .split(" ") + .map((e: string) => parseInt(e)); + setUrlsErrorIdx(errorIndices); + setValidationErrors((prevErrors) => ({ + ...prevErrors, + ["urls"]: customError.message, + })); + } else { + throw error; + } } } - function renderTextField( field: updateVariableType, - title: string, + label: string, placeholder?: string ) { const handleChanges = async (e: ChangeEvent) => { @@ -999,17 +1032,23 @@ export const EditScenesDialog: React.FC = ( ...prevErrors, [name]: undefined, })); - } catch (error: any) { - setValidationErrors((prevErrors) => ({ - ...prevErrors, - [name]: error.message, - })); + } catch (error: unknown) { + if (error instanceof CustomError) { + const customError = error as CustomError; + + setValidationErrors((prevErrors) => ({ + ...prevErrors, + [name]: customError.message, + })); + } else { + throw error; + } } }; return ( {FormUtils.renderLabel({ - title, + title: label, })} {}; @@ -42,7 +41,6 @@ export const ModalComponent: React.FC = ({ dialogClassName, footerButtons, leftFooterButtons, - scrollable, }) => (