From 1d8ddb0d75d4a6b10197c7fba051c6feda573978 Mon Sep 17 00:00:00 2001 From: Nicholas Chiang Date: Thu, 23 Nov 2023 23:30:14 -0800 Subject: [PATCH] fix(app/profile): own/want nav items go to sets This patch updates the user profile page so that the "own" and "want" navigation items simply open the corresponding set page. There is nothing particularly special about these sets, so I figured I might as well have them included just as normal sets and exposed so to the end user. This does result in some unintuitive behavior where both the "sets" and the "own/want" tab will be active at a given time. But it makes sense. --- app/routes/_header.$username.own.tsx | 39 ------------------ app/routes/_header.$username.sets.tsx | 57 +++++++++++++++------------ app/routes/_header.$username.tsx | 28 ++++++++----- app/routes/_header.$username.want.tsx | 39 ------------------ 4 files changed, 50 insertions(+), 113 deletions(-) delete mode 100644 app/routes/_header.$username.own.tsx delete mode 100644 app/routes/_header.$username.want.tsx diff --git a/app/routes/_header.$username.own.tsx b/app/routes/_header.$username.own.tsx deleted file mode 100644 index 1fb9920f..00000000 --- a/app/routes/_header.$username.own.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { useLoaderData } from '@remix-run/react' -import { type DataFunctionArgs } from '@vercel/remix' - -import { SetItem } from 'components/set-item' - -import { OWN_SET_NAME, getItems } from 'utils/set' - -import { prisma } from 'db.server' -import { requireUserId } from 'session.server' - -export async function loader({ request }: DataFunctionArgs) { - const userId = await requireUserId(request) - const set = await prisma.set.findUnique({ - where: { name_authorId: { name: OWN_SET_NAME, authorId: userId } }, - include: { - variants: { - orderBy: { updatedAt: 'desc' }, - include: { images: { take: 1 }, product: true }, - }, - looks: { - orderBy: { updatedAt: 'desc' }, - include: { images: { take: 1 } }, - }, - }, - }) - if (set == null) throw new Response('Not Found', { status: 404 }) - return getItems(set) -} - -export default function OwnPage() { - const items = useLoaderData() - return ( -
    - {items.map((item) => ( - - ))} -
- ) -} diff --git a/app/routes/_header.$username.sets.tsx b/app/routes/_header.$username.sets.tsx index ad60e70a..ad493c48 100644 --- a/app/routes/_header.$username.sets.tsx +++ b/app/routes/_header.$username.sets.tsx @@ -19,10 +19,7 @@ import { prisma } from 'db.server' export async function loader({ params }: DataFunctionArgs) { if (params.username == null) throw new Response('Not Found', { status: 404 }) const sets = await prisma.set.findMany({ - where: { - author: { username: params.username }, - name: { notIn: [OWN_SET_NAME, WANT_SET_NAME] }, - }, + where: { author: { username: params.username } }, orderBy: { updatedAt: 'desc' }, }) return sets @@ -30,32 +27,40 @@ export async function loader({ params }: DataFunctionArgs) { export default function UserSetsPage() { const sets = useLoaderData() + const want = sets.find((set) => set.name === WANT_SET_NAME) + const own = sets.find((set) => set.name === OWN_SET_NAME) return (
    - - - {WANT_SET_NAME} - - - - {OWN_SET_NAME} - - - {sets.map((set) => ( - - {({ isActive }) => ( - <> - {isActive ? ( - - ) : ( - - )} - {set.name} - - )} + {want && ( + + + {WANT_SET_NAME} - ))} + )} + {own && ( + + + {OWN_SET_NAME} + + )} + {(want != null || own != null) && } + {sets + .filter((set) => set !== want && set !== own) + .map((set) => ( + + {({ isActive }) => ( + <> + {isActive ? ( + + ) : ( + + )} + {set.name} + + )} + + ))}
diff --git a/app/routes/_header.$username.tsx b/app/routes/_header.$username.tsx index 9b5e5c4c..12b83682 100644 --- a/app/routes/_header.$username.tsx +++ b/app/routes/_header.$username.tsx @@ -77,7 +77,10 @@ export async function loader({ params }: DataFunctionArgs) { const [user, lookCount] = await Promise.all([ prisma.user.findUnique({ where: { username: params.username }, - include: { _count: { select: { reviews: true, sets: true } } }, + include: { + sets: { where: { name: { in: [WANT_SET_NAME, OWN_SET_NAME] } } }, + _count: { select: { reviews: true, sets: true } }, + }, }), prisma.look.count({ where: { sets: { some: { author: { username: params.username } } } }, @@ -127,6 +130,9 @@ export async function action({ request, params }: DataFunctionArgs) { export const useUser = () => useOutletContext>() export default function UserPage() { + const { sets } = useLoaderData() + const want = sets.find((set) => set.name === WANT_SET_NAME) + const own = sets.find((set) => set.name === OWN_SET_NAME) return (
@@ -135,14 +141,18 @@ export default function UserPage() { Saved - - - {WANT_SET_NAME} - - - - {OWN_SET_NAME} - + {want && ( + + + {WANT_SET_NAME} + + )} + {own && ( + + + {OWN_SET_NAME} + + )} Sets diff --git a/app/routes/_header.$username.want.tsx b/app/routes/_header.$username.want.tsx deleted file mode 100644 index a08f4b17..00000000 --- a/app/routes/_header.$username.want.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { useLoaderData } from '@remix-run/react' -import { type DataFunctionArgs } from '@vercel/remix' - -import { SetItem } from 'components/set-item' - -import { WANT_SET_NAME, getItems } from 'utils/set' - -import { prisma } from 'db.server' -import { requireUserId } from 'session.server' - -export async function loader({ request }: DataFunctionArgs) { - const userId = await requireUserId(request) - const set = await prisma.set.findUnique({ - where: { name_authorId: { name: WANT_SET_NAME, authorId: userId } }, - include: { - variants: { - orderBy: { updatedAt: 'desc' }, - include: { images: { take: 1 }, product: true }, - }, - looks: { - orderBy: { updatedAt: 'desc' }, - include: { images: { take: 1 } }, - }, - }, - }) - if (set == null) throw new Response('Not Found', { status: 404 }) - return getItems(set) -} - -export default function WantPage() { - const items = useLoaderData() - return ( -
    - {items.map((item) => ( - - ))} -
- ) -}