Skip to content

Commit

Permalink
Lesson plan WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aberonni committed Jan 17, 2024
1 parent 4b3bb97 commit 1285a64
Show file tree
Hide file tree
Showing 14 changed files with 1,392 additions and 118 deletions.
131 changes: 89 additions & 42 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ model Resource {
relatedResources Resource[] @relation("RelatedResources") // child Resource (Resource that are suggested)
relatedResourceParent Resource[] @relation("RelatedResources") // parent Resource (parent Resource of a suggested Resource)
published Boolean @default(false)
createdBy User @relation(fields: [createdById], references: [id])
createdById String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
published Boolean @default(false)
createdBy User @relation(fields: [createdById], references: [id])
createdById String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lessonPlanItems LessonPlanItem[]
@@index([createdById])
}
Expand All @@ -69,58 +71,103 @@ model CategoriesOnResources {
@@index([resourceId])
}

model LessonPlanItem {
id String @id @default(cuid())
text String? @db.Text
resource Resource? @relation(fields: [resourceId], references: [id], onUpdate: Cascade, onDelete: Cascade)
resourceId String? // relation scalar field (used in the `@relation` attribute above)
duration Int?
order Int
section LessonPlanSection @relation(fields: [sectionId], references: [id], onUpdate: Cascade, onDelete: Cascade)
sectionId String
@@index([sectionId])
@@index([resourceId])
}

model LessonPlanSection {
id String @id @default(cuid())
title String?
items LessonPlanItem[]
lessonPlan LessonPlan @relation(fields: [lessonPlanId], references: [id], onUpdate: Cascade, onDelete: Cascade)
lessonPlanId String
order Int
@@index([lessonPlanId])
}

model LessonPlan {
id String @id @default(cuid())
title String
description String? @db.Text
private Boolean @default(true)
useDuration Boolean @default(true)
createdBy User @relation(fields: [createdById], references: [id])
createdById String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
sections LessonPlanSection[]
@@index([createdById])
}

// Necessary for Next auth
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@index([userId])
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@index([userId])
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId])
@@index([userId])
}

enum UserRole {
ADMIN
USER
ADMIN
USER
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
role UserRole? @default(USER)
accounts Account[]
sessions Session[]
resources Resource[]
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
role UserRole? @default(USER)
accounts Account[]
sessions Session[]
resources Resource[]
lessonPlans LessonPlan[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
@@unique([identifier, token])
}
44 changes: 44 additions & 0 deletions src/components/LessonPlan.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import ReactMarkdown from "react-markdown";
import Link from "next/link";
import type * as z from "zod";

import type { RouterOutputs } from "~/utils/api";
import type { ResourceConfiguation, ResourceType } from "@prisma/client";
import { use, useMemo } from "react";
import { lessonPlanCreateSchema, type resourceCreateSchema } from "~/utils/zod";
import { ScrollArea } from "~/components/ui/scroll-area";
import { Separator } from "./ui/separator";

type ApiLessonPlan = Readonly<RouterOutputs["lessonPlan"]["getById"]>;
type CreationLessonPlan = z.infer<typeof lessonPlanCreateSchema>;
type LessonPlanUnion = ApiLessonPlan | CreationLessonPlan;

type Props = {
lessonPlan: LessonPlanUnion;
};
export function SingleLessonPlanComponent({ lessonPlan }: Props) {
const isPreviewItem = (
item: LessonPlanUnion["sections"][0]["items"][0],
): item is CreationLessonPlan["sections"][0]["items"][0] => {
return !!item.resource && "label" in item.resource;
};

return (
<div className="prose dark:prose-invert">
<p>{lessonPlan.description}</p>
{lessonPlan.sections.map((section, index) => (
<div key={index}>
<h2>{section.title}</h2>
{section.items.map((item, itemIndex) => (
<div key={itemIndex}>
{isPreviewItem(item)
? item.resource?.label
: item.resource?.title}
- {item.text}
</div>
))}
</div>
))}
</div>
);
}
Loading

0 comments on commit 1285a64

Please sign in to comment.