From d0112c2bdc2e4e0d3bc6652e8c70c7c27cab3332 Mon Sep 17 00:00:00 2001 From: EETagent Date: Sun, 4 Dec 2022 23:34:36 +0100 Subject: [PATCH] feat: ssr for candidate details, own page, refactoring --- .../CandidateDetails.svelte | 0 .../{dashboard => list}/ListElement.svelte | 0 .../[code=application]/+page.server.ts | 20 +++++++++++++++++++ .../candidate/[code=application]/+page.svelte | 11 ++++++++++ .../{+layout.server.ts => +page.server.ts} | 4 ++-- .../(authenticated)/dashboard/+page.svelte | 13 ++---------- 6 files changed, 35 insertions(+), 13 deletions(-) rename frontend/src/lib/components/{dashboard => list}/CandidateDetails.svelte (100%) rename frontend/src/lib/components/{dashboard => list}/ListElement.svelte (100%) create mode 100644 frontend/src/routes/(admin)/admin/(authenticated)/candidate/[code=application]/+page.server.ts create mode 100644 frontend/src/routes/(admin)/admin/(authenticated)/candidate/[code=application]/+page.svelte rename frontend/src/routes/(admin)/admin/(authenticated)/dashboard/{+layout.server.ts => +page.server.ts} (73%) diff --git a/frontend/src/lib/components/dashboard/CandidateDetails.svelte b/frontend/src/lib/components/list/CandidateDetails.svelte similarity index 100% rename from frontend/src/lib/components/dashboard/CandidateDetails.svelte rename to frontend/src/lib/components/list/CandidateDetails.svelte diff --git a/frontend/src/lib/components/dashboard/ListElement.svelte b/frontend/src/lib/components/list/ListElement.svelte similarity index 100% rename from frontend/src/lib/components/dashboard/ListElement.svelte rename to frontend/src/lib/components/list/ListElement.svelte diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/candidate/[code=application]/+page.server.ts b/frontend/src/routes/(admin)/admin/(authenticated)/candidate/[code=application]/+page.server.ts new file mode 100644 index 0000000..49b7ee6 --- /dev/null +++ b/frontend/src/routes/(admin)/admin/(authenticated)/candidate/[code=application]/+page.server.ts @@ -0,0 +1,20 @@ +import { apiFetchCandidate } from '$lib/@api/admin'; +import type { CandidateData } from '$lib/stores/candidate'; +import type { PageServerLoad } from './$types'; + +export const load: PageServerLoad = async ({ fetch, params }) => { + const { code } = params; + const codeNumber = Number(code); + + let candidateData: CandidateData = {}; + try { + candidateData = await apiFetchCandidate(codeNumber, fetch); + } catch (e) { + console.error(e); + } + + return { + id: codeNumber, + candidate: candidateData + }; +}; diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/candidate/[code=application]/+page.svelte b/frontend/src/routes/(admin)/admin/(authenticated)/candidate/[code=application]/+page.svelte new file mode 100644 index 0000000..6f83319 --- /dev/null +++ b/frontend/src/routes/(admin)/admin/(authenticated)/candidate/[code=application]/+page.svelte @@ -0,0 +1,11 @@ + + + + + diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+layout.server.ts b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.server.ts similarity index 73% rename from frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+layout.server.ts rename to frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.server.ts index 27927e4..6dc03b4 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+layout.server.ts +++ b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.server.ts @@ -1,8 +1,8 @@ import { apiListCandidates } from '$lib/@api/admin'; import type { CandidatePreview } from '$lib/stores/candidate'; -import type { LayoutServerLoad } from './$types'; +import type { PageServerLoad } from './$types'; -export const load: LayoutServerLoad = async ({ fetch }) => { +export const load: PageServerLoad = async ({ fetch }) => { let candidatePreview: [CandidatePreview] = [{}]; try { candidatePreview = await apiListCandidates(fetch); diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte index 76823a7..3b5be2f 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte +++ b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte @@ -3,7 +3,7 @@ import Home from '$lib/components/icons/Home.svelte'; import TextField from '$lib/components/textfield/TextField.svelte'; import type { CandidateData, CandidatePreview } from '$lib/stores/candidate'; - import CandidateDetails from '$lib/components/dashboard/CandidateDetails.svelte'; + import CandidateDetails from '$lib/components/list/CandidateDetails.svelte'; import { onMount } from 'svelte'; import type { PageData } from '../$types'; @@ -94,7 +94,7 @@ class="border-b bg-white hover:cursor-pointer" > {candidate.applicationId}{candidate.applicationId} {candidate.name} @@ -106,15 +106,6 @@ {candidate.study} - {#if candidateDetails.hasOwnProperty(candidate.applicationId)} -
- -
-
- {/if} {/each}