From eafd1e382f92d5e6a21cbfa29ea4bdbe678e5c35 Mon Sep 17 00:00:00 2001 From: Ogheneyoma Date: Thu, 12 Sep 2024 16:56:26 +0100 Subject: [PATCH 1/2] fix(ui): added component for users to contribute missing search terms --- src/components/islands/search.jsx | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/components/islands/search.jsx b/src/components/islands/search.jsx index 52e6c98..cc05fcd 100644 --- a/src/components/islands/search.jsx +++ b/src/components/islands/search.jsx @@ -227,7 +227,8 @@ function SearchResult({ result = [], cursor, searchTerm }) { /** * @todo add message suggesting adding/contributing the word to dictionary */ -

No Result found

+ //

No Result found

+ ) : ( result.map(({ doc }, i) => ( ); +} + +function SearchSuggestionContribution({ searchTerm }){ + return ( +
+
+
+

+ No Result found for{" "} + {searchTerm} +

+

+ Help add the word {searchTerm}{" "} + to jargon.dev. +

+
+
+ Start Now + + + + +
+
+ ); } \ No newline at end of file From 8c9ce54dc153ca1586bb05a0c02770b90006326c Mon Sep 17 00:00:00 2001 From: babblebey Date: Sat, 14 Sep 2024 12:30:00 +0100 Subject: [PATCH 2/2] feat: add `useDebounce` hook --- src/lib/hooks/use-debounce.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/lib/hooks/use-debounce.js diff --git a/src/lib/hooks/use-debounce.js b/src/lib/hooks/use-debounce.js new file mode 100644 index 0000000..e8a7c40 --- /dev/null +++ b/src/lib/hooks/use-debounce.js @@ -0,0 +1,23 @@ +import { useState, useEffect } from 'react'; + +/** + * Hook that delays invoking an operation until after wait milliseconds + * @param {any} value + * @param {number} delay + * @returns {any} + */ +export default function useDebounce(value, delay) { + const [debouncedValue, setDebouncedValue] = useState(value); + + useEffect(() => { + const handler = setTimeout(() => { + setDebouncedValue(value); + }, delay); + + return () => { + clearTimeout(handler); + }; + }, [value, delay]); + + return debouncedValue; +} \ No newline at end of file