mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-01 14:38:50 +00:00
refactor(web): wip pagination
This commit is contained in:
1 parent
3c199c2217
commit
e06c61d292
7 files changed
+51
-28
No files matched your search
@@ -1,7 +1,24 @@
|
||||
<script lang="ts">
|
||||
import { fetchNui } from '../../utils/fetchNui';
|
||||
import Pagination from './components/Pagination.svelte';
|
||||
import QueryTable from './components/QueryTable.svelte';
|
||||
import ResourceHeader from './components/ResourceHeader.svelte';
|
||||
import { meta } from 'tinro';
|
||||
import { useNuiEvent } from '../../utils/useNuiEvent';
|
||||
import { queries, type QueryData } from '../../store';
|
||||
|
||||
const route = meta();
|
||||
|
||||
let page = 0;
|
||||
let maxPage = 0;
|
||||
|
||||
// I miss callbacks :(
|
||||
useNuiEvent('loadResource', (data: { queries: QueryData[]; pageCount: number }) => {
|
||||
maxPage = data.pageCount;
|
||||
$queries = data.queries;
|
||||
});
|
||||
|
||||
$: fetchNui('fetchResource', { resource: route.params.resource, pageIndex: page });
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col w-full justify-between">
|
||||
@@ -9,5 +26,5 @@
|
||||
<ResourceHeader />
|
||||
<QueryTable />
|
||||
</div>
|
||||
<Pagination />
|
||||
<Pagination {page} {maxPage} />
|
||||
</div>
|
||||
@@ -1,26 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { IconChevronLeft, IconChevronRight, IconChevronsLeft, IconChevronsRight } from '@tabler/icons-svelte';
|
||||
|
||||
export let page: number;
|
||||
export let maxPage: number;
|
||||
</script>
|
||||
|
||||
<div class="flex justify-center items-center gap-6 pb-5">
|
||||
<button
|
||||
class="bg-dark-600 text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||
disabled={page === 0}
|
||||
on:click={() => (page = 0)}
|
||||
class="bg-dark-600 disabled:bg-dark-300 disabled:text-dark-400 disabled:cursor-not-allowed text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||
>
|
||||
<IconChevronsLeft />
|
||||
</button>
|
||||
<button
|
||||
class="bg-dark-600 text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||
disabled={page === 0}
|
||||
on:click={() => page--}
|
||||
class="bg-dark-600 disabled:bg-dark-300 disabled:text-dark-400 disabled:cursor-not-allowed text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||
>
|
||||
<IconChevronLeft />
|
||||
</button>
|
||||
<p>Page 1 of 13</p>
|
||||
<p>Page {page + 1} of {maxPage}</p>
|
||||
<button
|
||||
class="bg-dark-600 text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||
disabled={page >= maxPage}
|
||||
on:click={() => page++}
|
||||
class="bg-dark-600 disabled:bg-dark-300 disabled:text-dark-400 disabled:cursor-not-allowed text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||
>
|
||||
<IconChevronRight />
|
||||
</button>
|
||||
<button
|
||||
class="bg-dark-600 text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||
disabled={page === maxPage}
|
||||
on:click={() => (page = maxPage)}
|
||||
class="bg-dark-600 disabled:bg-dark-300 disabled:text-dark-400 disabled:cursor-not-allowed text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||
>
|
||||
<IconChevronsRight />
|
||||
</button>
|
||||
|
||||
@@ -2,25 +2,9 @@
|
||||
import { IconChevronDown, IconChevronUp } from '@tabler/icons-svelte';
|
||||
import { createTable, Render, Subscribe } from 'svelte-headless-table';
|
||||
import { addSortBy } from 'svelte-headless-table/plugins';
|
||||
import { readable } from 'svelte/store';
|
||||
import { queries } from '../../../store';
|
||||
|
||||
const data = readable([
|
||||
{
|
||||
query: 'SELECT * FROM users WHERE ID = 1',
|
||||
time: 13,
|
||||
},
|
||||
{ query: 'SELECT * FROM users WHERE ID = 1', time: 15 },
|
||||
{ query: 'SELECT * FROM users WHERE ID = 1', time: 13 },
|
||||
{ query: 'SELECT * FROM users WHERE ID = 1', time: 32 },
|
||||
{ query: 'SELECT * FROM users WHERE ID = 1', time: 13 },
|
||||
{ query: 'SELECT * FROM users WHERE ID = 1', time: 11 },
|
||||
{ query: 'SELECT * FROM users WHERE ID = 1', time: 13 },
|
||||
{ query: 'SELECT * FROM users WHERE ID = 1', time: 15 },
|
||||
{ query: 'SELECT * FROM users WHERE ID = 1', time: 13 },
|
||||
{ query: 'SELECT * FROM users WHERE ID = 1', time: 32 },
|
||||
]);
|
||||
|
||||
const table = createTable(data, {
|
||||
const table = createTable(queries, {
|
||||
sort: addSortBy(),
|
||||
});
|
||||
|
||||
@@ -34,7 +18,7 @@
|
||||
}),
|
||||
table.column({
|
||||
header: 'Time (ms)',
|
||||
accessor: 'time',
|
||||
accessor: 'executionTime',
|
||||
plugins: {
|
||||
sort: {},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { IconChevronLeft } from '@tabler/icons-svelte';
|
||||
import { meta, router } from 'tinro';
|
||||
|
||||
const data = meta();
|
||||
const route = meta();
|
||||
</script>
|
||||
|
||||
<div class="p-4 grid grid-flow-col grid-cols-3 items-center ">
|
||||
@@ -12,7 +12,7 @@
|
||||
>
|
||||
<IconChevronLeft />
|
||||
</button>
|
||||
<p class="text-center text-lg">{data.params.resource}</p>
|
||||
<p class="text-center text-lg">{route.params.resource}</p>
|
||||
<div class="text-end text-dark-100 flex flex-col text-xs">
|
||||
<p>Queries: 530</p>
|
||||
<p>Time: 3014 ms</p>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { derived, writable } from 'svelte/store';
|
||||
|
||||
export const search = writable('');
|
||||
|
||||
let timeout: NodeJS.Timeout;
|
||||
export const debouncedSearch = derived(search, (value, set: (value: string) => void) => {
|
||||
timeout = setTimeout(() => set(value), 500);
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './general';
|
||||
export * from './resource';
|
||||
@@ -0,0 +1,10 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export interface QueryData {
|
||||
date: number;
|
||||
query: string;
|
||||
executionTime: number;
|
||||
slow?: boolean;
|
||||
}
|
||||
|
||||
export const queries = writable<QueryData[]>([]);
|
||||
Reference in new issue
Block a user