Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
elkorol committed Sep 24, 2023
1 parent dd1a260 commit 40c017f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 32 deletions.
99 changes: 69 additions & 30 deletions ui/v2.5/src/components/Scenes/EditScenesDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -39,6 +38,7 @@ import {
import {
queryScrapeScene,
queryScrapeSceneURL,
useBulkSceneUpdate,
useListSceneScrapers,
mutateReloadScrapers,
queryScrapeSceneQueryFragment,
Expand All @@ -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";

Expand All @@ -61,7 +62,7 @@ const SceneQueryModal = lazyComponent(
);

interface IListOperationProps {
selected: GQL.SceneDataFragment[];
selected: GQL.SlimSceneDataFragment[];
onClose: (applied: boolean) => void;
}

Expand Down Expand Up @@ -118,6 +119,7 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
const [studioId, setStudioId] = useState<string>();
const [performerMode, setPerformerMode] =
React.useState<GQL.BulkUpdateIdMode>(GQL.BulkUpdateIdMode.Add);
const [performers, setPerformers] = useState<Performer[]>([]);
const [performerIds, setPerformerIds] = useState<string[]>();
const [existingPerformerIds, setExistingPerformerIds] = useState<string[]>();
const [tagMode, setTagMode] = React.useState<GQL.BulkUpdateIdMode>(
Expand Down Expand Up @@ -209,6 +211,25 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
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 {
Expand Down Expand Up @@ -340,6 +361,7 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
return (
<SceneScrapeDialog
scene={currentScene}
scenePerformers={performers}
scraped={scrapedScene}
endpoint={endpoint}
onClose={(s) => onScrapeDialogClosed(s)}
Expand Down Expand Up @@ -544,8 +566,8 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (

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 {
Expand All @@ -558,8 +580,8 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
);

if (!found) {
setStashIds((stashIds) => [
...stashIds,
setStashIds((prevStashIds) => [
...prevStashIds,
{ endpoint, stash_id: updatedScene.remote_site_id },
]);
}
Expand Down Expand Up @@ -687,7 +709,7 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
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;
Expand Down Expand Up @@ -800,7 +822,7 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
}

return null;
}, [coverImage]);
}, [props.selected, isSingleScene, coverImage]);

function onImageLoad(imageData: string) {
setCoverImage(imageData);
Expand Down Expand Up @@ -835,7 +857,7 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (

// 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",
Expand Down Expand Up @@ -942,13 +964,20 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
}
}

const variableMap: Record<updateVariableType, any> = {
const variableMap: Record<updateVariableType, string> = {
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({
Expand All @@ -964,24 +993,28 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
...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<HTMLInputElement>) => {
Expand All @@ -999,17 +1032,23 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
...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 (
<Form.Group controlId={field} as={Row}>
{FormUtils.renderLabel({
title,
title: label,
})}
<Col xs={9}>
<Form.Control
Expand Down
2 changes: 0 additions & 2 deletions ui/v2.5/src/components/Shared/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface IModal {
dialogClassName?: string;
footerButtons?: React.ReactNode;
leftFooterButtons?: React.ReactNode;
scrollable?: boolean;
}

const defaultOnHide = () => {};
Expand All @@ -42,7 +41,6 @@ export const ModalComponent: React.FC<IModal> = ({
dialogClassName,
footerButtons,
leftFooterButtons,
scrollable,
}) => (
<Modal
className="ModalComponent"
Expand Down

0 comments on commit 40c017f

Please sign in to comment.