Skip to content

Commit

Permalink
feat: add automatic error message clearing after 5 seconds in useCode…
Browse files Browse the repository at this point in the history
…Search hook
  • Loading branch information
HikaruEgashira committed Dec 30, 2024
1 parent e08bee8 commit f706fee
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/hooks/useCodeSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function useCodeSearch({
const requestIdRef = useRef<number>(0);
const filteredCountRef = useRef<number>(0);
const debounceTimerRef = useRef<ReturnType<typeof setTimeout>>();
const errorTimerRef = useRef<ReturnType<typeof setTimeout>>();
const lastSearchRef = useRef<string>('');

// キャッシュチェック関数
Expand Down Expand Up @@ -314,6 +315,24 @@ export function useCodeSearch({
};
}, []);

// エラーメッセージを5秒後に自動的にクリア
useEffect(() => {
if (error) {
if (errorTimerRef.current) {
clearTimeout(errorTimerRef.current);
}
errorTimerRef.current = setTimeout(() => {
setError(null);
}, 5000);

return () => {
if (errorTimerRef.current) {
clearTimeout(errorTimerRef.current);
}
};
}
}, [error]);

const isLastPage = useCallback(() => {
return !hasMore && results.length > 0 && currentQuery !== '';
}, [hasMore, results.length, currentQuery]);
Expand Down

0 comments on commit f706fee

Please sign in to comment.