Frontend display countries option

This commit is contained in:
Cristian Ditaputratama 2024-05-06 13:59:33 +07:00
parent 59b368d91e
commit 3acfdd2905
Signed by: ditatompel
GPG key ID: 31D3D06D77950979
2 changed files with 14 additions and 4 deletions

View file

@ -1,7 +1,7 @@
<script> <script>
import { DataHandler } from '@vincjo/datatables/remote'; import { DataHandler } from '@vincjo/datatables/remote';
import { format, formatDistance } from 'date-fns'; import { format, formatDistance } from 'date-fns';
import { loadData } from './api-handler'; import { loadData, loadCountries } from './api-handler';
import { onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import { import {
DtSrRowsPerPage, DtSrRowsPerPage,
@ -27,6 +27,9 @@
let filterStatus = -1; let filterStatus = -1;
let checkboxCors = false; let checkboxCors = false;
/** @type {{total_nodes: number, cc: string, name: string}[]} */
let countries = [];
const handler = new DataHandler([], { rowsPerPage: 10, totalRows: 0 }); const handler = new DataHandler([], { rowsPerPage: 10, totalRows: 0 });
let rows = handler.getRows(); let rows = handler.getRows();
@ -109,6 +112,9 @@
clearInterval(intervalId); // Clear the interval when the component is destroyed clearInterval(intervalId); // Clear the interval when the component is destroyed
}); });
onMount(() => { onMount(() => {
loadCountries().then((data) => {
countries = data;
});
handler.onChange((state) => loadData(state)); handler.onChange((state) => loadData(state));
handler.invalidate(); handler.invalidate();
}); });
@ -233,8 +239,7 @@
}} }}
> >
<option value="any">Any</option> <option value="any">Any</option>
<!-- {#each countries as country}
{#each data.countries as country}
{#if country.cc === ''} {#if country.cc === ''}
<option value="UNKNOWN">UNKNOWN ({country.total_nodes})</option> <option value="UNKNOWN">UNKNOWN ({country.total_nodes})</option>
{:else} {:else}
@ -243,7 +248,6 @@
> >
{/if} {/if}
{/each} {/each}
-->
</select> </select>
</th> </th>
<th colspan="2"> <th colspan="2">

View file

@ -8,6 +8,12 @@ export const loadData = async (state) => {
return json.data.items ?? []; return json.data.items ?? [];
}; };
export const loadCountries = async () => {
const response = await fetch(apiUri('/api/v1/countries'));
const json = await response.json();
return json.data ?? [];
};
const getParams = ({ pageNumber, rowsPerPage, sort, filters }) => { const getParams = ({ pageNumber, rowsPerPage, sort, filters }) => {
let params = `page=${pageNumber}&limit=${rowsPerPage}`; let params = `page=${pageNumber}&limit=${rowsPerPage}`;