From 008862f8a2431c8f755a38a0ef242b8faf125057 Mon Sep 17 00:00:00 2001
From: ivar <i@oiee.no>
Date: Thu, 11 Dec 2025 00:44:59 +0100
Subject: WIP! Restructure

---
 app/src/routes/+page.svelte | 69 +++++++++++++++++----------------------------
 1 file changed, 26 insertions(+), 43 deletions(-)

(limited to 'app/src/routes/+page.svelte')

diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte
index 005eb34..e89df9b 100644
--- a/app/src/routes/+page.svelte
+++ b/app/src/routes/+page.svelte
@@ -1,68 +1,51 @@
 <script lang="ts">
     import Button from "$lib/ui/button.svelte";
-    import {
-        clearTokens,
-        createSb1SyncSessionAndReturnLoginUrl,
-        getAccounts,
-        getTokenExpires,
-        getTransactions,
-        refreshSB1Token,
-    } from "./sb1.remote";
+    import { onMount } from "svelte";
+    import { clear_auth_session, get_accounts, get_transactions, init_auth_session, is_ready } from "./sb1.remote";
+    import { get_actual_meta } from "./actual.remote";
 
     let navigating = $state(false);
 
     async function authorize() {
         navigating = true;
-        const url = await createSb1SyncSessionAndReturnLoginUrl();
+        const url = await init_auth_session();
         location.href = url;
         navigating = false;
     }
 
-    async function clearAuth() {
-        await clearTokens();
-        getTokenExpires().refresh();
+    async function logout() {
+        await clear_auth_session();
     }
 
-    async function refreshAuth() {
-        await refreshSB1Token();
-        getTokenExpires().refresh();
-    }
-
-    async function initActual() {
-        await initActual()
-    }
+    onMount(async () => {
+        await get_actual_meta();
+    });
 </script>
 
 <main>
-    {#if await getTokenExpires()}
-        {@const tokens = await getTokenExpires()}
-        {@const accounts = await getAccounts()}
-        {#if tokens}
-            <pre>accessToken: {tokens.accessToken.created.add({ seconds: tokens.accessToken.expires }).toLocaleString()}
-refreshToken: {tokens.refreshToken.created.add({ seconds: tokens.refreshToken.expires }).toLocaleString()}</pre>
-            <ul>
-                {#each accounts?.accounts as account}
-                    {@const transactions = await getTransactions(account.key)}
-                    <li>{account.name}</li>
+    {#if await is_ready()}
+        {@const accounts = await get_accounts()}
+        {@const actual_meta = await get_actual_meta()}
+        {#if accounts}
+            {#each accounts?.accounts as account}
+                {@const transactions = await get_transactions(account.key)}
+                <li>{account.name}</li>
+                {#if transactions?.length}
                     <ul>
-                        {#each transactions?.transactions as transaction}
+                        {#each transactions as transaction}
                             <li>{JSON.stringify(transaction)}</li>
                         {/each}
                     </ul>
-                {/each}
-            </ul>
-            <Button onclick={clearAuth}>Slett autorisasjon</Button>
-            <Button onclick={refreshAuth}>Oppdater autorisasjon</Button>
-            <Button></Button>
+                {:else}
+                    <small>Ingen transaksjoner</small>
+                {/if}
+            {/each}
         {/if}
+        {#if actual_meta}
+            <pre>{JSON.stringify(actual_meta, null, 2)}</pre>
+        {/if}
+        <Button onclick={logout}>Logg ut</Button>
     {:else}
         <Button onclick={authorize} loading={navigating}>Autentisér hos Sparebanken 1</Button>
     {/if}
 </main>
-
-<style>
-    pre {
-        max-width: 50vw;
-        overflow: auto;
-    }
-</style>
-- 
cgit v1.3

