From ae1d9d269ea4e9080565270106831c4120823380 Mon Sep 17 00:00:00 2001 From: Indigo Tang Date: Mon, 9 Jun 2025 03:53:30 +0000 Subject: [PATCH] add page to view owner toy list and status --- .vscode/settings.json | 4 + .../[locale]/owner/[ownerId]/toys/page.tsx | 85 +++++++++++++++++++ src/locales/en.ts | 5 ++ src/locales/zh-TW.ts | 5 ++ 4 files changed, 99 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 src/app/[locale]/owner/[ownerId]/toys/page.tsx diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..03adc8d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "IDX.aI.enableInlineCompletion": true, + "IDX.aI.enableCodebaseIndexing": true +} \ No newline at end of file diff --git a/src/app/[locale]/owner/[ownerId]/toys/page.tsx b/src/app/[locale]/owner/[ownerId]/toys/page.tsx new file mode 100644 index 0000000..6ca8def --- /dev/null +++ b/src/app/[locale]/owner/[ownerId]/toys/page.tsx @@ -0,0 +1,85 @@ +import Link from 'next/link'; +import { Button } from '@/components/ui/button'; +import ToyList from '@/components/toys/ToyList'; +import { mockToys } from '@/lib/mockData'; +import type { Toy } from '@/types'; +import { getI18n, getStaticParams as getLocaleStaticParams } from '@/locales/server'; +import { ArrowLeft, Home } from 'lucide-react'; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { ToyBrick } from 'lucide-react'; + +interface OwnerToysPageProps { + params: { ownerId: string; locale: string }; +} + +async function getOwnerToys(ownerId: string): Promise { + await new Promise(resolve => setTimeout(resolve, 100)); // Simulate fetch + return mockToys.filter(toy => toy.ownerId === ownerId); +} + +export default async function OwnerToysPage({ params }: OwnerToysPageProps) { + const t = await getI18n(); + const ownerToys = await getOwnerToys(params.ownerId); + + let ownerName: string | undefined; + if (ownerToys.length > 0) { + ownerName = ownerToys[0].ownerName; + } else { + // Attempt to find owner name even if they have no toys, if we had a user list + // For now, we rely on toys or show a generic message if ownerId itself is unknown + const ownerFromAnyToy = mockToys.find(toy => toy.ownerId === params.ownerId); + if (ownerFromAnyToy) { + ownerName = ownerFromAnyToy.ownerName; + } + } + + const pageTitle = ownerName + ? t('owner_toys.title', { ownerName }) + : t('owner_toys.owner_not_found'); + + return ( +
+
+

{pageTitle}

+ + + +
+ + {ownerToys.length > 0 ? ( + ({...toy, dataAiHint: toy.category.toLowerCase()}))} /> + ) : ( + + + + + {ownerName ? t('owner_toys.no_toys_listed_by', { ownerName }) : t('owner_toys.owner_not_found')} + + {ownerName && {t('home.explore_toys')}} + + + + + + + + )} +
+ ); +} + +export async function generateStaticParams() { + const localeParams = getLocaleStaticParams(); // e.g. [{ locale: 'en' }, { locale: 'zh-TW' }] + + const ownerIds = Array.from(new Set(mockToys.map(toy => toy.ownerId))); + const ownerParams = ownerIds.map(id => ({ ownerId: id })); + + return localeParams.flatMap(lang => + ownerParams.map(owner => ({ ...lang, ...owner })) + ); +} diff --git a/src/locales/en.ts b/src/locales/en.ts index ae45a1d..95eb865 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -144,4 +144,9 @@ export default { 'dashboard.requests.status_pending': 'Pending', 'dashboard.requests.status_approved': 'Approved', 'dashboard.requests.status_declined': 'Declined', + 'owner_toys.title': "{ownerName}'s Shared Toys", + 'owner_toys.no_toys_listed_by': '{ownerName} has not listed any toys yet.', + 'owner_toys.owner_not_found': 'Owner not found or has no toys listed.', + 'owner_toys.back_to_home': 'Back to Home', + 'owner_toys.unknown_owner': 'Unknown Owner', } as const; diff --git a/src/locales/zh-TW.ts b/src/locales/zh-TW.ts index ae9bb91..60ade0a 100644 --- a/src/locales/zh-TW.ts +++ b/src/locales/zh-TW.ts @@ -144,4 +144,9 @@ export default { 'dashboard.requests.status_pending': '待處理', 'dashboard.requests.status_approved': '已批准', 'dashboard.requests.status_declined': '已拒絕', + 'owner_toys.title': '{ownerName} 分享的玩具', + 'owner_toys.no_toys_listed_by': '{ownerName} 目前沒有列出任何玩具。', + 'owner_toys.owner_not_found': '找不到擁有者或該擁有者沒有列出任何玩具。', + 'owner_toys.back_to_home': '返回首頁', + 'owner_toys.unknown_owner': '未知擁有者', } as const;