Fix scraped tags issues (#5522)

* Fix display of matched scraped tags
* Fix create new scraped tag not updating field correctly
This commit is contained in:
WithoutPants
2024-12-03 08:02:29 +11:00
committed by GitHub
parent 60bb6bf50b
commit 4be793d4b3

View File

@@ -44,10 +44,15 @@ export function useTagsEdit(
} }
// add the new tag to the new tags value // add the new tag to the new tags value
const newTagIds = tags onSetTags(
.map((t) => t.id) tags.concat([
.concat([result.data.tagCreate.id]); {
setFieldValue(newTagIds); id: result.data.tagCreate.id,
name: toCreate.name ?? "",
aliases: [],
},
])
);
// remove the tag from the list // remove the tag from the list
const newTagsClone = newTags!.concat(); const newTagsClone = newTags!.concat();
@@ -73,20 +78,26 @@ export function useTagsEdit(
function updateTagsStateFromScraper( function updateTagsStateFromScraper(
scrapedTags?: Pick<GQL.ScrapedTag, "name" | "stored_id">[] scrapedTags?: Pick<GQL.ScrapedTag, "name" | "stored_id">[]
) { ) {
if (scrapedTags) { if (!scrapedTags) {
// map tags to their ids and filter out those not found return;
onSetTags(
scrapedTags.map((p) => {
return {
id: p.stored_id!,
name: p.name ?? "",
aliases: [],
};
})
);
setNewTags(scrapedTags.filter((t) => !t.stored_id));
} }
// map tags to their ids and filter out those not found
const idTags = scrapedTags.filter(
(t) => t.stored_id !== undefined && t.stored_id !== null
);
const newNewTags = scrapedTags.filter((t) => !t.stored_id);
onSetTags(
idTags.map((p) => {
return {
id: p.stored_id!,
name: p.name ?? "",
aliases: [],
};
})
);
setNewTags(newNewTags);
} }
function renderNewTags() { function renderNewTags() {