diff --git a/ui/v2.5/src/components/Tagger/performers/PerformerTagger.tsx b/ui/v2.5/src/components/Tagger/performers/PerformerTagger.tsx index 40e33ec02fa..6270d7f05bf 100755 --- a/ui/v2.5/src/components/Tagger/performers/PerformerTagger.tsx +++ b/ui/v2.5/src/components/Tagger/performers/PerformerTagger.tsx @@ -25,6 +25,7 @@ import { LOCAL_FORAGE_KEY, ITaggerConfig, initialConfig } from "../constants"; import PerformerModal from "../PerformerModal"; import { useUpdatePerformer } from "../queries"; import { faStar, faTags } from "@fortawesome/free-solid-svg-icons"; +import { mergeStashIDs } from "src/utils/stashbox"; type JobFragment = Pick< GQL.Job, @@ -367,10 +368,18 @@ const PerformerTaggerList: React.FC = ({ }); } - const handlePerformerUpdate = async (input: GQL.PerformerCreateInput) => { + const handlePerformerUpdate = async ( + existing: GQL.PerformerDataFragment, + input: GQL.PerformerCreateInput + ) => { setModalPerformer(undefined); const performerID = modalPerformer?.stored_id; if (performerID) { + // handle stash ids - we want to add, not set them + if (input.stash_ids?.length) { + input.stash_ids = mergeStashIDs(existing.stash_ids, input.stash_ids); + } + const updateData: GQL.PerformerUpdateInput = { ...input, id: performerID, @@ -540,7 +549,9 @@ const PerformerTaggerList: React.FC = ({ closeModal={() => setModalPerformer(undefined)} modalVisible={modalPerformer.stored_id === performer.id} performer={modalPerformer} - onSave={handlePerformerUpdate} + onSave={(input) => { + handlePerformerUpdate(performer, input); + }} excludedPerformerFields={config.excludedPerformerFields} icon={faTags} header={intl.formatMessage({ diff --git a/ui/v2.5/src/components/Tagger/performers/StashSearchResult.tsx b/ui/v2.5/src/components/Tagger/performers/StashSearchResult.tsx index 563a92eda4c..e30ca182a58 100755 --- a/ui/v2.5/src/components/Tagger/performers/StashSearchResult.tsx +++ b/ui/v2.5/src/components/Tagger/performers/StashSearchResult.tsx @@ -5,6 +5,7 @@ import * as GQL from "src/core/generated-graphql"; import { useUpdatePerformer } from "../queries"; import PerformerModal from "../PerformerModal"; import { faTags } from "@fortawesome/free-solid-svg-icons"; +import { mergeStashIDs } from "src/utils/stashbox"; interface IStashSearchResultProps { performer: GQL.SlimPerformerDataFragment; @@ -38,6 +39,10 @@ const StashSearchResult: React.FC = ({ setSaveState("Saving performer"); setModalPerformer(undefined); + if (input.stash_ids?.length) { + input.stash_ids = mergeStashIDs(performer.stash_ids, input.stash_ids); + } + const updateData: GQL.PerformerUpdateInput = { ...input, id: performer.id, diff --git a/ui/v2.5/src/utils/stashbox.ts b/ui/v2.5/src/utils/stashbox.ts index d641da7b8ea..f2483bc4214 100644 --- a/ui/v2.5/src/utils/stashbox.ts +++ b/ui/v2.5/src/utils/stashbox.ts @@ -1,6 +1,16 @@ +import { StashIdInput } from "src/core/generated-graphql"; + export function stashboxDisplayName(name: string, index: number) { return name || `Stash-Box #${index + 1}`; } export const getStashboxBase = (endpoint: string) => endpoint.match(/(https?:\/\/.*?\/)graphql/)?.[1]; + +// mergeStashIDs merges the src stash ID into the dest stash IDs. +// If the src stash ID is already in dest, the src stash ID overwrites the dest stash ID. +export function mergeStashIDs(dest: StashIdInput[], src: StashIdInput[]) { + return dest + .filter((i) => !src.find((j) => i.endpoint === j.endpoint)) + .concat(src); +}