85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
import { getListWithItems } from '@/lib/actions'
|
|
import { getPermission } from '@/lib/permissions'
|
|
import { getServerSession } from 'next-auth'
|
|
import { authOptions } from '@/pages/api/auth/[...nextauth]'
|
|
import { notFound } from 'next/navigation'
|
|
import Link from 'next/link'
|
|
import { ArrowLeft } from 'lucide-react'
|
|
import InlineItemCreate from '@/components/InlineItemCreate'
|
|
import ListDetailView from '@/components/ListDetailView'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
export default async function ListDetailPage({ params }: { params: { id: string } }) {
|
|
const session = await getServerSession(authOptions)
|
|
if (!session?.user?.id) {
|
|
notFound()
|
|
}
|
|
|
|
const list = await getListWithItems(params.id)
|
|
|
|
if (!list) {
|
|
notFound()
|
|
}
|
|
|
|
// Get user's permission for this list
|
|
const permission = await getPermission(session.user.id, params.id)
|
|
if (!permission) {
|
|
notFound()
|
|
}
|
|
|
|
const canShare = permission === 'owner'
|
|
const canEdit = permission === 'owner' || permission === 'editor'
|
|
const completedItems = list.items.filter(item => item.completed)
|
|
|
|
return (
|
|
<main className="container mx-auto px-4 sm:px-6 py-6 sm:py-8 max-w-6xl">
|
|
{/* Header */}
|
|
<div className="mb-6 sm:mb-8">
|
|
<Link
|
|
href="/"
|
|
className="inline-flex items-center gap-2 text-gray-600 hover:text-gray-900 active:text-black mb-4 transition-colors tap-target-sm text-sm sm:text-base"
|
|
>
|
|
<ArrowLeft size={20} className="flex-shrink-0" />
|
|
<span>Back to Lists</span>
|
|
</Link>
|
|
|
|
<div className="flex items-center gap-2 sm:gap-3 mb-2">
|
|
<div
|
|
className="w-5 h-5 sm:w-6 sm:h-6 rounded-full flex-shrink-0"
|
|
style={{ backgroundColor: list.color }}
|
|
/>
|
|
<h1 className="text-2xl sm:text-3xl lg:text-4xl font-bold text-gray-900 truncate">{list.title}</h1>
|
|
</div>
|
|
|
|
<p className="text-gray-600 text-sm sm:text-base">
|
|
{completedItems.length} of {list.items.length} tasks completed
|
|
</p>
|
|
</div>
|
|
|
|
{/* Inline Item Creation - only show if user can edit */}
|
|
{canEdit && (
|
|
<div className="mb-6 sm:mb-8">
|
|
<InlineItemCreate listId={list.id} />
|
|
</div>
|
|
)}
|
|
|
|
{/* Search, Filter, and Items List */}
|
|
<ListDetailView
|
|
listId={list.id}
|
|
initialItems={list.items}
|
|
permission={permission}
|
|
canShare={canShare}
|
|
listTitle={list.title}
|
|
ownerId={list.ownerId}
|
|
ownerName={list.owner?.name}
|
|
ownerEmail={list.owner?.email || ''}
|
|
collaborators={list.collaborators.map(c => ({
|
|
...c,
|
|
permission: c.permission as 'editor' | 'viewer'
|
|
}))}
|
|
/>
|
|
</main>
|
|
)
|
|
}
|