Skip to content

Commit

Permalink
Fix scraped tags issues (#5522)
Browse files Browse the repository at this point in the history
* Fix display of matched scraped tags
* Fix create new scraped tag not updating field correctly
  • Loading branch information
WithoutPants authored Dec 2, 2024
1 parent 60bb6bf commit 4be793d
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions ui/v2.5/src/hooks/tagsEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ export function useTagsEdit(
}

// add the new tag to the new tags value
const newTagIds = tags
.map((t) => t.id)
.concat([result.data.tagCreate.id]);
setFieldValue(newTagIds);
onSetTags(
tags.concat([
{
id: result.data.tagCreate.id,
name: toCreate.name ?? "",
aliases: [],
},
])
);

// remove the tag from the list
const newTagsClone = newTags!.concat();
Expand All @@ -73,20 +78,26 @@ export function useTagsEdit(
function updateTagsStateFromScraper(
scrapedTags?: Pick<GQL.ScrapedTag, "name" | "stored_id">[]
) {
if (scrapedTags) {
// map tags to their ids and filter out those not found
onSetTags(
scrapedTags.map((p) => {
return {
id: p.stored_id!,
name: p.name ?? "",
aliases: [],
};
})
);

setNewTags(scrapedTags.filter((t) => !t.stored_id));
if (!scrapedTags) {
return;
}

// 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() {
Expand Down

0 comments on commit 4be793d

Please sign in to comment.