From add6bfb1b3aace64aff81a39ad161ca9f6438ca8 Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 26 Aug 2025 17:44:31 -0600 Subject: [PATCH] Disabling search temporarily when suggestions are fetched to prevent accidental clicks. --- app/src/components/Search.js | 27 +++++++++++++++++++++++++++ requirements.txt | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/components/Search.js b/app/src/components/Search.js index 0281c08b..59e9fb10 100644 --- a/app/src/components/Search.js +++ b/app/src/components/Search.js @@ -208,6 +208,10 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag) // The results summarized. const [suggestionsSums, setSuggestionsSums] = useState({}); + // Disable selecting a result briefly after new suggestions arrive. + const [selectDisabled, setSelectDisabled] = React.useState(false); + const selectDisableTimerRef = React.useRef(null); + const noResults = [{title: 'No results'}]; const normalizeSuggestionsResults = (newSuggestions) => { @@ -303,17 +307,40 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag) }); } + const suggestionSelectDelay = 250; + React.useEffect(() => { setSuggestionsSums({}); setSuggestionsResults({}); if (!_.isEmpty(suggestions)) { + // Start a brief window where selecting results is disabled to prevent accidental clicks + // when the dropdown re-renders with new suggestions. + if (selectDisableTimerRef.current) { + clearTimeout(selectDisableTimerRef.current); + } + setSelectDisabled(true); + selectDisableTimerRef.current = setTimeout(() => setSelectDisabled(false), suggestionSelectDelay); + normalizeSuggestionsResults(suggestions); } }, [JSON.stringify(suggestions)]); + // Clear timer on unmount. + React.useEffect(() => { + return () => { + if (selectDisableTimerRef.current) { + clearTimeout(selectDisableTimerRef.current); + } + }; + }, []); + // User clicked on a result in the dropdown. const handleResultSelect = ({result}) => { + if (selectDisabled) { + console.debug('Selection temporarily disabled after suggestions update'); + return; + } if (result.location) { console.info(`useSearchSuggestions Navigating: ${result.location}`) navigate(result.location); diff --git a/requirements.txt b/requirements.txt index 7e0b50de..ef1df973 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,4 +29,4 @@ tqdm==4.67.1 vininfo[cli]==1.8.0 websockets==13.1 webvtt-py==0.5.1 -yt-dlp==2025.8.11 +yt-dlp==2025.8.22