feat: add search input on user profile pages
This commit is contained in:
@@ -2,11 +2,12 @@ import { Link } from "@tanstack/react-router"
|
|||||||
import { useCallback } from "react"
|
import { useCallback } from "react"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { Bar, BarChart, XAxis, YAxis } from "recharts"
|
import { Bar, BarChart, XAxis, YAxis } from "recharts"
|
||||||
import { User } from "lucide-react"
|
import { Search, User } from "lucide-react"
|
||||||
import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from "@/components/ui/chart"
|
import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from "@/components/ui/chart"
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { Skeleton } from "@/components/ui/skeleton"
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
import { MovieCard } from "@/components/movie-card"
|
import { MovieCard } from "@/components/movie-card"
|
||||||
import { EmptyState } from "@/components/empty-state"
|
import { EmptyState } from "@/components/empty-state"
|
||||||
import { SwipeTabs } from "@/components/swipe-tabs"
|
import { SwipeTabs } from "@/components/swipe-tabs"
|
||||||
@@ -19,6 +20,8 @@ type ProfileViewProps = {
|
|||||||
actions?: React.ReactNode
|
actions?: React.ReactNode
|
||||||
headerRight?: React.ReactNode
|
headerRight?: React.ReactNode
|
||||||
userId?: string
|
userId?: string
|
||||||
|
search?: string
|
||||||
|
onSearchChange?: (value: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ProfileView({
|
export function ProfileView({
|
||||||
@@ -26,6 +29,8 @@ export function ProfileView({
|
|||||||
actions,
|
actions,
|
||||||
headerRight,
|
headerRight,
|
||||||
userId,
|
userId,
|
||||||
|
search,
|
||||||
|
onSearchChange,
|
||||||
}: ProfileViewProps) {
|
}: ProfileViewProps) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const initial = (data.username || "?")[0]?.toUpperCase() ?? "?"
|
const initial = (data.username || "?")[0]?.toUpperCase() ?? "?"
|
||||||
@@ -72,6 +77,18 @@ export function ProfileView({
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{onSearchChange && (
|
||||||
|
<div className="relative">
|
||||||
|
<Search className="absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||||
|
<Input
|
||||||
|
placeholder={t("profile.searchPlaceholder")}
|
||||||
|
value={search ?? ""}
|
||||||
|
onChange={(e) => onSearchChange(e.target.value)}
|
||||||
|
className="pl-9"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{actions}
|
{actions}
|
||||||
|
|
||||||
<SwipeTabs
|
<SwipeTabs
|
||||||
@@ -82,13 +99,14 @@ export function ProfileView({
|
|||||||
{(tab) => (
|
{(tab) => (
|
||||||
<>
|
<>
|
||||||
{tab === "recent" && (
|
{tab === "recent" && (
|
||||||
<DiaryTab key="date_desc" sortBy="date_desc" userId={userId} />
|
<DiaryTab key="date_desc" sortBy="date_desc" userId={userId} search={search} />
|
||||||
)}
|
)}
|
||||||
{tab === "top_rated" && (
|
{tab === "top_rated" && (
|
||||||
<DiaryTab
|
<DiaryTab
|
||||||
key="rating_desc"
|
key="rating_desc"
|
||||||
sortBy="rating_desc"
|
sortBy="rating_desc"
|
||||||
userId={userId}
|
userId={userId}
|
||||||
|
search={search}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{tab === "trends" && <TrendsView data={data} />}
|
{tab === "trends" && <TrendsView data={data} />}
|
||||||
@@ -108,19 +126,24 @@ function StatCell({ label, value }: { label: string; value: string | number }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DiaryTab({ sortBy }: { sortBy: string; userId?: string }) {
|
function DiaryTab({ sortBy, search }: { sortBy: string; userId?: string; search?: string }) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { data, isPending, hasNextPage, isFetchingNextPage, fetchNextPage } =
|
const { data, isPending, hasNextPage, isFetchingNextPage, fetchNextPage } =
|
||||||
useInfiniteDiary({ sort_by: sortBy, movie_id: undefined })
|
useInfiniteDiary({ sort_by: sortBy, movie_id: undefined })
|
||||||
const items = data?.pages.flatMap((p) => p.items) ?? []
|
const items = data?.pages.flatMap((p) => p.items) ?? []
|
||||||
|
const filtered = search
|
||||||
|
? items.filter((e) =>
|
||||||
|
e.movie.title.toLowerCase().includes(search.toLowerCase())
|
||||||
|
)
|
||||||
|
: items
|
||||||
const loadMore = useCallback(() => fetchNextPage(), [fetchNextPage])
|
const loadMore = useCallback(() => fetchNextPage(), [fetchNextPage])
|
||||||
|
|
||||||
if (isPending) return <Skeleton className="h-40 w-full rounded-xl" />
|
if (isPending) return <Skeleton className="h-40 w-full rounded-xl" />
|
||||||
if (!items.length) return <EmptyState icon={User} title={t("profile.noEntries")} />
|
if (!filtered.length) return <EmptyState icon={User} title={t("profile.noEntries")} />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VirtualList
|
<VirtualList
|
||||||
items={items}
|
items={filtered}
|
||||||
estimateSize={52}
|
estimateSize={52}
|
||||||
hasMore={!!hasNextPage}
|
hasMore={!!hasNextPage}
|
||||||
isFetching={isFetchingNextPage}
|
isFetching={isFetchingNextPage}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export const userProfileQueryParamsSchema = z.object({
|
|||||||
view: z.string().optional(),
|
view: z.string().optional(),
|
||||||
limit: z.number().optional(),
|
limit: z.number().optional(),
|
||||||
offset: z.number().optional(),
|
offset: z.number().optional(),
|
||||||
|
search: z.string().optional(),
|
||||||
})
|
})
|
||||||
export type UserProfileQueryParams = z.infer<typeof userProfileQueryParamsSchema>
|
export type UserProfileQueryParams = z.infer<typeof userProfileQueryParamsSchema>
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ function ProfilePage() {
|
|||||||
view: "trends",
|
view: "trends",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [search, setSearch] = useState("")
|
||||||
|
|
||||||
if (!auth) return null
|
if (!auth) return null
|
||||||
if (isPending) return <ProfileSkeleton />
|
if (isPending) return <ProfileSkeleton />
|
||||||
if (!data) return null
|
if (!data) return null
|
||||||
@@ -39,6 +41,8 @@ function ProfilePage() {
|
|||||||
|
|
||||||
<ProfileView
|
<ProfileView
|
||||||
data={data}
|
data={data}
|
||||||
|
search={search}
|
||||||
|
onSearchChange={setSearch}
|
||||||
actions={
|
actions={
|
||||||
<>
|
<>
|
||||||
<GoalSection goals={data.goals ?? []} />
|
<GoalSection goals={data.goals ?? []} />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { createFileRoute } from "@tanstack/react-router"
|
import { createFileRoute } from "@tanstack/react-router"
|
||||||
|
import { useState } from "react"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { UserCheck, UserPlus } from "lucide-react"
|
import { UserCheck, UserPlus } from "lucide-react"
|
||||||
import { BackButton } from "@/components/back-button"
|
import { BackButton } from "@/components/back-button"
|
||||||
@@ -22,6 +23,8 @@ function UserProfilePage() {
|
|||||||
const followMutation = useFollow()
|
const followMutation = useFollow()
|
||||||
const unfollowMutation = useUnfollow()
|
const unfollowMutation = useUnfollow()
|
||||||
|
|
||||||
|
const [search, setSearch] = useState("")
|
||||||
|
|
||||||
if (isPending) return <ProfileSkeleton />
|
if (isPending) return <ProfileSkeleton />
|
||||||
if (!data) return null
|
if (!data) return null
|
||||||
|
|
||||||
@@ -35,6 +38,8 @@ function UserProfilePage() {
|
|||||||
<ProfileView
|
<ProfileView
|
||||||
data={data}
|
data={data}
|
||||||
userId={id}
|
userId={id}
|
||||||
|
search={search}
|
||||||
|
onSearchChange={setSearch}
|
||||||
actions={
|
actions={
|
||||||
data.goals?.length ? (
|
data.goals?.length ? (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user