Wire up Tagger set tags checkbox (#889)

This commit is contained in:
InfiniteTF 2020-10-24 10:19:45 +02:00 committed by GitHub
parent 3346f8dcca
commit 77da544e98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 23 deletions

View file

@ -59,6 +59,7 @@ interface IStashSearchResultProps {
setScene: (scene: GQL.SlimSceneDataFragment) => void;
setCoverImage: boolean;
tagOperation: string;
setTags: boolean;
endpoint: string;
queueFingerprintSubmission: (sceneId: string, endpoint: string) => void;
}
@ -72,6 +73,7 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
setScene,
setCoverImage,
tagOperation,
setTags,
endpoint,
queueFingerprintSubmission,
}) => {
@ -234,29 +236,33 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
}
}
const tagIDs: string[] =
tagOperation === "merge"
? stashScene?.tags?.map((t) => t.id) ?? []
: [];
const tags = scene.tags ?? [];
if (tags.length > 0) {
const tagDict: Record<string, string> = (allTags?.allTagsSlim ?? [])
.filter((t) => t.name)
.reduce((dict, t) => ({ ...dict, [t.name.toLowerCase()]: t.id }), {});
const newTags: string[] = [];
tags.forEach((tag) => {
if (tagDict[tag.name.toLowerCase()])
tagIDs.push(tagDict[tag.name.toLowerCase()]);
else newTags.push(tag.name);
});
let updatedTags = stashScene?.tags?.map((t) => t.id) ?? [];
if (setTags) {
const newTagIDs = tagOperation === "merge" ? updatedTags : [];
const tags = scene.tags ?? [];
if (tags.length > 0) {
const tagDict: Record<string, string> = (allTags?.allTagsSlim ?? [])
.filter((t) => t.name)
.reduce(
(dict, t) => ({ ...dict, [t.name.toLowerCase()]: t.id }),
{}
);
const newTags: string[] = [];
tags.forEach((tag) => {
if (tagDict[tag.name.toLowerCase()])
newTagIDs.push(tagDict[tag.name.toLowerCase()]);
else newTags.push(tag.name);
});
const createdTags = await Promise.all(
newTags.map((tag) => createTag(tag))
);
createdTags.forEach((createdTag) => {
if (createdTag?.data?.tagCreate?.id)
tagIDs.push(createdTag.data.tagCreate.id);
});
const createdTags = await Promise.all(
newTags.map((tag) => createTag(tag))
);
createdTags.forEach((createdTag) => {
if (createdTag?.data?.tagCreate?.id)
newTagIDs.push(createdTag.data.tagCreate.id);
});
}
updatedTags = uniq(newTagIDs);
}
const sceneUpdateResult = await updateScene({
@ -269,7 +275,7 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
studio_id: studioID,
cover_image: imgData,
url: scene.url,
...(tagIDs ? { tag_ids: uniq(tagIDs) } : {}),
tag_ids: updatedTags,
stash_ids: [
...(stashScene?.stash_ids ?? []),
{

View file

@ -260,6 +260,7 @@ const TaggerList: React.FC<ITaggerListProps> = ({
setScene={handleTaggedScene}
scene={fingerprintMatch}
setCoverImage={config.setCoverImage}
setTags={config.setTags}
tagOperation={config.tagOperation}
endpoint={selectedEndpoint.endpoint}
queueFingerprintSubmission={queueFingerprintSubmission}
@ -285,6 +286,7 @@ const TaggerList: React.FC<ITaggerListProps> = ({
}
setCoverImage={config.setCoverImage}
tagOperation={config.tagOperation}
setTags={config.setTags}
setScene={handleTaggedScene}
endpoint={selectedEndpoint.endpoint}
queueFingerprintSubmission={queueFingerprintSubmission}