-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search)!: Migrate to new Search UI powered by Meilisearch (#240)
* Implement new search UI * Move "no results" into its own component * re-lock dependencies * Refactor: Move search logic into reusable hooks * Refactor: clean up, combine useSearchIndex * Refactor: Separate QueryInput, add ability to clear results * Cleanup * Tweak UI * Cleanup: Remove unused types * Move searchParams out; lower debounce ms * UI: Make "Clear" button smaller * Remove OpenSearchModalButton from mobile nav * Revert "Remove OpenSearchModalButton from mobile nav" This reverts commit 035fc9a. * cleanup * Refactor to a generic response transformation method * Remove redundant `Array.from` * Remove baseUri from slug * fix: close modal on result click
- Loading branch information
Showing
16 changed files
with
473 additions
and
153 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
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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useDebouncedSearch } from "@/hooks/useDebouncedSearch"; | ||
import { Search } from "@/types"; | ||
import React from "react"; | ||
import tw from "twin.macro"; | ||
import NoResults from "./NoResults"; | ||
import QueryInput from "./QueryInput"; | ||
import Results from "./Results"; | ||
|
||
interface Props { | ||
closeModal: () => void; | ||
} | ||
|
||
const Modal: React.FC<Props> = ({ closeModal }) => { | ||
const searchParams = { | ||
limit: 10, | ||
attributesToHighlight: ["*"], | ||
highlightPreTag: "<span>", | ||
highlightPostTag: "</span>", | ||
}; | ||
const { clearResponse, query, setQuery, results } = useDebouncedSearch< | ||
Search.Document, | ||
Search.Result | ||
>( | ||
process.env.NEXT_PUBLIC_MEILISEARCH_HOST ?? "", | ||
process.env.NEXT_PUBLIC_MEILISEARCH_READ_API_KEY ?? "", | ||
process.env.NEXT_PUBLIC_MEILISEARCH_INDEX_NAME ?? "", | ||
searchParams, | ||
200, | ||
); | ||
|
||
return ( | ||
<div | ||
css={[tw`px-2 mt-12 mb-12`, `sm:px-4`, `md:px-0 md:mt-28 md:mb-28`]} | ||
onPointerDown={() => { | ||
closeModal(); | ||
}} | ||
> | ||
<div | ||
onPointerDown={e => e.stopPropagation()} | ||
css={[tw`bg-background border rounded-lg w-full md:w-1/2 mx-auto`]} | ||
> | ||
<div className="search-input"> | ||
<QueryInput | ||
clearResponse={clearResponse} | ||
query={query} | ||
setQuery={setQuery} | ||
/> | ||
</div> | ||
<div className="search-results"> | ||
{results && | ||
(Object.keys(results).length === 0 ? ( | ||
<NoResults /> | ||
) : ( | ||
<Results closeModal={closeModal} results={results} /> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Modal; |
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,43 @@ | ||
import { DiscordIcon } from "@/components/Icons"; | ||
import { Link } from "@/components/Link"; | ||
import React from "react"; | ||
import { HelpCircle, Mail } from "react-feather"; | ||
import tw, { styled } from "twin.macro"; | ||
|
||
const ContactButton = styled(Link)` | ||
${[ | ||
tw`flex flex-row items-center gap-2 p-2`, | ||
tw`border border-solid rounded-lg`, | ||
tw`hover:bg-pink-100`, | ||
tw`[&>svg]:w-8`, | ||
tw`[&>svg]:h-8`, | ||
]} | ||
`; | ||
|
||
const NoResults: React.FC = () => { | ||
return ( | ||
<div css={[tw`flex flex-col items-center justify-center mb-4`]}> | ||
<HelpCircle size={64} css={tw`mt-8 mb-4`} /> | ||
<div css={tw`flex flex-col items-center justify-center p-4`}> | ||
<p css={tw`font-bold mb-4 text-center`}> | ||
We couldn't find what you're searching for. | ||
</p> | ||
<div> | ||
<p css={tw`mb-4 text-center`}>Reach out to us if you need help:</p> | ||
<div css={tw`flex flex-row gap-4 items-center justify-center`}> | ||
<ContactButton href="https://discord.gg/railway"> | ||
<DiscordIcon /> | ||
Discord | ||
</ContactButton> | ||
<ContactButton href="mailto:[email protected]"> | ||
<Mail /> | ||
</ContactButton> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NoResults; |
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,28 @@ | ||
import { searchStore } from "@/store"; | ||
import React from "react"; | ||
import { Search as SearchIcon } from "react-feather"; | ||
import tw from "twin.macro"; | ||
|
||
const OpenModalButton: React.FC = () => { | ||
return ( | ||
<> | ||
<button | ||
onClick={() => searchStore.set(true)} | ||
css={[ | ||
tw`flex items-center justify-between space-x-4 w-full`, | ||
tw`rounded border border-gray-200 cursor-pointer`, | ||
tw`px-2 py-2 md:py-1 text-gray-300 text-left`, | ||
tw`focus:outline-none md:hover:border-pink-300`, | ||
]} | ||
> | ||
<div tw="flex items-center space-x-2"> | ||
<SearchIcon tw="w-4 h-4" /> | ||
<span tw="text-sm">Search</span> | ||
</div> | ||
<div tw="text-gray-300 text-sm hidden md:block">⌘K</div> | ||
</button> | ||
</> | ||
); | ||
}; | ||
|
||
export default OpenModalButton; |
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,47 @@ | ||
import React from "react"; | ||
import { Search as SearchIcon } from "react-feather"; | ||
import tw from "twin.macro"; | ||
|
||
interface Props { | ||
clearResponse: () => void; | ||
query: string; | ||
setQuery: (q: string) => void; | ||
} | ||
|
||
const QueryInput: React.FC<Props> = ({ clearResponse, query, setQuery }) => { | ||
return ( | ||
<div css={tw`flex flex-col`}> | ||
<form css={tw`flex flex-row`}> | ||
<span css={tw`flex items-center px-3`}> | ||
<SearchIcon /> | ||
</span> | ||
<input | ||
autoFocus | ||
css={tw`w-full focus:outline-none bg-transparent`} | ||
type="text" | ||
placeholder="Search" | ||
value={query} | ||
onChange={e => setQuery(e.target.value)} | ||
/> | ||
<span css={tw`flex items-center p-2`}> | ||
<button | ||
css={[ | ||
tw`flex items-center justify-center w-14 h-8`, | ||
tw`rounded border border-solid rounded-lg`, | ||
tw`text-black text-sm dark:text-white`, | ||
tw`hover:bg-pink-100`, | ||
]} | ||
onClick={e => { | ||
e.preventDefault(); | ||
clearResponse(); | ||
}} | ||
> | ||
Clear | ||
</button> | ||
</span> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default QueryInput; |
Oops, something went wrong.