From ca8a92d82b605c349e39b71bdb9f4b8b99c97f98 Mon Sep 17 00:00:00 2001 From: Tuomas Alanen Date: Wed, 24 Jul 2024 19:08:29 +0300 Subject: [PATCH] Add correct titles for modals --- .../(...)courses/[slug]/manage/page.tsx | 19 ++++++++++++++++++ .../(...)courses/[slug]/upload/page.tsx | 19 ++++++++++++++++++ src/app/@modal/(...)courses/create/page.tsx | 5 +++++ .../[fileId]/[fileName]/manage/page.tsx | 20 +++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/src/app/@modal/(...)courses/[slug]/manage/page.tsx b/src/app/@modal/(...)courses/[slug]/manage/page.tsx index 39e16d09..7204e2fc 100644 --- a/src/app/@modal/(...)courses/[slug]/manage/page.tsx +++ b/src/app/@modal/(...)courses/[slug]/manage/page.tsx @@ -1,4 +1,5 @@ import { notFound } from 'next/navigation' +import { Metadata } from 'next' import { parseSlug } from '@lib/courses' import { getCourseInfo } from '@services/archive' @@ -8,6 +9,24 @@ import RenameCourse from '@components/tools/RenameCourse' import DeleteCourse from '@components/tools/DeleteCourse' import { validateUserRights } from '@services/tkoUserService' +export const generateMetadata = async ({ + params +}: { + params: { slug: string } +}): Promise => { + const { id } = parseSlug(params.slug) + const course = await getCourseInfo(id) + + if (!course) { + notFound() + } + + return { + title: `Manage - ${course.name} - Tärpistö - TKO-äly ry`, + description: 'The TKO-äly ry exam archive' + } +} + const Page = async ({ params }: { params: { slug: string } }) => { await validateUserRights('rename', 'remove') diff --git a/src/app/@modal/(...)courses/[slug]/upload/page.tsx b/src/app/@modal/(...)courses/[slug]/upload/page.tsx index 0668f4b1..bae07764 100644 --- a/src/app/@modal/(...)courses/[slug]/upload/page.tsx +++ b/src/app/@modal/(...)courses/[slug]/upload/page.tsx @@ -1,4 +1,5 @@ import { notFound } from 'next/navigation' +import { Metadata } from 'next' import { parseSlug } from '@lib/courses' import { getCourseInfo } from '@services/archive' @@ -7,6 +8,24 @@ import Modal from '@components/Modal' import UploadFiles from '@components/tools/UploadFiles' import { validateUserRights } from '@services/tkoUserService' +export const generateMetadata = async ({ + params +}: { + params: { slug: string } +}): Promise => { + const { id } = parseSlug(params.slug) + const course = await getCourseInfo(id) + + if (!course) { + notFound() + } + + return { + title: `Upload files - ${course.name} - Tärpistö - TKO-äly ry`, + description: 'The TKO-äly ry exam archive' + } +} + const Page = async ({ params }: { params: { slug: string } }) => { await validateUserRights('upload') diff --git a/src/app/@modal/(...)courses/create/page.tsx b/src/app/@modal/(...)courses/create/page.tsx index f2da88e3..d175249b 100644 --- a/src/app/@modal/(...)courses/create/page.tsx +++ b/src/app/@modal/(...)courses/create/page.tsx @@ -3,6 +3,11 @@ import { validateUserRights } from '@services/tkoUserService' import Modal from '@components/Modal' import CreateCourse from '@components/tools/CreateCourse' +export const metadata = { + title: `Create new course - Tärpistö - TKO-äly ry`, + description: 'The TKO-äly ry exam archive' +} + const Page = async () => { await validateUserRights('upload') diff --git a/src/app/@modal/(...)files/[fileId]/[fileName]/manage/page.tsx b/src/app/@modal/(...)files/[fileId]/[fileName]/manage/page.tsx index 4a275b9a..d13cce8b 100644 --- a/src/app/@modal/(...)files/[fileId]/[fileName]/manage/page.tsx +++ b/src/app/@modal/(...)files/[fileId]/[fileName]/manage/page.tsx @@ -1,4 +1,5 @@ import { notFound } from 'next/navigation' +import { Metadata } from 'next' import { getFileNameById } from '@services/archive' @@ -7,6 +8,25 @@ import DeleteFile from '@components/tools/DeleteFile' import UpdateFile from '@components/tools/UpdateFile' import { validateUserRights } from '@services/tkoUserService' +export const generateMetadata = async ({ + params +}: { + params: { fileId: string; fileName: string } +}): Promise => { + const fileId = parseInt(params.fileId, 10) + + const file = await getFileNameById(fileId) + + if (!file) { + notFound() + } + + return { + title: `Manage file ${file.fileName} - Tärpistö - TKO-äly ry`, + description: 'The TKO-äly ry exam archive' + } +} + const Page = async ({ params }: {