Skip to content

Commit

Permalink
Actually get assignments from server
Browse files Browse the repository at this point in the history
  • Loading branch information
arctixdev committed Feb 22, 2024
1 parent 121ee43 commit 98c443b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
Binary file modified bun.lockb
Binary file not shown.
27 changes: 26 additions & 1 deletion src/lib/api/apiStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { writable } from 'svelte/store';
import type ApiHandler from '.';
import type { AuthorizerState } from 'akademia-authorizer-svelte/types';
import { getContext } from 'svelte';

export interface FileInfo {
user_id: string;
Expand All @@ -11,7 +12,19 @@ export interface FileInfo {
id: string;
}

export async function updateFiles(api: ApiHandler) {
export interface Assignment {
id: string;
name: string;
created_at: string;
updated_at: string;
due_date: string;
assignment_document_id: string;
progress: number;
}

export async function updateFiles() {
const api = getContext('api') as ApiHandler;

const userDocuments = await api.getUserDocuments();
const userDocumentsJson = await userDocuments.json();
console.log(userDocumentsJson);
Expand Down Expand Up @@ -42,3 +55,15 @@ interface userInfo {
name: string;
}
export const userInfo = writable<userInfo>();

export const assignmentStore = writable<Assignment[]>([]);

export async function updateAssignments() {
const api = getContext('api') as ApiHandler;

const response = await api.getAssignments();
const json = await response.json();

assignmentStore.set(json);
console.log('updated assignments', json);
}
5 changes: 3 additions & 2 deletions src/routes/workspace/Workspace.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Sidebar from './Sidebar.svelte';
import type { Readable } from 'svelte/store';
import type { AuthorizerState } from 'akademia-authorizer-svelte/types';
import { updateFiles, updateUserInfo } from '@/api/apiStore';
import { updateFiles, updateUserInfo, updateAssignments } from '@/api/apiStore';
import ApiHandler from '@/api';
import SidebarAssignment from './SidebarAssignment.svelte';
Expand All @@ -20,7 +20,8 @@
});
const api = new ApiHandler(store);
setContext('api', api);
updateFiles(api);
updateFiles();
updateAssignments();
updateUserInfo($store);
var urlParams = new URLSearchParams(window.location.search);
Expand Down
27 changes: 17 additions & 10 deletions src/routes/workspace/home/activeFiles/ActiveFiles.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<script lang="ts">
import Assignment from './Assignment.svelte';
import ApiHandler from '$lib/api';
import { getContext, onMount } from 'svelte';
import { Notebook, Target, File } from 'lucide-svelte';
import { fileStore, userInfo } from '@/api/apiStore';
import { fileStore, userInfo, assignmentStore } from '@/api/apiStore';
let assignments: { name: string; progress: number }[] = [
{ name: 'beskrivende tekst', progress: 100 },
{ name: 'matematik aflevering', progress: 50 },
{ name: 'matematik aflevering', progress: 0 }
];
console.log($assignmentStore);
</script>

<div class="cont br-2 frontground">
Expand All @@ -19,9 +13,16 @@
Afleveringer
</h2>
<div class="filelist">
{#each assignments as assignment}
<Assignment name={assignment.name} progress={assignment.progress} date="3. jan"></Assignment>
{#each $assignmentStore as assignment}
<Assignment
name={assignment.name}
progress={assignment.progress}
date={new Date(assignment.due_date).toISOString()}
></Assignment>
{/each}
{#if $assignmentStore.length == 0}
<p class="">Der er ingen afleveringer</p>
{/if}
</div>
<h2>
<File />
Expand All @@ -31,6 +32,9 @@
{#each $fileStore as f}
<Assignment name={f.name} id={f.id}></Assignment>
{/each}
{#if $fileStore.length == 0}
<p class="">Der er ingen dokumenter</p>
{/if}
</div>
<h2>
<Notebook />
Expand All @@ -40,6 +44,9 @@
{#each $fileStore as f}
<Assignment name={f.name} id={f.id}></Assignment>
{/each}
{#if $fileStore.length == 0}
<p class="">Der er ingen noter</p>
{/if}
</div>
</div>

Expand Down

0 comments on commit 98c443b

Please sign in to comment.