Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quantum-kittens
GitHub Repository: quantum-kittens/platypus
Path: blob/main/frontend/ts/syllabus.ts
3855 views
1
2
export type UnitUUID = string
3
4
export type SyllabusCode = string
5
6
export interface SyllabusCourse {
7
title: string,
8
description: string,
9
unitList: UnitUUID[],
10
}
11
12
export interface Syllabus {
13
id?: string,
14
code?: SyllabusCode,
15
name: string,
16
instructor: string,
17
location: string,
18
institution: string,
19
officeHours: string,
20
classHours: string,
21
email: string,
22
courseList: SyllabusCourse[]
23
}
24
25
let promise: Promise<Syllabus[]> | undefined
26
27
interface fetchResult {
28
data: Syllabus[],
29
count: number,
30
limit: number,
31
page: number
32
}
33
34
export const getSyllabi = () : Promise<Syllabus[]> => {
35
if (!promise) {
36
promise = fetch('/syllabus').then((res) => {
37
return res.json().then((jsonResult: fetchResult) => {
38
return jsonResult.data
39
})
40
})
41
}
42
return promise
43
}
44
45
export const getActiveSyllabus = (): Syllabus | undefined => {
46
const jsonText: string = document.getElementById('syllabus')?.textContent || ''
47
48
try {
49
return JSON.parse(jsonText) as Syllabus
50
} catch {
51
return undefined
52
}
53
}
54
55
export const emptySyllabus = (): Syllabus => ({
56
name: '',
57
instructor: '',
58
location: '',
59
institution: '',
60
officeHours: '',
61
classHours: '',
62
email: '',
63
courseList: [
64
{
65
title: '',
66
description: '',
67
unitList: []
68
}
69
]
70
})
71
72