mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 22:20:56 +00:00
fix(nui): Data fetching into manual pagination
Perhaps don't need the loading state...?
This commit is contained in:
1 parent
7560099231
commit
238d7cd589
4 files changed
+60
-50
No files matched your search
+3
-2
@@ -51,8 +51,9 @@ RegisterCommand(
|
|||||||
onNet(`oxmysql:fetchResource`, (data: {resource: string, pageIndex: number}) => {
|
onNet(`oxmysql:fetchResource`, (data: {resource: string, pageIndex: number}) => {
|
||||||
if (typeof data.resource !== 'string') return;
|
if (typeof data.resource !== 'string') return;
|
||||||
|
|
||||||
const queries = logStorage[data.resource].slice(data.pageIndex * 12, data.pageIndex + 12)
|
const startRow = data.pageIndex * 12
|
||||||
|
const endRow = startRow + 12
|
||||||
|
const queries = logStorage[data.resource].slice(startRow, endRow)
|
||||||
const pageCount = Math.ceil(logStorage[data.resource].length / 12)
|
const pageCount = Math.ceil(logStorage[data.resource].length / 12)
|
||||||
|
|
||||||
if (!queries) return;
|
if (!queries) return;
|
||||||
|
|||||||
@@ -11,8 +11,12 @@ import { useVisibility } from '../providers/VisibilityProvider';
|
|||||||
|
|
||||||
debugData([
|
debugData([
|
||||||
{
|
{
|
||||||
action: 'setVisible',
|
action: 'openUI',
|
||||||
data: true,
|
data: {
|
||||||
|
resources: ['ox_inventory', 'luke_garages', 'es_extended'],
|
||||||
|
totalQueries: 732,
|
||||||
|
totalTime: 258,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -6,17 +6,6 @@ import { debugData } from '../../utils/debugData';
|
|||||||
import type { InitData } from '../../types';
|
import type { InitData } from '../../types';
|
||||||
|
|
||||||
const LeftBar: React.FC = () => {
|
const LeftBar: React.FC = () => {
|
||||||
debugData([
|
|
||||||
{
|
|
||||||
action: 'init',
|
|
||||||
data: {
|
|
||||||
resources: ['ox_inventory', 'luke_garages', 'es_extended'],
|
|
||||||
totalQueries: 732,
|
|
||||||
totalTime: 258,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const [initData, setInitData] = useState<InitData>({ resources: [''], totalQueries: 0, totalTime: 0 });
|
const [initData, setInitData] = useState<InitData>({ resources: [''], totalQueries: 0, totalTime: 0 });
|
||||||
|
|
||||||
useNuiEvent<InitData>('openUI', (data) => {
|
useNuiEvent<InitData>('openUI', (data) => {
|
||||||
@@ -24,7 +13,7 @@ const LeftBar: React.FC = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box p="1.2vh" fontSize="1.5vh" float="left" w="13%" height="55vh" overflowY="scroll">
|
<Box p="1.2vh" fontSize="1.5vh" float="left" w="13%" height="90%" overflowY="scroll">
|
||||||
<VStack align="left">
|
<VStack align="left">
|
||||||
{initData.resources.map((resource, index) => (
|
{initData.resources.map((resource, index) => (
|
||||||
<Link to={resource} key={`${resource}-${index}`}>
|
<Link to={resource} key={`${resource}-${index}`}>
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ interface NuiData {
|
|||||||
|
|
||||||
const Resource: React.FC = () => {
|
const Resource: React.FC = () => {
|
||||||
let { resource } = useParams();
|
let { resource } = useParams();
|
||||||
|
const [isLoaded, setIsLoaded] = useState(false);
|
||||||
const [resourceData, setResourceData] = useState<QueryData[]>([
|
const [resourceData, setResourceData] = useState<QueryData[]>([
|
||||||
{
|
{
|
||||||
date: 0,
|
date: 0,
|
||||||
@@ -44,6 +45,7 @@ const Resource: React.FC = () => {
|
|||||||
useNuiEvent<NuiData>('loadResource', (data) => {
|
useNuiEvent<NuiData>('loadResource', (data) => {
|
||||||
setResourceData(data.queries);
|
setResourceData(data.queries);
|
||||||
setTotalPages(data.pageCount);
|
setTotalPages(data.pageCount);
|
||||||
|
setIsLoaded(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = useMemo<TableData[]>(() => resourceData, [resourceData]);
|
const data = useMemo<TableData[]>(() => resourceData, [resourceData]);
|
||||||
@@ -77,27 +79,35 @@ const Resource: React.FC = () => {
|
|||||||
state: { pageIndex },
|
state: { pageIndex },
|
||||||
prepareRow,
|
prepareRow,
|
||||||
} = useTable(
|
} = useTable(
|
||||||
{ columns, data, initialState: { pageSize: 12 }, manualPagination: true, pageCount: totalPages },
|
{
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
initialState: { pageSize: 12 },
|
||||||
|
manualPagination: true,
|
||||||
|
pageCount: totalPages,
|
||||||
|
autoResetPage: false,
|
||||||
|
},
|
||||||
useSortBy,
|
useSortBy,
|
||||||
usePagination
|
usePagination
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchNui('fetchResource', { resource, pageIndex });
|
fetchNui('fetchResource', { resource, pageIndex });
|
||||||
debugData([
|
setIsLoaded(false);
|
||||||
{
|
// debugData([
|
||||||
action: 'loadResource',
|
// {
|
||||||
data: {
|
// action: 'loadResource',
|
||||||
pageCount: 1,
|
// data: {
|
||||||
queries: [
|
// pageCount: 1,
|
||||||
{ query: 'SELECT * FROM `users`', executionTime: 5 },
|
// queries: [
|
||||||
{ query: 'SELECT * FROM `owned_vehicles`', executionTime: 2 },
|
// { query: 'SELECT * FROM `users`', executionTime: 5 },
|
||||||
{ query: 'SELECT * FROM `properties`', executionTime: 7 },
|
// { query: 'SELECT * FROM `owned_vehicles`', executionTime: 2 },
|
||||||
{ query: 'SELECT * FROM `phone_messages`', executionTime: 13 },
|
// { query: 'SELECT * FROM `properties`', executionTime: 7 },
|
||||||
],
|
// { query: 'SELECT * FROM `phone_messages`', executionTime: 13 },
|
||||||
},
|
// ],
|
||||||
},
|
// },
|
||||||
]);
|
// },
|
||||||
|
// ]);
|
||||||
}, [resource, pageIndex]);
|
}, [resource, pageIndex]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -129,25 +139,31 @@ const Resource: React.FC = () => {
|
|||||||
))}
|
))}
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody {...getTableBodyProps()}>
|
<Tbody {...getTableBodyProps()}>
|
||||||
{page.map((row) => {
|
{isLoaded ? (
|
||||||
prepareRow(row);
|
<>
|
||||||
return (
|
{page.map((row) => {
|
||||||
<Tr {...row.getRowProps()}>
|
prepareRow(row);
|
||||||
{row.cells.map((cell) => (
|
return (
|
||||||
<Td
|
<Tr {...row.getRowProps()}>
|
||||||
{...cell.getCellProps()}
|
{row.cells.map((cell) => (
|
||||||
fontFamily="Poppins"
|
<Td
|
||||||
wordBreak="break-word"
|
{...cell.getCellProps()}
|
||||||
textOverflow="ellipsis"
|
fontFamily="Poppins"
|
||||||
overflow="hidden"
|
wordBreak="break-word"
|
||||||
borderBottomColor="#313C4A"
|
textOverflow="ellipsis"
|
||||||
>
|
overflow="hidden"
|
||||||
{cell.render('Cell')}
|
borderBottomColor="#313C4A"
|
||||||
</Td>
|
>
|
||||||
))}
|
{cell.render('Cell')}
|
||||||
</Tr>
|
</Td>
|
||||||
);
|
))}
|
||||||
})}
|
</Tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<h2>Loading....</h2>
|
||||||
|
)}
|
||||||
</Tbody>
|
</Tbody>
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user