2024-06-29 17:27:46 +01:00
|
|
|
<script>
|
2024-06-29 19:52:52 +01:00
|
|
|
import '$lib/app.css';
|
2024-06-29 17:27:46 +01:00
|
|
|
import Navigation from '$lib/ui/Navigation.svelte';
|
|
|
|
import Widgets from '$lib/ui/Widgets.svelte';
|
2024-07-01 03:41:02 +01:00
|
|
|
import { client, Client } from '$lib/client/client.js';
|
2024-07-02 20:21:34 +01:00
|
|
|
import { user, getUser } from '$lib/stores/user.js';
|
2024-06-30 21:39:37 +01:00
|
|
|
import { get } from 'svelte/store';
|
2024-07-02 19:38:20 +01:00
|
|
|
import { logged_in } from '$lib/stores/user.js';
|
|
|
|
import { unread_notif_count, last_read_notif_id } from '$lib/notifications.js';
|
2024-07-02 12:36:26 +01:00
|
|
|
|
2024-07-01 03:41:02 +01:00
|
|
|
let ready = new Promise(resolve => {
|
|
|
|
if (get(client)) {
|
2024-07-02 20:21:34 +01:00
|
|
|
if (get(user)) logged_in.set(true);
|
2024-07-01 03:41:02 +01:00
|
|
|
return resolve();
|
|
|
|
}
|
|
|
|
let new_client = new Client();
|
|
|
|
new_client.load();
|
2024-07-02 12:36:26 +01:00
|
|
|
client.set(new_client);
|
2024-07-01 03:41:02 +01:00
|
|
|
|
2024-07-02 20:21:34 +01:00
|
|
|
return getUser().then(new_user => {
|
|
|
|
if (!new_user) return resolve();
|
|
|
|
|
|
|
|
logged_in.set(true);
|
|
|
|
user.set(new_user);
|
2024-07-02 19:38:20 +01:00
|
|
|
|
|
|
|
// spin up async task to fetch notifications
|
|
|
|
get(client).getNotifications(
|
|
|
|
get(last_read_notif_id)
|
|
|
|
).then(notif_data => {
|
|
|
|
if (!notif_data) return;
|
|
|
|
unread_notif_count.set(notif_data.length);
|
|
|
|
});
|
|
|
|
|
2024-07-01 03:41:02 +01:00
|
|
|
return resolve();
|
|
|
|
});
|
|
|
|
});
|
2024-06-29 17:27:46 +01:00
|
|
|
</script>
|
|
|
|
|
2024-06-30 17:37:19 +01:00
|
|
|
<div id="app">
|
2024-06-29 17:27:46 +01:00
|
|
|
|
|
|
|
<header>
|
2024-07-02 19:38:20 +01:00
|
|
|
<Navigation />
|
2024-06-29 17:27:46 +01:00
|
|
|
</header>
|
|
|
|
|
|
|
|
<main>
|
2024-07-01 03:41:02 +01:00
|
|
|
{#await ready}
|
2024-06-30 21:39:37 +01:00
|
|
|
<div class="loading throb">
|
|
|
|
<span>just a moment...</span>
|
|
|
|
</div>
|
|
|
|
{:then}
|
|
|
|
<slot></slot>
|
|
|
|
{/await}
|
2024-06-29 17:27:46 +01:00
|
|
|
</main>
|
|
|
|
|
|
|
|
<div id="widgets">
|
|
|
|
<Widgets />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
2024-07-01 03:41:02 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.loading {
|
|
|
|
width: 100%;
|
|
|
|
height: 100vh;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
font-size: 2em;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
</style>
|