From ee9f9ffd1914a35e6fc66a2bd51b2c8ada73a275 Mon Sep 17 00:00:00 2001 From: Pierre-Henry Soria Date: Fri, 3 May 2024 18:39:03 +1000 Subject: [PATCH] Add pages --- client/components/SearchForm.tsx | 2 +- client/pages/search/SearchPage.tsx | 80 ++++++++++++++++++++++++++ client/pages/static/ComparisonPage.tsx | 10 ++++ client/utils/debounce.ts | 16 ++++++ 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 client/pages/search/SearchPage.tsx create mode 100644 client/pages/static/ComparisonPage.tsx create mode 100644 client/utils/debounce.ts diff --git a/client/components/SearchForm.tsx b/client/components/SearchForm.tsx index 36a9972..436fcba 100644 --- a/client/components/SearchForm.tsx +++ b/client/components/SearchForm.tsx @@ -36,7 +36,7 @@ const startSearching = useCallback((queryToEncode: string) => { } else if (!userQueryIsBlank && !suggestedQueryIsBlank) { setSuggestedQuery(""); } - + // Start searching immediately when user types if (!userQueryIsBlank) { debouncedStartSearching(userQuery); diff --git a/client/pages/search/SearchPage.tsx b/client/pages/search/SearchPage.tsx new file mode 100644 index 0000000..fedb3cc --- /dev/null +++ b/client/pages/search/SearchPage.tsx @@ -0,0 +1,80 @@ +import { usePubSub } from "create-pubsub/react"; +import { + promptPubSub, + responsePubSub, + searchResultsPubSub, + urlsDescriptionsPubSub, +} from "../../modules/pubSub"; +import { SearchForm } from "../../components/SearchForm"; +import { Toaster } from "react-hot-toast"; +import { SettingsButton } from "../../components/SettingsButton"; +import Markdown from "markdown-to-jsx"; +import { getDisableAiResponseSetting } from "../../modules/pubSub"; +import { SearchResultsList } from "../../components/SearchResultsList"; +import { useEffect } from "react"; +import { prepareTextGeneration } from "../../modules/textGeneration"; +import { useLocation } from 'react-router-dom'; + +export const SearchPage = () => { + const [query, setQuery] = usePubSub(promptPubSub); + const [response] = usePubSub(responsePubSub); + const [searchResults] = usePubSub(searchResultsPubSub); + const [urlsDescriptions] = usePubSub(urlsDescriptionsPubSub); + + useEffect(() => { + prepareTextGeneration(); + }, []); + + const location = useLocation(); + + useEffect(() => { + const params = new URLSearchParams(location.search); + const newQuery = params.get('q'); + if (newQuery !== null) { + setQuery(newQuery); + } + }, [location.search, setQuery]); + + + return ( + <> + + {!getDisableAiResponseSetting() && response.length > 0 && ( +
+

AI's thoughts:

+
+ {response} +
+
+ )} + {searchResults.length > 0 && ( +
+ +
+ )} +
+ +
+ + + ); +}; diff --git a/client/pages/static/ComparisonPage.tsx b/client/pages/static/ComparisonPage.tsx new file mode 100644 index 0000000..44c9665 --- /dev/null +++ b/client/pages/static/ComparisonPage.tsx @@ -0,0 +1,10 @@ +import React from 'react'; + +export const ComparisonPage = () => { + return ( +
+

Comparison Page

+ {/* Add your comparison logic here */} +
+ ); +}; diff --git a/client/utils/debounce.ts b/client/utils/debounce.ts new file mode 100644 index 0000000..788ac57 --- /dev/null +++ b/client/utils/debounce.ts @@ -0,0 +1,16 @@ +export const debounce = void>( + func: T, + wait: number, +): ((...args: Parameters) => void) => { + let timeout: NodeJS.Timeout; + + return (...args: Parameters): void => { + const later = () => { + clearTimeout(timeout); + func(...args); + }; + + clearTimeout(timeout); + timeout = setTimeout(later, wait); + }; +};