diff --git a/frontend/src/lib/@api/admin.ts b/frontend/src/lib/@api/admin.ts index 36164c7..860804d 100644 --- a/frontend/src/lib/@api/admin.ts +++ b/frontend/src/lib/@api/admin.ts @@ -70,16 +70,20 @@ export const apiLogout = async (fetchSsr?: Fetch) => { // SSR compatible // List all candidates /admin/list/candidates -export const apiListCandidates = async (fetchSsr?: Fetch): Promise<[CandidatePreview]> => { +export const apiListCandidates = async (fetchSsr?: Fetch, field?: string): Promise<[CandidatePreview]> => { + const params = new URLSearchParams(); + if (field) { + params.append('field', field); + } try { if (fetchSsr) { - const res = await fetchSsr(API_URL + '/admin/list/candidates', { + const res = await fetchSsr(API_URL + '/admin/list/candidates?' + params.toString(), { method: 'GET', credentials: 'include' }); return await res.json(); } - const res = await axios.get(API_URL + '/admin/list/candidates', { + const res = await axios.get(API_URL + '/admin/list/candidates?' + params.toString(), { withCredentials: true }); return res.data; diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte index 5b002f4..d7f53f9 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte +++ b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte @@ -18,14 +18,13 @@ candidates = data.preview; }); - const getCandidates = async () => { + const getCandidates = async (field?: string) => { try { - candidates = await apiListCandidates(); + candidates = await apiListCandidates(undefined, field); } catch { console.log('error'); } - } - + }; type Filter = 'Vše' | 'KBB' | 'IT' | 'GYM'; @@ -33,6 +32,25 @@ let activeFilter: Filter = 'Vše'; + const changeFilter = (filter: Filter) => { + activeFilter = filter; + switch (activeFilter) { + case 'Vše': + getCandidates(); + break; + case 'KBB': + getCandidates('KB'); + break; + case 'IT': + getCandidates('IT'); + break; + case 'GYM': + getCandidates('G'); + break; + } + }; + + let scrollTop = 0; let createCandidateModal: boolean = false; @@ -43,7 +61,10 @@ {#if createCandidateModal} - (createCandidateModal = false)} /> + (createCandidateModal = false)} + /> {/if}
@@ -52,7 +73,7 @@ {#each filters as filter}
- +
{/each}
@@ -95,9 +116,7 @@ {#each candidates as candidate} - +