huge refactor. addresses #21 w/ inifinite scrolling notifications

This commit is contained in:
ari melody 2024-07-03 22:00:32 +01:00
parent f883b61659
commit 2e64f63caa
Signed by: ari
GPG key ID: CF99829C92678188
29 changed files with 887 additions and 1030 deletions

View file

@ -1,42 +1,48 @@
<script>
import { client } from '$lib/client/client.js';
import * as api from '$lib/api.js';
import { server } from '$lib/client/server.js';
import { app } from '$lib/client/app.js';
import { parseAccount } from '$lib/account.js';
import { get } from 'svelte/store';
import { goto } from '$app/navigation';
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';
import { last_read_notif_id } from '$lib/notifications.js';
import { logged_in, user, getUser } from '$lib/stores/user.js';
import { unread_notif_count, last_read_notif_id } from '$lib/notifications.js';
import { logged_in, account } from '$lib/stores/account.js';
export let data;
let auth_code = data.code;
if (!auth_code) {
if (!auth_code || !get(server) || !get(app)) {
error(400, { message: "Bad request" });
} else {
get(client).getToken(auth_code).then(token => {
api.getToken(get(server).host, get(app).id, get(app).secret, auth_code).then(token => {
if (!token) {
error(400, { message: "Invalid auth code provided" });
return;
}
client.update(c => {
c.app.token = token;
c.save();
return c;
app.update(app => {
app.token = token;
return app;
});
getUser().then(new_user => {
if (!new_user) return;
api.verifyCredentials(get(server).host, get(app).token).then(data => {
if (!data) return goto("/");
account.set(parseAccount(data));
logged_in.set(true);
user.set(new_user);
console.log(`Logged in as @${get(account).username}@${get(account).host}`);
return get(client).getNotifications(
// spin up async task to fetch notifications
return api.getNotifications(
get(server).host,
get(app).token,
get(last_read_notif_id)
).then(notif_data => {
unread_notif_count.set(0);
if (notif_data.constructor === Array && notif_data.length > 0)
last_read_notif_id.set(notif_data[0].id);
get(client).save();
goto("/");
});
});