From 569dfc6d1d8b0d1a3aa25d112b594634215407d5 Mon Sep 17 00:00:00 2001 From: geekysilento Date: Wed, 15 May 2024 18:25:50 +0530 Subject: [PATCH 1/3] feat: curriculum page --- .../academics/curricula/[code]/page.tsx | 196 +++++++++++++++++- i18n/en.ts | 15 ++ i18n/hi.ts | 15 ++ i18n/translations.ts | 15 ++ server/db/schema/courses.schema.ts | 5 +- 5 files changed, 241 insertions(+), 5 deletions(-) diff --git a/app/[locale]/academics/curricula/[code]/page.tsx b/app/[locale]/academics/curricula/[code]/page.tsx index f2095a8a..00b280cf 100644 --- a/app/[locale]/academics/curricula/[code]/page.tsx +++ b/app/[locale]/academics/curricula/[code]/page.tsx @@ -1,14 +1,202 @@ -import { WorkInProgressStatus } from '~/components/status'; +import Image from 'next/image'; +import Link from 'next/link'; +import { MdEmail, MdPhone } from 'react-icons/md'; + +import Heading from '~/components/heading'; +import { getTranslations } from '~/i18n/translations'; import { courses, db } from '~/server/db'; export async function generateStaticParams() { return await db.select({ code: courses.code }).from(courses); } -export default function Curriculum({ - params: { locale }, +export default async function Curriculum({ + params: { locale, code }, }: { params: { locale: string; code: string }; }) { - return ; + const text = (await getTranslations(locale)).Curricula.Details; + const courses = (await db.query.courses.findFirst({ + where: (course, { eq }) => eq(course.code, code), + with: { + coordinator: { + with: { + person: { + columns: { + name: true, + telephone: true, + email: true, + }, + }, + }, + }, + }, + }))!; + + console.log(courses); + return ( + <> + + +
+
+
+
+ {text.courseCode} {courses.code} +
+
+
{text.prerequisites}
+
    + {courses.prerequisites.map((prerequisite, idx) => ( + +
  1. +

    + {prerequisite} +

    +
  2. + + ))} +
+
+ +
+
{text.objectives}
+

{courses.objectives}

+
+ +
+ {text.nature} {courses.nature} +
+
+ + +
+ +
+ +
+ {courses.content.map((section, index) => ( +
+

{section.topic}

+
    + {section.subtopics.map((subtopic, subIndex) => ( +
  1. +

    {subtopic}

    +
  2. + ))} +
+
+ ))} +
+
+ +
+ +
    + {courses.outcomes.map((outcome, idx) => ( +
  1. +

    {outcome}

    +
  2. + ))} +
+
+ +
+ +
+

{text.essentialReading}

+
    + {courses.essentialReading.map((book, idx) => ( + +
  1. +

    {book}

    +
  2. + + ))} +
+
+
+

{text.supplementaryReading}

+
    + {courses.supplementaryReading.map((book, idx) => ( + +
  1. +

    {book}

    +
  2. + + ))} +
+
+
+ +
+ +
    + {courses.similarCourses.map((course, idx) => ( + +
  1. +

    {course}

    +
  2. + + ))} +
+
+
+ + ); } diff --git a/i18n/en.ts b/i18n/en.ts index 52eb7ca1..7aefc358 100644 --- a/i18n/en.ts +++ b/i18n/en.ts @@ -50,6 +50,21 @@ const text: Translations = { credits: 'L-T-P', totalCredits: 'Credits', syllabus: 'Syllabus', + Details: { + courseCode: 'Course Code: ', + title: 'Course Details', + coordinator: 'Coordinator', + prerequisites: 'Prerequisites', + nature: 'Course Nature: ', + objectives: 'Objectives', + content: 'Content', + outcomes: 'Outcomes', + essentialReading: 'Essential Reading', + supplementaryReading: 'Supplementary Reading', + similarCourses: 'Similar Courses', + headOfDepartment: 'Head of Department', + referenceBooks: 'Reference Books', + }, }, Departments: { title: 'DEPARTMENTS' }, Department: { diff --git a/i18n/hi.ts b/i18n/hi.ts index 60dbf024..a1a8cbd2 100644 --- a/i18n/hi.ts +++ b/i18n/hi.ts @@ -46,6 +46,21 @@ const text: Translations = { credits: 'एल-टी-पी', totalCredits: 'क्रेडिट्स', syllabus: 'पाठ्यक्रम', + Details: { + courseCode: 'कोर्स कोड: ', + title: 'कोर्स विवरण', + coordinator: 'समन्वयक', + prerequisites: 'आवश्यक शर्तें', + nature: 'कोर्स प्रकृति: ', + objectives: 'उद्देश्य', + content: 'सामग्री', + outcomes: 'परिणाम', + essentialReading: 'आवश्यक पाठ्य', + supplementaryReading: 'परिशिष्ट पाठ्य', + similarCourses: 'समान कोर्स', + headOfDepartment: 'विभाग के प्रमुख', + referenceBooks: 'संदर्भ पुस्तकें', + }, }, Departments: { title: 'विभाग' }, Department: { diff --git a/i18n/translations.ts b/i18n/translations.ts index 50628799..0bcacec7 100644 --- a/i18n/translations.ts +++ b/i18n/translations.ts @@ -42,6 +42,21 @@ export interface Translations { credits: string; totalCredits: string; syllabus: string; + Details: { + courseCode: string; + title: string; + coordinator: string; + prerequisites: string; + nature: string; + objectives: string; + content: string; + outcomes: string; + essentialReading: string; + supplementaryReading: string; + similarCourses: string; + headOfDepartment: string; + referenceBooks: string; + }; }; Departments: { title: string }; Department: { diff --git a/server/db/schema/courses.schema.ts b/server/db/schema/courses.schema.ts index b9ef5cba..22557921 100644 --- a/server/db/schema/courses.schema.ts +++ b/server/db/schema/courses.schema.ts @@ -2,6 +2,7 @@ import { relations, sql } from 'drizzle-orm'; import { char, integer, + json, pgTable, smallint, smallserial, @@ -30,7 +31,9 @@ export const courses = pgTable('courses', { .array() .default(sql`'{}'`) .notNull(), - content: text('content').notNull(), + content: json('content') + .$type<{ topic: string; subtopics: string[] }[]>() + .notNull(), outcomes: text('outcomes') .array() .default(sql`'{}'`) From 4bf883483d8e6c6c3779378f70be6d19920707a8 Mon Sep 17 00:00:00 2001 From: GetPsyched Date: Wed, 26 Jun 2024 16:41:08 +0400 Subject: [PATCH 2/3] fix: translation schema and coordinator typo --- .../academics/curricula/[code]/page.tsx | 32 ++++++++++--------- i18n/en.ts | 29 ++++++++--------- i18n/hi.ts | 29 ++++++++--------- i18n/translations.ts | 29 ++++++++--------- 4 files changed, 59 insertions(+), 60 deletions(-) diff --git a/app/[locale]/academics/curricula/[code]/page.tsx b/app/[locale]/academics/curricula/[code]/page.tsx index 00b280cf..cd9f2d69 100644 --- a/app/[locale]/academics/curricula/[code]/page.tsx +++ b/app/[locale]/academics/curricula/[code]/page.tsx @@ -15,7 +15,7 @@ export default async function Curriculum({ }: { params: { locale: string; code: string }; }) { - const text = (await getTranslations(locale)).Curricula.Details; + const text = (await getTranslations(locale)).Curriculum; const courses = (await db.query.courses.findFirst({ where: (course, { eq }) => eq(course.code, code), with: { @@ -33,7 +33,6 @@ export default async function Curriculum({ }, }))!; - console.log(courses); return ( <>
- {text.courseCode} {courses.code} + {text.courseCode}: {courses.code}
{text.prerequisites}
    - {courses.prerequisites.map((prerequisite, idx) => ( - + {courses.prerequisites.map((prerequisite, index) => ( +
  1. {prerequisite} @@ -71,12 +73,12 @@ export default async function Curriculum({

- {text.nature} {courses.nature} + {text.nature}: {courses.nature}
-
+
- {courses.content.map((section, index) => ( -
-

{section.topic}

-
    - {section.subtopics.map((subtopic, subIndex) => ( -
  1. -

    {subtopic}

    -
  2. - ))} -
-
- ))} + + {course.content.map((section, index) => ( + + {section.title} + +
    + {section.topics.map((topic, subIndex) => ( +
  1. +

    {topic}

    +
  2. + ))} +
+
+
+ ))} +
-
+
-
    - {courses.outcomes.map((outcome, index) => ( +
      + {course.outcomes.map((outcome, index) => (
    1. -

      {outcome}

      +
      {outcome}
    2. ))}
-
+
-
-

{text.essentialReading}

-
    - {courses.essentialReading.map((book, index) => ( - -
  1. -

    {book}

    -
  2. - - ))} -
-
-
-

{text.supplementaryReading}

-
    - {courses.supplementaryReading.map((book, index) => ( - -
  1. -

    {book}

    -
  2. - - ))} -
-
-
-
- -
    - {courses.similarCourses.map((course, index) => ( - -
  1. -

    {course}

    +
    +
      + {course.essentialReading.map((book, index) => ( +
    1. +

      + {book} +

    2. - - ))} -
    + ))} +
+
diff --git a/app/[locale]/academics/curricula/page.tsx b/app/[locale]/academics/curricula/page.tsx index 6fc2805c..24ac3182 100644 --- a/app/[locale]/academics/curricula/page.tsx +++ b/app/[locale]/academics/curricula/page.tsx @@ -88,6 +88,8 @@ const Courses = async ({ page }: { page: number }) => { offset: (page - 1) * 10, }); + console.log(courses); + return courses.map(({ code, coursesToMajors, title }) => coursesToMajors.map( ({ lectureCredits, practicalCredits, tutorialCredits, major }, index) => ( diff --git a/i18n/en.ts b/i18n/en.ts index 6324095c..be469cf6 100644 --- a/i18n/en.ts +++ b/i18n/en.ts @@ -55,7 +55,10 @@ const text: Translations = { courseCode: 'Course Code', title: 'Course Details', coordinator: 'Course Coordinator', - prerequisites: 'Prerequisites', + prerequisites: { + title: 'Prerequisites', + none: 'No prerequisites for this course', + }, nature: 'Course Nature', objectives: 'Objectives', content: 'Content', diff --git a/i18n/hi.ts b/i18n/hi.ts index fb0b5a76..ef4a4c69 100644 --- a/i18n/hi.ts +++ b/i18n/hi.ts @@ -51,7 +51,10 @@ const text: Translations = { courseCode: 'कोर्स कोड', title: 'कोर्स विवरण', coordinator: 'समन्वयक', - prerequisites: 'आवश्यक शर्तें', + prerequisites: { + title: 'आवश्यकताएँ', + none: 'इस कोर्स के लिए कोई आवश्यकता नहीं', + }, nature: 'कोर्स प्रकृति', objectives: 'उद्देश्य', content: 'सामग्री', diff --git a/i18n/translations.ts b/i18n/translations.ts index eefdc1e4..22e156d7 100644 --- a/i18n/translations.ts +++ b/i18n/translations.ts @@ -47,7 +47,10 @@ export interface Translations { courseCode: string; title: string; coordinator: string; - prerequisites: string; + prerequisites: { + title: string; + none: string; + }; nature: string; objectives: string; content: string; diff --git a/server/db/schema/courses.schema.ts b/server/db/schema/courses.schema.ts index 22557921..c14e0e9e 100644 --- a/server/db/schema/courses.schema.ts +++ b/server/db/schema/courses.schema.ts @@ -14,7 +14,7 @@ import { courseLogs, coursesToMajors, departments, faculty } from '.'; export const courses = pgTable('courses', { id: smallserial('id').primaryKey(), - code: varchar('code', { length: 7 }).unique().notNull(), + code: varchar('code', { length: 8 }).unique().notNull(), title: varchar('title', { length: 128 }).notNull(), coordinatorId: integer('coordinator_id') .references(() => faculty.id) @@ -26,13 +26,13 @@ export const courses = pgTable('courses', { .array() .default(sql`'{}'`) .notNull(), - nature: char('nature', { length: 3 }).notNull(), + nature: char('nature', { length: 20 }).notNull(), objectives: text('objectives') .array() .default(sql`'{}'`) .notNull(), content: json('content') - .$type<{ topic: string; subtopics: string[] }[]>() + .$type<{ title: string; topics: string[] }[]>() .notNull(), outcomes: text('outcomes') .array()