Skip to content

Commit

Permalink
improve Assignment class handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ell1ott committed Feb 28, 2024
1 parent a228b9d commit 31bd144
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 40 deletions.
53 changes: 14 additions & 39 deletions src/lib/api/apiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,18 @@ export class FileInfo {
created_at: string;
updated_at: string;

constructor(
id: string,
name: string,
data: { type: string; data: [] },
created_at: string,
updated_at: string
) {
this.id = id;
this.name = name;
this.data = data;
this.created_at = created_at;
this.updated_at = updated_at;
constructor(info) {
this.id = info.id;
this.name = info.name;
this.data = info.data;
this.created_at = info.created_at;
this.updated_at = info.updated_at;
}
}

export class DocumentInfo extends FileInfo {
constructor(
id: string,
name: string,
data: { type: string; data: [] },
created_at: string,
updated_at: string
) {
super(id, name, data, created_at, updated_at);
constructor(info) {
super(info);
}
}

Expand All @@ -48,18 +36,10 @@ export class Assignment extends FileInfo {
due_date: string;
progress: AssignmentProgress;

constructor(
id: string,
name: string,
data: { type: string; data: [] },
created_at: string,
updated_at: string,
due_date: string,
progress: AssignmentProgress
) {
super(id, name, data, created_at, updated_at);
this.due_date = due_date;
this.progress = progress;
constructor(info) {
super(info);
this.due_date = info.due_date;
this.progress = AssignmentProgress[info.progress as keyof typeof AssignmentProgress];
}
}

Expand Down Expand Up @@ -108,14 +88,9 @@ export async function updateAssignments() {
if (!response) {
throw new Error('Could not update assignments due to no response');
}
const json = await response.json().map((it) => ({ ...it, type: 'Assignment' }));
const json = await response.json();

assignmentStore.set(
json.map((it) => ({
...it,
type: 'Assignment'
}))
);
assignmentStore.set(json.map((assignmentInfo) => new Assignment(assignmentInfo)));
console.log('updated assignments', json);
}

Expand Down
4 changes: 3 additions & 1 deletion src/routes/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FileInfo } from '@/api/apiStore';
import { Assignment, type FileInfo } from '@/api/apiStore';
import { writable } from 'svelte/store';

export const themeVariant = writable(localStorage.getItem('themeVariant') || 'light');
Expand All @@ -8,3 +8,5 @@ themeVariant.subscribe((value) => {
});

export const activeFile = writable<FileInfo | null>(null);

activeFile.set(new Assignment({}));

0 comments on commit 31bd144

Please sign in to comment.