mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-27 05:51:56 +00:00
feat: local storage
This commit is contained in:
parent
bfa04e0206
commit
ffba0bc828
2 changed files with 30 additions and 11 deletions
|
|
@ -12,25 +12,22 @@
|
||||||
let fullName = "";
|
let fullName = "";
|
||||||
let email = "";
|
let email = "";
|
||||||
|
|
||||||
$: if ($candidateData === undefined) {
|
$: if ($candidateData) {
|
||||||
|
fullName = ($candidateData.name ?? "") + " " + ($candidateData.surname ?? "");
|
||||||
|
email = $candidateData.email ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if ($candidateData.name === undefined) {
|
||||||
fetch();
|
fetch();
|
||||||
} else {
|
|
||||||
setNameEmail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
try {
|
try {
|
||||||
await fetchDetails();
|
await fetchDetails();
|
||||||
setNameEmail();
|
|
||||||
} catch {
|
} catch {
|
||||||
console.error("error");
|
console.error("error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const setNameEmail = async () => {
|
|
||||||
fullName = $candidateData.name + " " + $candidateData.surname;
|
|
||||||
email = $candidateData.email ?? "!Nevyplněné údaje!";
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FullLayout>
|
<FullLayout>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { apiFetchDetails, apiFillDetails, apiLogin, apiLogout } from "../@api/candidate";
|
import { apiFetchDetails, apiFillDetails, apiLogin, apiLogout } from "../@api/candidate";
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
import type { ApiError } from "src/@api";
|
import { browser } from "$app/environment";
|
||||||
|
|
||||||
export interface CandidateData {
|
export interface CandidateData {
|
||||||
name?: string;
|
name?: string;
|
||||||
|
|
@ -25,7 +25,29 @@ export interface CandidateLogin {
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const candidateData = writable<CandidateData>();
|
export const candidateData = writable<CandidateData>({});
|
||||||
|
|
||||||
|
|
||||||
|
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) {
|
export async function login(data: CandidateLogin) {
|
||||||
// TODO: handle errors
|
// TODO: handle errors
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue