Skip to content

Commit c9f2a22

Browse files
committed
feat: implement search bar state management using Jotai atom
1 parent 3de5f46 commit c9f2a22

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/components/Navbar/NavbarActions.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ import SocialLoginCard from "../SocialLoginCard";
1212
import AuthenticatedUserMenu from "./AuthenticatedUserMenu";
1313
import LanguageSwitcher from "./LanguageSwitcher";
1414
import Link from "next/link";
15+
import { useAtom } from "jotai";
16+
import { searchBarAtom } from "@/store/search-bar.atom";
1517

1618
const NavbarActions: React.FC = () => {
1719
const { _t } = useTranslation();
1820
const authSession = useSession();
21+
const [, setSearchOpen] = useAtom(searchBarAtom);
1922

2023
return (
2124
<div className="flex items-center gap-2">
22-
<Button variant="ghost" className="md:hidden">
25+
<Button
26+
variant="ghost"
27+
className="md:hidden"
28+
onClick={() => setSearchOpen(true)}
29+
>
2330
<SearchIcon size={18} />
2431
</Button>
2532
<LanguageSwitcher />

src/components/Navbar/SearchInput.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import {
1616
CommandItem,
1717
CommandList,
1818
} from "../ui/command";
19+
import { useAtom } from "jotai";
20+
import { searchBarAtom } from "@/store/search-bar.atom";
1921

2022
const SearchInput = () => {
2123
const { _t } = useTranslation();
2224
const router = useRouter();
2325
const index = meilisearchClient.index("articles");
2426

25-
const [open, setOpen] = React.useState(false);
27+
const [open, setOpen] = useAtom(searchBarAtom);
2628

2729
const debouncedSearch = useDebouncedCallback((query: string) => {
2830
mutation.mutate(query);

src/store/search-bar.atom.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { atom } from "jotai";
2+
3+
export const searchBarAtom = atom<boolean>(false);

0 commit comments

Comments
 (0)