From a9072370ca1eb9a5cce928b1d487db0f307edea6 Mon Sep 17 00:00:00 2001
From: ivarlovlie <git@ivarlovlie.no>
Date: Tue, 20 Sep 2022 15:24:27 +0800
Subject: feat: Move old apps into it's own directory

---
 old-apps/portal/src/app/index.svelte | 87 ++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 old-apps/portal/src/app/index.svelte

(limited to 'old-apps/portal/src/app/index.svelte')

diff --git a/old-apps/portal/src/app/index.svelte b/old-apps/portal/src/app/index.svelte
new file mode 100644
index 0000000..af2b6d0
--- /dev/null
+++ b/old-apps/portal/src/app/index.svelte
@@ -0,0 +1,87 @@
+<svelte:options immutable={true}/>
+<svelte:window bind:online={online}/>
+
+<script>
+    import Router, {replace} from "svelte-spa-router";
+    import {wrap} from "svelte-spa-router/wrap";
+    import {is_active} from "$shared/lib/session";
+    import SignUp from "$app/pages/sign-up.svelte";
+    import Login from "$app/pages/login.svelte";
+    import Forgot from "$app/pages/forgot.svelte";
+    import Reset from "$app/pages/reset-password.svelte";
+    import Home from "$app/pages/home.svelte";
+    import ProfileHome from "$app/pages/profile/index.svelte";
+    import AdminHome from "$app/pages/admin/index.svelte";
+    import PreHeader from "$shared/components/pre-header.svelte";
+
+    let online = true;
+
+    const publicRoutes = ["/login", "/signup", "/reset-password", "/forgot"];
+    const guardedRoutes = ["/", "/home", "/profile", "/admin"];
+
+    async function user_is_logged_in(event) {
+        const isActive = await is_active();
+        if (!isActive && !publicRoutes.includes(event.route)) {
+            return false;
+        }
+        if (isActive && !guardedRoutes.includes(event.route)) {
+            await replace("/");
+        }
+        return true;
+    }
+
+    function route_guarded(event) {
+        if (!publicRoutes.includes(event.detail.route)) {
+            replace("/login");
+        }
+    }
+
+    const routes = {
+        "/login": wrap({
+            component: Login,
+            conditions: [user_is_logged_in],
+        }),
+        "/home": wrap({
+            component: Home,
+            conditions: [user_is_logged_in],
+        }),
+        "/admin": wrap({
+            component: AdminHome,
+            conditions: [user_is_logged_in],
+        }),
+        "/profile": wrap({
+            component: ProfileHome,
+            conditions: [user_is_logged_in],
+        }),
+        "/": wrap({
+            component: Home,
+            conditions: [user_is_logged_in],
+        }),
+        "/signup": wrap({
+            component: SignUp,
+            conditions: [user_is_logged_in],
+        }),
+        "/reset-password": wrap({
+            component: Reset,
+            conditions: [user_is_logged_in],
+        }),
+        "/forgot": wrap({
+            component: Forgot,
+            conditions: [user_is_logged_in],
+        })
+    };
+</script>
+
+<PreHeader show="{!online}">You seem to be offline, please check your internet connection.</PreHeader>
+
+<Router
+        {routes}
+        restoreScrollState={true}
+        on:conditionsFailed={route_guarded}
+        on:routeLoading={() => {
+            document.getElementById("loader").style.display = "inline-block";
+        }}
+        on:routeLoaded={() => {
+            document.getElementById("loader").style.display = "none";
+        }}
+/>
-- 
cgit v1.3

