From 213e91aee44ac7eaafa494bfe0d4cf04c7dd8ef2 Mon Sep 17 00:00:00 2001 From: Korbinian Flietel <63589691+kojofl@users.noreply.github.com> Date: Wed, 22 Feb 2023 13:41:08 +0100 Subject: [PATCH] Refactor/remove index uni (#9) * refactor: remove unused code * refactor: remove secondary session call * refactor: switch index based routing to hash based * fix: actually require fields in form * refactor: remove useless link --------- Co-authored-by: Korbinian Flietel --- packages/demo-frontend/src/App.svelte | 4 +- packages/school-frontend/src/App.svelte | 18 +----- packages/university-frontend/src/App.svelte | 56 ++++++++++--------- .../src/components/application.svelte | 19 ++++--- .../src/components/final.svelte | 10 ---- .../src/components/index.svelte | 29 ---------- .../src/components/landing.svelte | 10 +--- .../src/components/state.svelte | 51 ----------------- .../university-frontend/src/lib/routes.svelte | 32 ++++++++--- 9 files changed, 69 insertions(+), 160 deletions(-) delete mode 100644 packages/university-frontend/src/components/index.svelte delete mode 100644 packages/university-frontend/src/components/state.svelte diff --git a/packages/demo-frontend/src/App.svelte b/packages/demo-frontend/src/App.svelte index c6a0bc1..94b8b46 100755 --- a/packages/demo-frontend/src/App.svelte +++ b/packages/demo-frontend/src/App.svelte @@ -34,9 +34,7 @@ authorization: `Bearer ${keycloakTokens.access_token}` } }); - // This call is needed to make the session persistant if the user imedatiely leaves the site and returns. - // TODO: Why do we need this/how do we fix this? - await axios.get("api/v1/session"); + userInfo.set(u.data); loggedIn.set(true); await push(`${parsed.redirect ?? "/"}`); diff --git a/packages/school-frontend/src/App.svelte b/packages/school-frontend/src/App.svelte index 99bba60..145d03e 100755 --- a/packages/school-frontend/src/App.svelte +++ b/packages/school-frontend/src/App.svelte @@ -2,11 +2,11 @@ import axios from "axios"; import { parse } from "qs"; import { onMount } from "svelte"; - import Router, { push, querystring } from "svelte-spa-router"; + import Router, { querystring } from "svelte-spa-router"; import { Styles } from "sveltestrap"; import { io } from "./lib/realtime"; import { routes } from "./lib/routes.svelte"; - import { loggedIn, siteConfig, userInfo } from "./store"; + import { siteConfig } from "./store"; $: parsed = parse($querystring!); onMount(async () => { @@ -15,20 +15,6 @@ siteConfig.set(config.data); - io.on("register", async (keycloakTokens) => { - const u = await axios.post("api/v1/auth/login", null, { - headers: { - authorization: `Bearer ${keycloakTokens.access_token}` - } - }); - // This call is needed to make the session persistant if the user imedatiely leaves the site and returns. - // TODO: Why do we need this/how do we fix this? - await axios.get("api/v1/session"); - userInfo.set(u.data); - loggedIn.set(true); - await push(`${parsed.redirect ?? "/"}`); - }); - io.on("error", (e) => { alert(e); }); diff --git a/packages/university-frontend/src/App.svelte b/packages/university-frontend/src/App.svelte index 6f54d18..bf752e2 100644 --- a/packages/university-frontend/src/App.svelte +++ b/packages/university-frontend/src/App.svelte @@ -3,10 +3,8 @@ import axios from "axios"; import { parse } from "qs"; import { onMount } from "svelte"; - import Router, { push, querystring } from "svelte-spa-router"; + import Router, { location, push, querystring, replace } from "svelte-spa-router"; import { Container, Styles } from "sveltestrap"; - import Index from "./components/index.svelte"; - import State from "./components/state.svelte"; import { io } from "./lib/realtime"; import { routes } from "./lib/routes.svelte"; import { @@ -20,7 +18,7 @@ } from "./store"; $: parsed = parse($querystring!); - let stateIndex = 0; + console.log($location); onMount(async () => { try { @@ -46,9 +44,7 @@ authorization: `Bearer ${keycloakTokens.access_token}` } }); - // This call is needed to make the session persistant if the user imedatiely leaves the site and returns. - // TODO: Why do we need this/how do we fix this? - await axios.get("api/v1/session"); + userInfo.set(u.data); loggedIn.set(true); await push(`${parsed.redirect ?? "/"}`); @@ -87,22 +83,31 @@
-
{#if $siteConfig && $userInfo} {#if $loggedIn !== undefined} {#if $loggedIn} -
- -
{:else} -
- -
{/if} +
+
+
+ { + if (event.detail.route === "/login" || event.detail.route === "/register") { + await replace("/"); + } else { + await replace(`/login?redirect=${event.detail.route !== "*" ? event.detail.route : "/"}`); + } + }} + /> +
+
+
{/if} {/if} @@ -117,11 +122,18 @@ height: 100%; } - .sidebar { - border-right: 6px solid black; - flex: 15%; - background-color: lightgray; - padding: 2em; + .story { + position: relative; + min-height: 800px; + height: 100%; + } + + .story-content { + position: relative; + max-height: 90%; + height: 90%; + display: flex; + justify-content: center; } .story-container { @@ -137,12 +149,6 @@ padding: 0 2em; } - .story-state { - height: 95%; - min-height: 800px; - min-width: 600px; - } - @media (min-width: 640px) { main { max-width: none; diff --git a/packages/university-frontend/src/components/application.svelte b/packages/university-frontend/src/components/application.svelte index 09f02c5..fa660b1 100644 --- a/packages/university-frontend/src/components/application.svelte +++ b/packages/university-frontend/src/components/application.svelte @@ -1,9 +1,9 @@ - -

Inhalt

-
    -
  1. Login / Registration
  2. -
  3. Index
  4. -
  5. Bewerbung
  6. -
  7. Test
  8. -
- - diff --git a/packages/university-frontend/src/components/landing.svelte b/packages/university-frontend/src/components/landing.svelte index 3af0a28..e8744b8 100644 --- a/packages/university-frontend/src/components/landing.svelte +++ b/packages/university-frontend/src/components/landing.svelte @@ -1,24 +1,18 @@

Hello {$userInfo.given_name ? $userInfo.given_name : $userInfo.preferred_username}

Starte deine Bewerbung zur Immatrikulation für das Fach Bachelor of Science Informatik an der Muster Hochschule. -
+
diff --git a/packages/university-frontend/src/lib/routes.svelte b/packages/university-frontend/src/lib/routes.svelte index 0d3a049..408cf17 100644 --- a/packages/university-frontend/src/lib/routes.svelte +++ b/packages/university-frontend/src/lib/routes.svelte @@ -2,23 +2,19 @@ import { Login, Register } from "@js-soft/nmshd-login-demo-helper"; import { wrap } from "svelte-spa-router/wrap"; import { get } from "svelte/store"; + import Application from "../components/application.svelte"; + import Final from "../components/final.svelte"; + import Landing from "../components/landing.svelte"; import { keycloakInstance, loggedIn, siteConfig, userInfo } from "../store"; import { io } from "./realtime"; export const routes = { // eslint-disable-next-line @typescript-eslint/naming-convention "/": wrap({ - component: Login, - props: { - siteConfig, - keycloakInstance, - loggedIn, - userInfo, - socket: io - }, + component: Landing, conditions: [ (_detail: any) => { - return !get(loggedIn); + return !!get(loggedIn); } ] }), @@ -51,6 +47,24 @@ ] }), // eslint-disable-next-line @typescript-eslint/naming-convention + "/application": wrap({ + component: Application, + conditions: [ + (_detail: any) => { + return !!get(loggedIn); + } + ] + }), + // eslint-disable-next-line @typescript-eslint/naming-convention + "/final": wrap({ + component: Final, + conditions: [ + (_detail: any) => { + return !!get(loggedIn); + } + ] + }), + // eslint-disable-next-line @typescript-eslint/naming-convention "*": wrap({ component: Login, conditions: [