-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
partially completed search bar atoms, changing comp
- Loading branch information
1 parent
dd5bc58
commit 584efbb
Showing
1 changed file
with
47 additions
and
13 deletions.
There are no files selected for viewing
60 changes: 47 additions & 13 deletions
60
packages/react/src/components/header/searchbar/SearchBarAtoms.tsx
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,24 +1,58 @@ | ||
import { atom } from "jotai"; | ||
import { QueryItem, SearchableCategory } from "./types"; | ||
import { atomWithReset } from "jotai/utils"; | ||
import { atomWithDefault, atomWithReset, splitAtom } from "jotai/utils"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useState } from "react"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
const searchAutocompleteOptions = atomWithReset({ | ||
vtuber: [], | ||
topic: [], | ||
org: [], | ||
has_song: [], | ||
type: [], | ||
lang: [], | ||
from: [], | ||
to: [], | ||
search: [], | ||
description: [], | ||
} as Record<SearchableCategory, QueryItem[]>); | ||
// const searchAutocompleteOptions = atomWithReset({ | ||
// vtuber: [], | ||
// topic: [], | ||
// org: [], | ||
// has_song: [], | ||
// type: [], | ||
// lang: [], | ||
// from: [], | ||
// to: [], | ||
// search: [], | ||
// description: [], | ||
// } as Record<SearchableCategory, QueryItem[]>); | ||
|
||
const queryAtom = atom([] as QueryItem[]); | ||
const splitQueryAtom = splitAtom(queryAtom); | ||
|
||
// const query = atomWithReset([] as QueryItem[]); | ||
|
||
// const useAutocomplete(query: string) { | ||
// const { t } = useTranslation(); | ||
|
||
// } | ||
|
||
function useServerAutocomplete(search: string) { | ||
const out = useQuery({ | ||
queryKey: ["autocomplete", search], | ||
queryFn: async ( | ||
ctx, | ||
): Promise<Record<"vtuber" | "topic" | "org", QueryItem[]>> => { | ||
return { | ||
vtuber: [], | ||
topic: [], | ||
org: [], | ||
}; | ||
}, | ||
}); | ||
} | ||
|
||
export function useAutocomplete() { | ||
// query: (what's in the search bar) | ||
// search: (the content typed into the input bar) | ||
const [search, updateSearch] = useState(""); | ||
// inverted_lang_index: useMemo(, [t, constants]) | ||
|
||
// server_autocomplete: (async response fetched from serverside autocomplete depending on search) | ||
// client_autocomplete: (sync response from client autocomplete depending on search and inverted_lang_index) | ||
|
||
// autocomplete_items: (merged autocomplete options, but grouped by category, also depending on query to remove selected items from dropdown) | ||
|
||
return { search, updateSearch }; | ||
} |