mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +00:00
feat: filtering
This commit is contained in:
parent
21d7ca9118
commit
0532a705a7
2 changed files with 35 additions and 12 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
</script>
|
||||
|
||||
{#if createCandidateModal}
|
||||
<CreateCandidateModal on:created={getCandidates} on:close={() => (createCandidateModal = false)} />
|
||||
<CreateCandidateModal
|
||||
on:created={getCandidates}
|
||||
on:close={() => (createCandidateModal = false)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
|
|
@ -52,7 +73,7 @@
|
|||
{#each filters as filter}
|
||||
<div class:selected={filter === activeFilter}>
|
||||
<Home />
|
||||
<button on:click={() => (activeFilter = filter)}>{filter}</button>
|
||||
<button on:click={() => changeFilter(filter)}>{filter}</button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
|
@ -95,9 +116,7 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
{#each candidates as candidate}
|
||||
<tr
|
||||
class="border-b bg-white hover:cursor-pointer"
|
||||
>
|
||||
<tr class="border-b bg-white hover:cursor-pointer">
|
||||
<td class="whitespace-nowrap px-6 py-4 text-sm text-gray-900"
|
||||
><a
|
||||
target="_blank"
|
||||
|
|
|
|||
Loading…
Reference in a new issue