mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +00:00
refactor: remove stores no longer needed after SSR
This commit is contained in:
parent
fa8e109338
commit
8950f133bf
4 changed files with 6 additions and 74 deletions
|
|
@ -1,6 +1,4 @@
|
|||
import { apiFetchDetails, apiFillDetails, apiLogin, apiLogout } from "../@api/candidate";
|
||||
import { writable } from "svelte/store";
|
||||
import { browser } from "$app/environment";
|
||||
|
||||
export interface CandidateData {
|
||||
name?: string;
|
||||
|
|
@ -25,67 +23,4 @@ export interface CandidateLogin {
|
|||
password: string;
|
||||
}
|
||||
|
||||
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) {
|
||||
// TODO: handle errors
|
||||
try {
|
||||
const applicationId = await apiLogin(data); // TODO: set candidate data from response to store
|
||||
console.log("login result: " + applicationId);
|
||||
} catch (e) {
|
||||
console.error("login failed");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export async function logout() {
|
||||
// TOOD: handle errors
|
||||
try {
|
||||
await apiLogout();
|
||||
candidateData.set({});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function fillDetails(data: CandidateData) {
|
||||
try {
|
||||
const res = await apiFillDetails(data);
|
||||
candidateData.set(res);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchDetails() {
|
||||
try {
|
||||
const res = await apiFetchDetails();
|
||||
candidateData.set(res);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
export const candidateData = writable<CandidateData>({});
|
||||
|
|
@ -18,7 +18,7 @@ export const submissionProgress = writable<SubmissionProgress>({});
|
|||
|
||||
export async function fetchSubmProgress() {
|
||||
try {
|
||||
let prog = await apiFetchSubmissionProgress();
|
||||
const prog = await apiFetchSubmissionProgress();
|
||||
submissionProgress.set(prog);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { apiFillDetails } from '$lib/@api/candidate';
|
||||
|
||||
import Email from '$lib/components/icons/Email.svelte';
|
||||
import Home from '$lib/components/icons/Home.svelte';
|
||||
|
|
@ -10,13 +11,9 @@
|
|||
import IdField from '$lib/components/textfield/IdField.svelte';
|
||||
import TelephoneField from '$lib/components/textfield/TelephoneField.svelte';
|
||||
import TextField from '$lib/components/textfield/TextField.svelte';
|
||||
import { fillDetails, candidateData, type CandidateData } from '$lib/stores/candidate';
|
||||
|
||||
import { createForm } from 'svelte-forms-lib';
|
||||
import * as yup from 'yup';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
let applicationValue = '';
|
||||
|
||||
const pageCount = 3;
|
||||
let pageIndex = 0;
|
||||
|
|
@ -67,7 +64,7 @@
|
|||
// @ts-ignore // love javascript
|
||||
delete values.undefined;
|
||||
values.birthdate = '2000-01-01' // TODO: reformat user typed date
|
||||
await fillDetails(values);
|
||||
await apiFillDetails(values);
|
||||
goto("/dashboard");
|
||||
} catch (e) {
|
||||
console.error("error while submitting data: " + e);
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
import woman from '$lib/assets/woman.png';
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { login } from '$lib/stores/candidate';
|
||||
import { goto } from '$app/navigation';
|
||||
import { apiLogin } from '$lib/@api/candidate';
|
||||
|
||||
|
||||
let applicationId = Number($page.params.code);
|
||||
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
async function submit() {
|
||||
try {
|
||||
await login({applicationId, password: codeValueMobile});
|
||||
await apiLogin({applicationId, password: codeValueMobile});
|
||||
goto("/dashboard");
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
|
|
|||
Loading…
Reference in a new issue