mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 22:20:56 +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">
|
<script lang="ts">
|
||||||
|
import { fetchNui } from '../../utils/fetchNui';
|
||||||
import Pagination from './components/Pagination.svelte';
|
import Pagination from './components/Pagination.svelte';
|
||||||
import QueryTable from './components/QueryTable.svelte';
|
import QueryTable from './components/QueryTable.svelte';
|
||||||
import ResourceHeader from './components/ResourceHeader.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>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col w-full justify-between">
|
<div class="flex flex-col w-full justify-between">
|
||||||
@@ -9,5 +26,5 @@
|
|||||||
<ResourceHeader />
|
<ResourceHeader />
|
||||||
<QueryTable />
|
<QueryTable />
|
||||||
</div>
|
</div>
|
||||||
<Pagination />
|
<Pagination {page} {maxPage} />
|
||||||
</div>
|
</div>
|
||||||
@@ -1,26 +1,37 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { IconChevronLeft, IconChevronRight, IconChevronsLeft, IconChevronsRight } from '@tabler/icons-svelte';
|
import { IconChevronLeft, IconChevronRight, IconChevronsLeft, IconChevronsRight } from '@tabler/icons-svelte';
|
||||||
|
|
||||||
|
export let page: number;
|
||||||
|
export let maxPage: number;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex justify-center items-center gap-6 pb-5">
|
<div class="flex justify-center items-center gap-6 pb-5">
|
||||||
<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 = 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 />
|
<IconChevronsLeft />
|
||||||
</button>
|
</button>
|
||||||
<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 />
|
<IconChevronLeft />
|
||||||
</button>
|
</button>
|
||||||
<p>Page 1 of 13</p>
|
<p>Page {page + 1} of {maxPage}</p>
|
||||||
<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++}
|
||||||
|
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 />
|
<IconChevronRight />
|
||||||
</button>
|
</button>
|
||||||
<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 />
|
<IconChevronsRight />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -2,25 +2,9 @@
|
|||||||
import { IconChevronDown, IconChevronUp } from '@tabler/icons-svelte';
|
import { IconChevronDown, IconChevronUp } from '@tabler/icons-svelte';
|
||||||
import { createTable, Render, Subscribe } from 'svelte-headless-table';
|
import { createTable, Render, Subscribe } from 'svelte-headless-table';
|
||||||
import { addSortBy } from 'svelte-headless-table/plugins';
|
import { addSortBy } from 'svelte-headless-table/plugins';
|
||||||
import { readable } from 'svelte/store';
|
import { queries } from '../../../store';
|
||||||
|
|
||||||
const data = readable([
|
const table = createTable(queries, {
|
||||||
{
|
|
||||||
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, {
|
|
||||||
sort: addSortBy(),
|
sort: addSortBy(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -34,7 +18,7 @@
|
|||||||
}),
|
}),
|
||||||
table.column({
|
table.column({
|
||||||
header: 'Time (ms)',
|
header: 'Time (ms)',
|
||||||
accessor: 'time',
|
accessor: 'executionTime',
|
||||||
plugins: {
|
plugins: {
|
||||||
sort: {},
|
sort: {},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { IconChevronLeft } from '@tabler/icons-svelte';
|
import { IconChevronLeft } from '@tabler/icons-svelte';
|
||||||
import { meta, router } from 'tinro';
|
import { meta, router } from 'tinro';
|
||||||
|
|
||||||
const data = meta();
|
const route = meta();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="p-4 grid grid-flow-col grid-cols-3 items-center ">
|
<div class="p-4 grid grid-flow-col grid-cols-3 items-center ">
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
>
|
>
|
||||||
<IconChevronLeft />
|
<IconChevronLeft />
|
||||||
</button>
|
</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">
|
<div class="text-end text-dark-100 flex flex-col text-xs">
|
||||||
<p>Queries: 530</p>
|
<p>Queries: 530</p>
|
||||||
<p>Time: 3014 ms</p>
|
<p>Time: 3014 ms</p>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { derived, writable } from 'svelte/store';
|
import { derived, writable } from 'svelte/store';
|
||||||
|
|
||||||
export const search = writable('');
|
export const search = writable('');
|
||||||
|
|
||||||
let timeout: NodeJS.Timeout;
|
let timeout: NodeJS.Timeout;
|
||||||
export const debouncedSearch = derived(search, (value, set: (value: string) => void) => {
|
export const debouncedSearch = derived(search, (value, set: (value: string) => void) => {
|
||||||
timeout = setTimeout(() => set(value), 500);
|
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