From fdcaccfbd6263f7640b0250ef6000172e2f0577a Mon Sep 17 00:00:00 2001 From: Damien Ostler Date: Sun, 2 Jun 2024 22:57:20 -0400 Subject: [PATCH] 23 replace recenter with back (#37) * fix:23 * fix * fix: girl bg * Update search_input.tsx * Update search_input.tsx --- components/neroshitron/search_input.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/components/neroshitron/search_input.tsx b/components/neroshitron/search_input.tsx index 69247b3..128ce0a 100644 --- a/components/neroshitron/search_input.tsx +++ b/components/neroshitron/search_input.tsx @@ -58,11 +58,12 @@ const SearchInput = ({ tagsChanged, searchChanged, nsfwChanged, nsfwButtonEnable getData(); }, []); const [color, setColor] = useState('black'); - + const selectRef = useRef(null); const [currentTag, setCurrentTag] = useState(''); useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'ArrowUp') { const currentIndex = tags.findIndex(tag => tag.name === currentTag); const newIndex = currentIndex === 0 ? tags.length - 1 : currentIndex - 1; @@ -74,10 +75,12 @@ const SearchInput = ({ tagsChanged, searchChanged, nsfwChanged, nsfwButtonEnable } else if(event.key === 'Enter'){ const currentIndex = tags.findIndex(tag => tag.name === currentTag); - setSelectedTags([...selectedTags, tags[currentIndex].name]); - const tagsInput = selectedTagsInput; - tagsInput.push({value: tags[currentIndex].name, label: tags[currentIndex].name}); - setSelectedTagsInput(tagsInput); + if (currentIndex !== -1 && !selectedTags.includes(tags[currentIndex].name)) { + setSelectedTags([...selectedTags, tags[currentIndex].name]); + const tagsInput = selectedTagsInput; + tagsInput.push({ value: tags[currentIndex].name, label: tags[currentIndex].name }); + setSelectedTagsInput(tagsInput); + } } };