diff --git a/frontend/src/routes/dashboard/+page.svelte b/frontend/src/routes/dashboard/+page.svelte index 7dcb68f..c08caa5 100644 --- a/frontend/src/routes/dashboard/+page.svelte +++ b/frontend/src/routes/dashboard/+page.svelte @@ -12,25 +12,22 @@ let fullName = ""; let email = ""; - $: if ($candidateData === undefined) { + $: if ($candidateData) { + fullName = ($candidateData.name ?? "") + " " + ($candidateData.surname ?? ""); + email = $candidateData.email ?? ""; + } + + $: if ($candidateData.name === undefined) { fetch(); - } else { - setNameEmail(); } const fetch = async () => { try { await fetchDetails(); - setNameEmail(); } catch { console.error("error"); } } - - const setNameEmail = async () => { - fullName = $candidateData.name + " " + $candidateData.surname; - email = $candidateData.email ?? "!Nevyplněné údaje!"; - } diff --git a/frontend/src/stores/candidate.ts b/frontend/src/stores/candidate.ts index 6a5e71e..aeee6e9 100644 --- a/frontend/src/stores/candidate.ts +++ b/frontend/src/stores/candidate.ts @@ -1,6 +1,6 @@ import { apiFetchDetails, apiFillDetails, apiLogin, apiLogout } from "../@api/candidate"; import { writable } from "svelte/store"; -import type { ApiError } from "src/@api"; +import { browser } from "$app/environment"; export interface CandidateData { name?: string; @@ -25,7 +25,29 @@ export interface CandidateLogin { password: string; } -export const candidateData = writable(); +export const candidateData = writable({}); + + +if (browser) { + const name = localStorage.getItem("name"); + const surname = localStorage.getItem("surname"); + const email = localStorage.getItem("email"); + if (name && email && surname) { + candidateData.set({ + name, + surname, + email + }); + } +} +candidateData.subscribe((val) => { + if (browser) { + localStorage.setItem("name", val.name ?? ""); + localStorage.setItem("surname", val.surname ?? ""); + localStorage.setItem("email", val.email ?? ""); + } +}) + export async function login(data: CandidateLogin) { // TODO: handle errors