diff --git a/app/routes/users/$username/notes/_layout.tsx b/app/routes/users/$username/notes/_layout.tsx index 1a3b897..147d0ee 100644 --- a/app/routes/users/$username/notes/_layout.tsx +++ b/app/routes/users/$username/notes/_layout.tsx @@ -1,34 +1,44 @@ import { invariantResponse } from '@epic-web/invariant' import { Img } from 'openimg/react' -import { Link, NavLink, Outlet } from 'react-router' +import { Form, Link, NavLink, Outlet } from 'react-router' import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx' import { Icon } from '#app/components/ui/icon.tsx' +import { Input } from '#app/components/ui/input.tsx' +import { Label } from '#app/components/ui/label.tsx' +import { StatusButton } from '#app/components/ui/status-button.tsx' import { prisma } from '#app/utils/db.server.ts' -import { cn, getUserImgSrc } from '#app/utils/misc.tsx' +import { cn, getUserImgSrc, useIsPending } from '#app/utils/misc.tsx' import { useOptionalUser } from '#app/utils/user.ts' import { type Route } from './+types/_layout.ts' -export async function loader({ params }: Route.LoaderArgs) { +export async function loader({ params, request }: Route.LoaderArgs) { + const url = new URL(request.url) + const q = url.searchParams.get('q')?.trim() ?? '' + const owner = await prisma.user.findFirst({ select: { id: true, name: true, username: true, image: { select: { objectKey: true } }, - notes: { select: { id: true, title: true } }, + notes: { + select: { id: true, title: true }, + where: q ? { title: { contains: q } } : {}, + }, }, where: { username: params.username }, }) invariantResponse(owner, 'Owner not found', { status: 404 }) - return { owner } + return { owner, q } } export default function NotesRoute({ loaderData }: Route.ComponentProps) { const user = useOptionalUser() const isOwner = user?.id === loaderData.owner.id const ownerDisplayName = loaderData.owner.name ?? loaderData.owner.username + const isSearching = useIsPending({ formMethod: 'GET' }) const navLinkDefaultClassName = 'line-clamp-2 block rounded-l-full py-2 pl-8 pr-6 text-base lg:text-xl' return ( @@ -51,7 +61,50 @@ export default function NotesRoute({ loaderData }: Route.ComponentProps) { {ownerDisplayName}'s Notes +
+ No notes match “{loaderData.q}” +
+