Skip to content

Commit

Permalink
move adduser to class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ell1ott committed Feb 29, 2024
1 parent 1273735 commit eca2476
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 16 additions & 2 deletions src/lib/api/apiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,26 @@ export class FileInfo {

apiPath: string = '/documents/';

getPath() {
return this.apiPath + this.id;
}

rename(newName: string, api: ApiHandler) {
return api.callApi(this.apiPath + this.id, { name: newName }, 'PUT');
return api.callApi(this.getPath(), { name: newName }, 'PUT');
}

delete(api: ApiHandler) {
return api.callApi(this.apiPath + this.id, {}, 'DELETE');
return api.callApi(this.getPath(), {}, 'DELETE');
}

addUser(user_email: string, api: ApiHandler) {
return api.callApi(
this.getPath() + '/users',
{
user_email
},
'PUT'
);
}

constructor(info) {
Expand Down
10 changes: 6 additions & 4 deletions src/routes/workspace/editor/Toolbar/ShareDocument.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { Separator } from '$lib/components/ui/separator';
import { getContext, onMount } from 'svelte';
import type ApiHandler from '@/api';
import { type FileInfo, currentFile } from '@/api/apiStore';
import { FileInfo, currentFile } from '@/api/apiStore';
const api = getContext('api') as ApiHandler;
Expand Down Expand Up @@ -100,9 +100,11 @@
if (!$currentFile) return;
var email = (document.getElementById('invite-email') as HTMLInputElement).value;
console.log(email);
api.addUserToDocument($currentFile?.id, email).then((response) => {
console.log(response);
});
if ($currentFile instanceof FileInfo) {
$currentFile.addUser(email, api).then((response) => {
console.log(response);
});
}
}
</script>

Expand Down

0 comments on commit eca2476

Please sign in to comment.