-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AtomicSearch/feature/refactoring-add-react…
…-router-dom-and-instant-search Feature/refactoring add react router dom and instant search
- Loading branch information
Showing
7 changed files
with
187 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,24 @@ | ||
import { usePubSub } from "create-pubsub/react"; | ||
import { | ||
promptPubSub, | ||
responsePubSub, | ||
searchResultsPubSub, | ||
urlsDescriptionsPubSub, | ||
} from "../modules/pubSub"; | ||
import { SearchForm } from "./SearchForm"; | ||
import { Toaster } from "react-hot-toast"; | ||
import { SettingsButton } from "./SettingsButton"; | ||
import Markdown from "markdown-to-jsx"; | ||
import { getDisableAiResponseSetting } from "../modules/pubSub"; | ||
import { SearchResultsList } from "./SearchResultsList"; | ||
import { useEffect } from "react"; | ||
import { prepareTextGeneration } from "../modules/textGeneration"; | ||
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; | ||
|
||
export function App() { | ||
const [query, updateQuery] = usePubSub(promptPubSub); | ||
const [response] = usePubSub(responsePubSub); | ||
const [searchResults] = usePubSub(searchResultsPubSub); | ||
const [urlsDescriptions] = usePubSub(urlsDescriptionsPubSub); | ||
import { SearchPage } from "../pages/search/SearchPage"; | ||
import { ComparisonPage } from "../pages/static/ComparisonPage"; | ||
|
||
useEffect(() => { | ||
prepareTextGeneration(); | ||
}, []); | ||
function InnerApp() { | ||
|
||
return ( | ||
<> | ||
<SearchForm query={query} updateQuery={updateQuery} /> | ||
{!getDisableAiResponseSetting() && response.length > 0 && ( | ||
<div | ||
style={{ | ||
backgroundColor: "var(--background)", | ||
borderRadius: "6px", | ||
padding: "10px 25px", | ||
}} | ||
> | ||
<Markdown>{response}</Markdown> | ||
</div> | ||
)} | ||
{searchResults.length > 0 && ( | ||
<div> | ||
<SearchResultsList | ||
searchResults={searchResults} | ||
urlsDescriptions={urlsDescriptions} | ||
/> | ||
</div> | ||
)} | ||
<div | ||
style={ | ||
searchResults.length === 0 | ||
? { | ||
position: "fixed", | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
display: "flex", | ||
justifyContent: "center", | ||
} | ||
: { | ||
display: "flex", | ||
justifyContent: "center", | ||
} | ||
} | ||
> | ||
<SettingsButton /> | ||
</div> | ||
<Toaster /> | ||
<Routes> | ||
<Route path="/" element={<SearchPage />} /> | ||
<Route path="/comparison-google" element={<ComparisonPage />} /> | ||
</Routes> | ||
</> | ||
); | ||
} | ||
|
||
export const App = () => { | ||
return ( | ||
<Router> | ||
<InnerApp /> | ||
</Router> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<SearchForm query={query} updateQuery={setQuery} /> | ||
{!getDisableAiResponseSetting() && response.length > 0 && ( | ||
<div className="mt-4"> | ||
<h2 className="text-lg font-semibold">AI's thoughts:</h2> | ||
<div className="bg-gray-100 p-4 rounded-md mt-2"> | ||
<Markdown>{response}</Markdown> | ||
</div> | ||
</div> | ||
)} | ||
{searchResults.length > 0 && ( | ||
<div> | ||
<SearchResultsList | ||
searchResults={searchResults} | ||
urlsDescriptions={urlsDescriptions} | ||
/> | ||
</div> | ||
)} | ||
<div | ||
style={ | ||
searchResults.length === 0 | ||
? { | ||
position: "fixed", | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
display: "flex", | ||
justifyContent: "center", | ||
} | ||
: { | ||
display: "flex", | ||
justifyContent: "center", | ||
} | ||
} | ||
> | ||
<SettingsButton /> | ||
</div> | ||
<Toaster /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
|
||
export const ComparisonPage = () => { | ||
return ( | ||
<div> | ||
<h1>Comparison Page</h1> | ||
{/* Add your comparison logic here */} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const debounce = <T extends (...args: any[]) => void>( | ||
func: T, | ||
wait: number, | ||
): ((...args: Parameters<T>) => void) => { | ||
let timeout: NodeJS.Timeout; | ||
|
||
return (...args: Parameters<T>): void => { | ||
const later = () => { | ||
clearTimeout(timeout); | ||
func(...args); | ||
}; | ||
|
||
clearTimeout(timeout); | ||
timeout = setTimeout(later, wait); | ||
}; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters