Skip to content

Commit

Permalink
Refactor/remove index uni (#9)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
kojofl and kojofl authored Feb 22, 2023
1 parent 5f36a5e commit 213e91a
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 160 deletions.
4 changes: 1 addition & 3 deletions packages/demo-frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "/"}`);
Expand Down
18 changes: 2 additions & 16 deletions packages/school-frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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);
});
Expand Down
56 changes: 31 additions & 25 deletions packages/university-frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -20,7 +18,7 @@
} from "./store";
$: parsed = parse($querystring!);
let stateIndex = 0;
console.log($location);
onMount(async () => {
try {
Expand All @@ -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 ?? "/"}`);
Expand Down Expand Up @@ -87,22 +83,31 @@

<main>
<div class="story-container">
<div class="sidebar" style="width:25%"><Index index={stateIndex} /></div>
<div class="story-content">
{#if $siteConfig && $userInfo}
{#if $loggedIn !== undefined}
<Container>
{#if $loggedIn}
<NavbarLoggedIn userName={$userInfo.preferred_username} {siteConfig} />
<div class="row align-self-center">
<State bind:stateIndex />
</div>
{:else}
<NavbarLoggedOut {siteConfig} />
<div class="row align-self-center">
<Router {routes} />
</div>
{/if}
<div class="row align-self-center">
<div class={$location !== "/login" && $location !== "/register" ? "story" : ""}>
<div class={$location !== "/login" && $location !== "/register" ? "story-content" : ""}>
<Router
{routes}
on:conditionsFailed={async (event) => {
if (event.detail.route === "/login" || event.detail.route === "/register") {
await replace("/");
} else {
await replace(`/login?redirect=${event.detail.route !== "*" ? event.detail.route : "/"}`);
}
}}
/>
</div>
</div>
</div>
</Container>
{/if}
{/if}
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
19 changes: 10 additions & 9 deletions packages/university-frontend/src/components/application.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script lang="ts">
import axios from "axios";
import { onMount } from "svelte";
import { replace } from "svelte-spa-router";
import { Button, FormGroup, Image, Input, Progress } from "sveltestrap";
import { application, applicationRequestStatus, Status, userInfo } from "../store";
export let stateIndex: number;
let imageBuffer: string;
Expand Down Expand Up @@ -53,7 +53,7 @@
<h2 class="display-1">Daten zur Person</h2>
<hr />

<form>
<form on:submit|preventDefault={async () => await replace("/final")}>
<h3>Persönlicher Daten</h3>
<br />
<FormGroup floating label="Vorname*">
Expand All @@ -72,13 +72,14 @@
$application.birthDate.day
)}`
: ""}
required
/>
</FormGroup>
<FormGroup floating label="Geburtsland*">
<Input id="birth_country" name="Geburtsland" value={$application.birthPlace?.country ?? ""} />
<Input id="birth_country" name="Geburtsland" value={$application.birthPlace?.country ?? ""} required />
</FormGroup>
<FormGroup floating label="Staatsangehörigkeit*">
<Input id="nationality" name="Staatsangehörigkeit" value={$application.nationality ?? ""} />
<Input id="nationality" name="Staatsangehörigkeit" value={$application.nationality ?? ""} required />
</FormGroup>
<FormGroup floating label="Geschlecht*">
<select id="gender" class="form-select form-select-sm" aria-label=".form-select-sm example" required>
Expand All @@ -93,24 +94,24 @@

<h3>Addresse</h3>
<FormGroup floating label="Straße, Hausnummer*">
<Input id="street_num" name="StraßeNummer" value={$application.streetAddress?.houseNumber ?? ""} />
<Input id="street_num" name="StraßeNummer" value={$application.streetAddress?.houseNumber ?? ""} required />
</FormGroup>
<FormGroup floating label="PLZ*">
<Input id="zip" name="PLZ" value={$application.streetAddress?.zipCode ?? ""} />
<Input id="zip" name="PLZ" value={$application.streetAddress?.zipCode ?? ""} required />
</FormGroup>
<FormGroup floating label="Ort*">
<Input id="place" name="Ort" value={$application.streetAddress?.city ?? ""} />
<Input id="place" name="Ort" value={$application.streetAddress?.city ?? ""} required />
</FormGroup>
<FormGroup floating label="Land*">
<Input id="country" name="Land" value={$application.streetAddress?.country ?? ""} />
<Input id="country" name="Land" value={$application.streetAddress?.country ?? ""} required />
</FormGroup>
<FormGroup floating label="Telefon">
<Input id="telefone" name="Telefon" value={$application.phoneNumber ?? ""} />
</FormGroup>
<br />

<FormGroup>
<Button type="submit" color="primary" block on:click={() => stateIndex++}>Weiter</Button>
<Button type="submit" color="primary" block>Weiter</Button>
</FormGroup>
</form>
</div>
Expand Down
10 changes: 0 additions & 10 deletions packages/university-frontend/src/components/final.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { onMount } from "svelte";
import { Button, Container, Image } from "sveltestrap";
import { userInfo } from "../store";
export let stateIndex: number;
let imageBuffer: string;
Expand Down Expand Up @@ -73,11 +72,6 @@
font-weight: bold;
}
h3 {
color: #0158ab;
font-size: 20px;
}
.update {
padding: 24px;
top: 10vh;
Expand All @@ -90,8 +84,4 @@
padding: 0 18px;
margin: auto;
}
a {
color: white;
}
</style>
29 changes: 0 additions & 29 deletions packages/university-frontend/src/components/index.svelte

This file was deleted.

10 changes: 2 additions & 8 deletions packages/university-frontend/src/components/landing.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
<script lang="ts">
import { replace } from "svelte-spa-router";
import { Button, Container } from "sveltestrap";
import { userInfo } from "../store";
export let stateIndex: number;
</script>

<Container>
<h1 class="display-1">Hello {$userInfo.given_name ? $userInfo.given_name : $userInfo.preferred_username}</h1>
<div>
Starte deine Bewerbung zur Immatrikulation für das Fach Bachelor of Science Informatik an der Muster Hochschule.
<br /><Button color="primary" on:click={() => stateIndex++}>Start</Button>
<br /><Button color="primary" on:click={async () => await replace("/application")}>Start</Button>
</div></Container
>

<style>
code:hover {
cursor: pointer;
}
mark:hover {
cursor: pointer;
}
div {
text-align: left;
}
Expand Down
51 changes: 0 additions & 51 deletions packages/university-frontend/src/components/state.svelte

This file was deleted.

Loading

0 comments on commit 213e91a

Please sign in to comment.