-
Notifications
You must be signed in to change notification settings - Fork 115
Add search bar to home screen #1775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,12 @@ import { | |
| DailyUserActivitiesResponseGroupedBy, | ||
| DashboardElementLot, | ||
| GraphqlSortOrder, | ||
| MediaLot, | ||
| MediaSortBy, | ||
| MinimalUserAnalyticsDocument, | ||
| TrendingMetadataDocument, | ||
| UserMetadataListDocument, | ||
| type UserMetadataListInput, | ||
| UserMetadataRecommendationsDocument, | ||
| type UserUpcomingCalendarEventInput, | ||
| UserUpcomingCalendarEventsDocument, | ||
|
|
@@ -31,7 +35,7 @@ import { | |
| } from "@tabler/icons-react"; | ||
| import { skipToken, useQuery } from "@tanstack/react-query"; | ||
| import CryptoJS from "crypto-js"; | ||
| import { type ReactNode, useMemo } from "react"; | ||
| import { type ReactNode, useMemo, useState } from "react"; | ||
| import { redirect } from "react-router"; | ||
| import { ClientOnly } from "remix-utils/client-only"; | ||
| import { match } from "ts-pattern"; | ||
|
|
@@ -43,6 +47,7 @@ import { | |
| SkeletonLoader, | ||
| } from "~/components/common"; | ||
| import { ApplicationGrid } from "~/components/common/layout"; | ||
| import { DebouncedSearchInput } from "~/components/common/filters"; | ||
| import { DisplaySummarySection } from "~/components/common/summary"; | ||
| import { MetadataDisplayItem } from "~/components/media/display-items"; | ||
| import { dayjsLib } from "~/lib/shared/date-utils"; | ||
|
|
@@ -86,6 +91,10 @@ export default function Page() { | |
| const userDetails = useUserDetails(); | ||
| const userCollections = useUserCollections(); | ||
| const userPreferences = useUserPreferences(); | ||
| const [dashboardSearchLot, setDashboardSearchLot] = useState<MediaLot | "ALL">( | ||
| "ALL", | ||
| ); | ||
| const [dashboardSearchQuery, setDashboardSearchQuery] = useState(""); | ||
|
Comment on lines
+94
to
+97
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | 💤 Low value Order the new hooks by ascending line length.
♻️ Proposed fix+ const [dashboardSearchQuery, setDashboardSearchQuery] = useState("");
const [dashboardSearchLot, setDashboardSearchLot] = useState<MediaLot | "ALL">(
"ALL",
);
- const [dashboardSearchQuery, setDashboardSearchQuery] = useState("");As per coding guidelines: "When declaring multiple variables in sequence (particularly React hooks), order them by ascending line length". 🤖 Prompt for AI Agents |
||
| const { startOnboardingTour } = useOnboardingTour(); | ||
| const isOnboardingTourCompleted = useIsOnboardingTourCompleted(); | ||
|
|
||
|
|
@@ -155,6 +164,28 @@ export default function Page() { | |
| }), | ||
| }); | ||
|
|
||
| const dashboardSearchInput: UserMetadataListInput = useMemo( | ||
| () => ({ | ||
| lot: dashboardSearchLot === "ALL" ? undefined : dashboardSearchLot, | ||
| search: { | ||
| page: 1, | ||
| take: 24, | ||
| query: dashboardSearchQuery || undefined, | ||
| }, | ||
| sort: { by: MediaSortBy.LastUpdated, order: GraphqlSortOrder.Desc }, | ||
| }), | ||
| [dashboardSearchLot, dashboardSearchQuery], | ||
| ); | ||
|
|
||
| const dashboardSearchResultsQuery = useQuery({ | ||
| enabled: dashboardSearchQuery.length > 0, | ||
| queryKey: queryFactory.media.userMetadataList(dashboardSearchInput).queryKey, | ||
| queryFn: () => | ||
| clientGqlService.request(UserMetadataListDocument, { | ||
| input: dashboardSearchInput, | ||
| }), | ||
| }); | ||
|
|
||
| const latestUserSummary = | ||
| userAnalyticsQuery.data?.userAnalytics.response.activities.items.at(0); | ||
|
|
||
|
|
@@ -187,6 +218,63 @@ export default function Page() { | |
| </> | ||
| )} | ||
| </ClientOnly> | ||
| <Stack gap="sm"> | ||
| <SectionTitle text="Discover your library" /> | ||
| <DebouncedSearchInput | ||
| value={dashboardSearchQuery} | ||
| onChange={setDashboardSearchQuery} | ||
| placeholder="Search across all media..." | ||
| /> | ||
| <Group gap="xs" wrap="nowrap" style={{ overflowX: "auto" }}> | ||
| {( | ||
| [ | ||
| { label: "All", value: "ALL" as const }, | ||
| { label: "Anime", value: MediaLot.Anime }, | ||
| { label: "Books", value: MediaLot.Book }, | ||
| { label: "Manga", value: MediaLot.Manga }, | ||
| { label: "Movies", value: MediaLot.Movie }, | ||
| { label: "Music", value: MediaLot.Music }, | ||
| { label: "Shows", value: MediaLot.Show }, | ||
| { label: "Podcasts", value: MediaLot.Podcast }, | ||
| { label: "Games", value: MediaLot.VideoGame }, | ||
| { label: "Comics", value: MediaLot.ComicBook }, | ||
| { label: "Audiobooks", value: MediaLot.AudioBook }, | ||
| { label: "Visual Novels", value: MediaLot.VisualNovel }, | ||
| ] as const | ||
| ).map((o) => ( | ||
| <Button | ||
| key={o.value} | ||
| size="compact-sm" | ||
| variant={dashboardSearchLot === o.value ? "light" : "default"} | ||
| onClick={() => setDashboardSearchLot(o.value)} | ||
| > | ||
| {o.label} | ||
| </Button> | ||
| ))} | ||
| </Group> | ||
| {dashboardSearchQuery.length > 0 ? ( | ||
| dashboardSearchResultsQuery.data ? ( | ||
| dashboardSearchResultsQuery.data.userMetadataList.response.items | ||
| .length > 0 ? ( | ||
| <ApplicationGrid> | ||
| {dashboardSearchResultsQuery.data.userMetadataList.response.items.map( | ||
| (m) => ( | ||
| <MetadataDisplayItem | ||
| key={m} | ||
| metadataId={m} | ||
| shouldHighlightNameIfInteracted | ||
| /> | ||
| ), | ||
| )} | ||
| </ApplicationGrid> | ||
| ) : ( | ||
| <Text c="dimmed">No media found matching your query.</Text> | ||
| ) | ||
| ) : ( | ||
| <SkeletonLoader /> | ||
| ) | ||
| ) : null} | ||
| </Stack> | ||
| {userPreferences.general.dashboard.map((de) => | ||
| match([de.section, de.hidden]) | ||
| .with([DashboardElementLot.Upcoming, false], ([v, _]) => ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Import out of alphabetical order.
~/components/common/filtersshould precede~/components/common/layout. This ordering is tooling-enforced and may fail lint/CI.♻️ Proposed fix
As per coding guidelines: "Import statements should follow alphabetical ordering as enforced by tooling".
📝 Committable suggestion
🤖 Prompt for AI Agents