From 31a701a2956fba58331968878de064ff02d46941 Mon Sep 17 00:00:00 2001 From: mjkeaton Date: Tue, 7 Jan 2025 13:08:35 +0100 Subject: [PATCH] chore(Search): externalize HomeSearch component --- src/pages/home/HomeSearch.tsx | 119 ++++++++++++++++++++++++++++++ src/pages/home/index.tsx | 132 ++++++---------------------------- 2 files changed, 139 insertions(+), 112 deletions(-) create mode 100644 src/pages/home/HomeSearch.tsx diff --git a/src/pages/home/HomeSearch.tsx b/src/pages/home/HomeSearch.tsx new file mode 100644 index 0000000..4978a8f --- /dev/null +++ b/src/pages/home/HomeSearch.tsx @@ -0,0 +1,119 @@ +import { FormattedMessage, } from "react-intl"; + +import Icon from "../contacts/components/Icon"; +import { type Contact, ContactTypes } from "@/types/contact"; +import { randomAvatar } from "@/utils/dev"; +import { SearchIcon } from "lucide-react"; +import { Skeleton } from "@/components/ui/skeleton"; + + +type RecentContactItemProps = Pick; + +function RecentContactItem({ name, type, avatar }: RecentContactItemProps) { + return ( +
+ +
{name}
+
+ ); +} + +function RecentContacts({ values }: { values: RecentContactItemProps[] }) { + return ( +
+
+ +
+
+ {values.map((value, index) => ( + + ))} +
+
+ ); +} + +function SearchSuggestions() { + return ( +
+
+ +
+
+
+ + +
+
+ + +
+
+ + Something here +
+
+
+ ); +} + +function SearchResults() { + return ( +
+
+ +
+
+
+
+ ); +} + +function Loader() { + return ( +
+ {Array.from({ length: 3 }, (_, index) => ( + + ))} +
+ ); +} + +const __dev__RECENT_CONTACTS = [ + { name: "Matt Preziegka", type: ContactTypes.Person, avatar: randomAvatar("men") }, + { name: "Jurica Kolectic", type: ContactTypes.Person, avatar: randomAvatar("men") }, + { name: "Testla Inc", type: ContactTypes.Company }, + { name: "Mia Flores", type: ContactTypes.Person, avatar: randomAvatar("women") }, +]; + +export default function HomeSearch({ isPending }: { isPending: boolean }) { + + return ( +
+ + + + {isPending && } +
+ ); +} diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 8697639..35cba1f 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -1,121 +1,32 @@ -import { FormattedMessage, useIntl } from "react-intl"; -import Topbar from "@/components/Topbar"; -import Search from "@/components/ui/search"; -import { Avatar, AvatarFallback } from "@/components/ui/avatar"; +import { useState } from "react"; +import { useIntl } from "react-intl"; +import { ChevronLeftIcon } from "lucide-react"; -import Balances from "./components/Balances"; -import Bills from "./components/Bills"; import { useQuery } from "@tanstack/react-query"; import { search } from "@/services/search"; -import { useState } from "react"; -import { cn } from "@/lib/utils"; -import SearchTypeFilter, { type SearchTypeFilterValue } from "./components/SearchTypeFilter"; +import { cn } from "@/lib/utils"; +import Topbar from "@/components/Topbar"; +import Search from "@/components/ui/search"; +import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; -import { ChevronLeftIcon, SearchIcon } from "lucide-react"; import { Separator } from "@/components/ui/separator"; -import Icon from "../contacts/components/Icon"; -import { type Contact, ContactTypes } from "@/types/contact"; -import { randomAvatar } from "@/utils/dev"; - - -type RecentContactItemProps = Pick; -function RecentContactItem({ name, type, avatar }: RecentContactItemProps) { - return ( -
- -
{name}
-
- ); -} - -function RecentContacts({ values }: { values: RecentContactItemProps[] }) { - return ( -
-
- -
-
- {values.map((value) => ( - - ))} -
-
- ); -} -function SearchSuggestions() { - return ( -
-
- -
-
-
- - -
-
- - -
-
- - Something here -
-
-
- ); -} - -function SearchResults() { - return ( -
-
- -
-
-
-
- ); -} - -const __dev__RECENT_CONTACTS = [ - { name: "Matt Preziegka", type: ContactTypes.Person, avatar: randomAvatar("men") }, - { name: "Jurica Kolectic", type: ContactTypes.Person, avatar: randomAvatar("men") }, - { name: "Testla Inc", type: ContactTypes.Company }, - { name: "Mia Flores", type: ContactTypes.Person, avatar: randomAvatar("women") }, -]; +import Balances from "./components/Balances"; +import Bills from "./components/Bills"; +import SearchTypeFilter, { type SearchTypeFilterValue } from "./components/SearchTypeFilter"; +import HomeSearch from "./HomeSearch"; export default function Home() { const intl = useIntl(); - const [typeFilters, setTypeFilters] = useState(["all"]); const [searchTerm, setSearchTerm] = useState(""); + const [typeFilters, setTypeFilters] = useState(["all"]); + const [searchModeEnabled, setSearchModeEnabled] = useState(searchTerm.length > 0); const { isPending, isSuccess, data } = useQuery({ - queryKey: ["search"], + queryKey: ["search", searchTerm, typeFilters], queryFn: () => search({ filter: { search_term: searchTerm, @@ -175,18 +86,15 @@ export default function Home() {
-
- - -
- - - -
-
+
+ + + +
+ ); }