This commit is contained in:
Damien Ostler 2024-06-02 22:58:53 -04:00
commit 172a3015af

View File

@ -58,11 +58,12 @@ const SearchInput = ({ tagsChanged, searchChanged, nsfwChanged, nsfwButtonEnable
getData(); getData();
}, []); }, []);
const [color, setColor] = useState('black'); const [color, setColor] = useState('black');
const selectRef = useRef(null);
const [currentTag, setCurrentTag] = useState<string>(''); const [currentTag, setCurrentTag] = useState<string>('');
useEffect(() => { useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => { const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'ArrowUp') { if (event.key === 'ArrowUp') {
const currentIndex = tags.findIndex(tag => tag.name === currentTag); const currentIndex = tags.findIndex(tag => tag.name === currentTag);
const newIndex = currentIndex === 0 ? tags.length - 1 : currentIndex - 1; const newIndex = currentIndex === 0 ? tags.length - 1 : currentIndex - 1;
@ -74,10 +75,12 @@ const SearchInput = ({ tagsChanged, searchChanged, nsfwChanged, nsfwButtonEnable
} }
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);
setSelectedTags([...selectedTags, tags[currentIndex].name]); if (currentIndex !== -1 && !selectedTags.includes(tags[currentIndex].name)) {
const tagsInput = selectedTagsInput; setSelectedTags([...selectedTags, tags[currentIndex].name]);
tagsInput.push({value: tags[currentIndex].name, label: tags[currentIndex].name}); const tagsInput = selectedTagsInput;
setSelectedTagsInput(tagsInput); tagsInput.push({ value: tags[currentIndex].name, label: tags[currentIndex].name });
setSelectedTagsInput(tagsInput);
}
} }
}; };