fix: adding duplicates

This commit is contained in:
Damien Ostler 2024-06-03 21:37:05 -04:00
parent e9e4f25520
commit fd76220269

View File

@ -73,14 +73,14 @@ const SearchInput = ({ tagsChanged, searchChanged, nsfwChanged, nsfwButtonEnable
const currentIndex = tags.findIndex(tag => tag.name === currentTag); const currentIndex = tags.findIndex(tag => tag.name === currentTag);
const newIndex = currentIndex === tags.length - 1 ? 0 : currentIndex + 1; const newIndex = currentIndex === tags.length - 1 ? 0 : currentIndex + 1;
setCurrentTag(tags[newIndex].name); setCurrentTag(tags[newIndex].name);
} } else if (event.key === 'Enter') {
else if(event.key === 'Enter'){
const currentIndex = tags.findIndex(tag => tag.name === currentTag); const currentIndex = tags.findIndex(tag => tag.name === currentTag);
if (currentIndex !== -1 && !selectedTags.includes(tags[currentIndex].name)) { if (currentIndex !== -1 && !selectedTags.includes(tags[currentIndex].name)) {
setSelectedTags([...selectedTags, tags[currentIndex].name]); setSelectedTags([...selectedTags, tags[currentIndex].name]);
const tagsInput = selectedTagsInput; const tagsInput = selectedTagsInput;
tagsInput.push({ value: tags[currentIndex].name, label: tags[currentIndex].name }); tagsInput.push({ value: tags[currentIndex].name, label: tags[currentIndex].name });
setSelectedTagsInput(tagsInput); setSelectedTagsInput(tagsInput);
setCurrentTag('');
} }
} }
}; };
@ -130,6 +130,13 @@ const SearchInput = ({ tagsChanged, searchChanged, nsfwChanged, nsfwButtonEnable
setSelectedTags([value.value]); setSelectedTags([value.value]);
setSelectedTagsInput([value]) setSelectedTagsInput([value])
} }
if (Array.isArray(value)) {
setSelectedTags(value.map((option) => option.value));
setSelectedTagsInput(value.filter((option) => option.value !== 'placeholder'));
} else if (value) {
setSelectedTags([value.value]);
setSelectedTagsInput([value]);
}
}} }}
onSearchInputChange={(value) => { onSearchInputChange={(value) => {