working on project list update by event
This commit is contained in:
@@ -1,19 +1,26 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
|
||||
import { api } from '../../urls.svelte.js';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { api, eventStream } from '../../urls.svelte.js';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
|
||||
const router = useTinyRouter();
|
||||
let events = null;
|
||||
let projects = $state(null);
|
||||
let companies = $state(null);
|
||||
let showClosed = $state(router.query.closed == "show");
|
||||
|
||||
let sortedProjects = $derived.by(() => Object.values(projects).sort((a, b) => a.name.localeCompare(b.name)));
|
||||
|
||||
function handleUpdate(evt){
|
||||
let json = JSON.parse(evt.data);
|
||||
if (json.project) projects[json.project.id] = json.project;
|
||||
}
|
||||
|
||||
async function loadProjects(){
|
||||
events = eventStream(handleUpdate,handleUpdate,null);
|
||||
let url = api('company/list');
|
||||
let resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
@@ -66,6 +73,9 @@
|
||||
}
|
||||
|
||||
onMount(loadProjects);
|
||||
onDestroy(() => {
|
||||
if (events) events.close();
|
||||
})
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
Reference in New Issue
Block a user