/opt/canhelp/apps/web/src/app/tasks/[id]
Edit: /opt/canhelp/apps/web/src/app/tasks/[id]/page.tsx (1753B)
import { getTask, getCategories, getLocations } from '@/lib/api'
import { notFound } from 'next/navigation'
import { cookies } from 'next/headers'
import type { Metadata } from 'next'
import TaskDetailClient from './TaskDetailClient'
interface Props {
params: Promise<{ id: string }>
}
export async function generateMetadata({ params }: Props): Promise
{
const { id } = await params
try {
const { task } = await getTask(id)
return { title: `${task.title} — CanHelp`, description: task.description.slice(0, 160) }
} catch {
return { title: 'Εργασία — CanHelp' }
}
}
export default async function TaskDetailPage({ params }: Props) {
const { id } = await params
let taskData: any
try {
taskData = await getTask(id)
} catch {
notFound()
}
const cookieStore = await cookies()
const locale = (cookieStore.get('canhelp_locale')?.value ?? 'el') as 'el' | 'en' | 'uk' | 'ru'
const [cats, locs] = await Promise.all([
getCategories().catch(() => []),
getLocations().catch(() => []),
])
const catMap: Record = {}
for (const cat of cats) {
catMap[(cat as any).slug] = (cat as any).names[locale] ?? (cat as any).names.el
for (const sub of (cat as any).children ?? []) {
catMap[sub.slug] = sub.names[locale] ?? sub.names.el
}
}
const locMap: Record = {}
for (const city of locs) {
locMap[(city as any).slug] = (city as any).names[locale] ?? (city as any).names.el
for (const d of (city as any).children ?? []) {
locMap[d.slug] = d.names[locale] ?? d.names.el
}
}
return
}