Skip to content

Commit 3ef4f06

Browse files
authored
Merge pull request #17 from MEITREX/docproc-ai
Docproc ai
2 parents 4924304 + 9a017f9 commit 3ef4f06

File tree

70 files changed

+4203
-2350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4203
-2350
lines changed

.eslintrc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": ["next/core-web-vitals", "prettier"]
2+
"extends": ["next/core-web-vitals", "prettier"],
3+
"rules": {
4+
"@next/next/no-img-element": "off"
5+
}
36
}

app/(dashboard)/student.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import dayjs from "dayjs";
1414
import { chain } from "lodash";
1515
import Link from "next/link";
16-
import { useState } from "react";
16+
import { Fragment, useState } from "react";
1717
import { useLazyLoadQuery } from "react-relay";
1818
import { graphql } from "relay-runtime";
1919

@@ -103,7 +103,7 @@ export default function StudentPage() {
103103
)
104104
.map(([key, courses]) => {
105105
return (
106-
<>
106+
<Fragment key={key}>
107107
<Typography variant="h6" gutterBottom>
108108
{key}
109109
</Typography>
@@ -118,7 +118,7 @@ export default function StudentPage() {
118118
/>
119119
))}
120120
</div>
121-
</>
121+
</Fragment>
122122
);
123123
})
124124

app/courses/[courseId]/flashcards/[flashcardSetId]/lecturer.tsx

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ export default function LecturerFlashcards() {
5151
...LecturerEditFlashcardFragment
5252
}
5353
}
54-
items{
54+
items {
5555
id
5656
associatedSkills {
5757
id
5858
skillName
5959
}
6060
associatedBloomLevels
6161
}
62-
}
62+
}
6363
...EditFlashcardSetModalFragment
6464
}
6565
}
@@ -72,34 +72,36 @@ export default function LecturerFlashcards() {
7272

7373
const [error, setError] = useState<any>(null);
7474

75-
7675
const [addFlashcard, isAddingFlashcard] =
7776
useMutation<lecturerAddFlashcardMutation>(graphql`
7877
mutation lecturerAddFlashcardMutation(
7978
$flashcard: CreateFlashcardInput!
8079
$assessmentId: UUID!
81-
$item:ItemInput!
82-
80+
$item: ItemInput!
8381
) {
8482
mutateFlashcardSet(assessmentId: $assessmentId) {
8583
assessmentId
86-
createFlashcard(flashcardInput: $flashcard,assessmentId: $assessmentId,item:$item) {
87-
flashcard{
84+
createFlashcard(
85+
flashcardInput: $flashcard
86+
assessmentId: $assessmentId
87+
item: $item
88+
) {
89+
flashcard {
8890
__id
89-
itemId
91+
itemId
9092
...LecturerEditFlashcardFragment
91-
}
92-
item{
93+
}
94+
item {
9395
id
9496
associatedSkills {
9597
id
9698
skillName
9799
}
98100
associatedBloomLevels
99-
}
100101
}
101102
}
102103
}
104+
}
103105
`);
104106
const [updateFlashcardSet, isUpdatingFlashcardSet] =
105107
useMutation<lecturerEditFlashcardSetMutation>(graphql`
@@ -124,7 +126,7 @@ export default function LecturerFlashcards() {
124126
}
125127
}
126128
}
127-
}
129+
}
128130
`);
129131

130132
const [deleteFlashcard, isDeleting] =
@@ -146,16 +148,17 @@ export default function LecturerFlashcards() {
146148

147149
const content = contentsByIds[0];
148150
const flashcardSet = content.flashcardSet;
149-
const transformedItems: ItemData[] = content.items?.map(item => ({
150-
associatedBloomLevels: Array.from(item.associatedBloomLevels),
151-
associatedSkills: Array.from(item.associatedSkills).map(skill => ({
151+
const transformedItems: ItemData[] =
152+
content.items?.map((item) => ({
153+
associatedBloomLevels: Array.from(item.associatedBloomLevels),
154+
associatedSkills: Array.from(item.associatedSkills).map((skill) => ({
152155
id: skill.id || undefined,
153156
skillName: skill.skillName,
154-
})),
155-
id: item.id,
156-
})) || [];
157-
const items=transformedItems;
158-
157+
})),
158+
id: item.id,
159+
})) || [];
160+
const items = transformedItems;
161+
159162
if (flashcardSet == null) {
160163
return (
161164
<PageError
@@ -165,15 +168,23 @@ const items=transformedItems;
165168
);
166169
}
167170

168-
function handleAddFlashcard(sides: FlashcardSideData[], item:ItemData,newSkillAdded?:boolean) {
171+
function handleAddFlashcard(
172+
sides: FlashcardSideData[],
173+
item: ItemData,
174+
newSkillAdded?: boolean
175+
) {
169176
const newFlashcard = {
170177
sides,
171-
itemId:null,
178+
itemId: null,
172179
};
173180

174181
setAddFlashcardOpen(false);
175182
addFlashcard({
176-
variables: { flashcard: newFlashcard,assessmentId: flashcardSetId,item:item },
183+
variables: {
184+
flashcard: newFlashcard,
185+
assessmentId: flashcardSetId,
186+
item: item,
187+
},
177188
onError: setError,
178189
updater(store, response) {
179190
// Get record of flashcard set and of the new flashcard
@@ -186,29 +197,27 @@ const items=transformedItems;
186197
// Update the linked records of the flashcard set
187198
const flashcardRecords =
188199
flashcardSetRecord.getLinkedRecords("flashcards") ?? [];
189-
console.log(flashcardRecords);
200+
console.log(flashcardRecords);
190201
flashcardSetRecord.setLinkedRecords(
191202
[...flashcardRecords, newRecord],
192203
"flashcards"
193204
);
194-
const root= store.get(flashcardSetId);
205+
const root = store.get(flashcardSetId);
195206

196-
if (!root) return;
207+
if (!root) return;
197208

198-
const items = root?.getLinkedRecords("items") ?? [];
209+
const items = root?.getLinkedRecords("items") ?? [];
199210

200-
const newItem=store.get(response.mutateFlashcardSet.createFlashcard.item!.id);
201-
202-
if (newItem) {
203-
204-
root.setLinkedRecords([...items, newItem], "items");
211+
const newItem = store.get(
212+
response.mutateFlashcardSet.createFlashcard.item!.id
213+
);
205214

215+
if (newItem) {
216+
root.setLinkedRecords([...items, newItem], "items");
206217
} else {
207-
208-
return;
209-
218+
return;
210219
}
211-
/* const items = store
220+
/* const items = store
212221
.getRoot()
213222
.getLinkedRecord("items")
214223
?.getLinkedRecords("elements");
@@ -222,13 +231,13 @@ const items=transformedItems;
222231

223232
console.log(flashcardSetRecord.getLinkedRecords("flashcards"));
224233
},
225-
onCompleted(){
234+
onCompleted() {
226235
//reload page, when a new skill is added
227-
if(newSkillAdded){
236+
if (newSkillAdded) {
228237
console.log("reload");
229238
window.location.reload();
230239
}
231-
}
240+
},
232241
});
233242
}
234243

@@ -355,7 +364,7 @@ const items=transformedItems;
355364
))}
356365
{isAddFlashcardOpen && (
357366
<LocalFlashcard
358-
courseId={courseId}
367+
courseId={courseId}
359368
onClose={() => setAddFlashcardOpen(false)}
360369
onSubmit={handleAddFlashcard}
361370
/>
@@ -379,7 +388,6 @@ const items=transformedItems;
379388
onClose={() => setEditSetOpen(false)}
380389
onSubmit={handleUpdateFlashcardSet}
381390
_content={content}
382-
383391
/>
384392
)}
385393
</main>

app/courses/[courseId]/flashcards/[flashcardSetId]/student.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function StudentFlashcards() {
6565
_flashcard: x,
6666
}))}
6767
emptyMessage="Empty flashcard set."
68-
onComplete={() =>window.location.replace(`/courses/${courseId}`)}
68+
onComplete={() => window.location.replace(`/courses/${courseId}`)}
6969
onError={setError}
7070
/>
7171
</main>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"use client";
2+
import { ContentMediaDisplayFragment$key } from "@/__generated__/ContentMediaDisplayFragment.graphql";
3+
import { ContentMediaDisplayVideoFragment$key } from "@/__generated__/ContentMediaDisplayVideoFragment.graphql";
4+
import { PdfViewer } from "@/components/PdfViewer";
5+
import { MediaPlayer, MediaProvider } from "@vidstack/react";
6+
import {
7+
defaultLayoutIcons,
8+
DefaultVideoLayout,
9+
} from "@vidstack/react/player/layouts/default";
10+
import "@vidstack/react/player/styles/default/layouts/video.css";
11+
import "@vidstack/react/player/styles/default/theme.css";
12+
import { useFragment } from "react-relay";
13+
import { graphql } from "relay-runtime";
14+
15+
export function ContentMediaDisplay({
16+
_record,
17+
onProgressChange,
18+
}: {
19+
_record: ContentMediaDisplayFragment$key;
20+
onProgressChange: (fraction: number) => void;
21+
}) {
22+
const mediaRecord = useFragment(
23+
graphql`
24+
fragment ContentMediaDisplayFragment on MediaRecord {
25+
type
26+
name
27+
standardizedDownloadUrl
28+
downloadUrl
29+
...ContentMediaDisplayVideoFragment
30+
}
31+
`,
32+
_record
33+
);
34+
35+
switch (mediaRecord.type) {
36+
case "VIDEO":
37+
return <VideoPlayer _video={mediaRecord} />;
38+
case "PRESENTATION":
39+
case "DOCUMENT":
40+
return (
41+
<PdfViewer
42+
onProgressChange={onProgressChange}
43+
url={mediaRecord.standardizedDownloadUrl ?? mediaRecord.downloadUrl}
44+
/>
45+
);
46+
case "IMAGE":
47+
// eslint-disable-next-line @next/next/no-img-element
48+
return (
49+
<img
50+
alt={mediaRecord.name}
51+
src={mediaRecord.standardizedDownloadUrl ?? mediaRecord.downloadUrl}
52+
className="max-h-md flex justify-center mx-auto"
53+
></img>
54+
);
55+
default:
56+
return <>Unsupported media type</>;
57+
}
58+
}
59+
60+
export function VideoPlayer({
61+
_video,
62+
}: {
63+
_video: ContentMediaDisplayVideoFragment$key;
64+
}) {
65+
const mediaRecord = useFragment(
66+
graphql`
67+
fragment ContentMediaDisplayVideoFragment on MediaRecord {
68+
type
69+
name
70+
standardizedDownloadUrl
71+
downloadUrl
72+
segments {
73+
id
74+
... on VideoRecordSegment {
75+
startTime
76+
transcript
77+
thumbnail
78+
title
79+
}
80+
}
81+
}
82+
`,
83+
_video
84+
);
85+
86+
return (
87+
<MediaPlayer
88+
src={mediaRecord.standardizedDownloadUrl ?? mediaRecord.downloadUrl}
89+
>
90+
<MediaProvider />
91+
<DefaultVideoLayout icons={defaultLayoutIcons} />
92+
</MediaPlayer>
93+
);
94+
}

0 commit comments

Comments
 (0)