mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-01 22:21:51 +00:00
Merge pull request #172 from LukeWasTakenn/svelte-rewrite
WIP Svelte rewrite
This commit is contained in:
51 files changed
+1826
-12172
No files matched your search
@@ -110,6 +110,9 @@ dist
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# JetBrains
|
||||
.idea
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
|
||||
+2
-1
@@ -26,7 +26,8 @@
|
||||
"mysql2": "^3.2.0",
|
||||
"named-placeholders": "^1.1.3",
|
||||
"node-fetch": "^3.3.0",
|
||||
"prettier": "^2.8.3"
|
||||
"prettier": "^2.8.3",
|
||||
"svelte-spa-router": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.14.54",
|
||||
|
||||
Generated
+13
@@ -12,6 +12,7 @@ specifiers:
|
||||
postinstall-postinstall: ^2.1.0
|
||||
prettier: ^2.8.3
|
||||
pretty-quick: ^3.1.3
|
||||
svelte-spa-router: ^3.3.0
|
||||
typescript: ^4.9.4
|
||||
|
||||
dependencies:
|
||||
@@ -22,6 +23,7 @@ dependencies:
|
||||
named-placeholders: 1.1.3
|
||||
node-fetch: 3.3.0
|
||||
prettier: 2.8.3
|
||||
svelte-spa-router: 3.3.0
|
||||
|
||||
devDependencies:
|
||||
esbuild: 0.14.54
|
||||
@@ -4182,6 +4184,11 @@ packages:
|
||||
functions-have-names: 1.2.3
|
||||
dev: true
|
||||
|
||||
/regexparam/2.0.1:
|
||||
resolution: {integrity: sha512-zRgSaYemnNYxUv+/5SeoHI0eJIgTL/A2pUtXUPLHQxUldagouJ9p+K6IbIZ/JiQuCEv2E2B1O11SjVQy3aMCkw==}
|
||||
engines: {node: '>=8'}
|
||||
dev: false
|
||||
|
||||
/request/2.88.2:
|
||||
resolution: {integrity: sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==}
|
||||
engines: {node: '>= 6'}
|
||||
@@ -4616,6 +4623,12 @@ packages:
|
||||
engines: {node: '>= 0.4'}
|
||||
dev: true
|
||||
|
||||
/svelte-spa-router/3.3.0:
|
||||
resolution: {integrity: sha512-cwRNe7cxD43sCvSfEeaKiNZg3FCizGxeMcf7CPiWRP3jKXjEma3vxyyuDtPOam6nWbVxl9TNM3hlE/i87ZlqcQ==}
|
||||
dependencies:
|
||||
regexparam: 2.0.1
|
||||
dev: false
|
||||
|
||||
/tar/4.4.19:
|
||||
resolution: {integrity: sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA==}
|
||||
engines: {node: '>=4.5'}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
@@ -1,24 +0,0 @@
|
||||
const path = require('path');
|
||||
module.exports = {
|
||||
webpack: {
|
||||
configure: (webpackConfig) => {
|
||||
// Because CEF has issues with loading source maps properly atm,
|
||||
// lets use the best we can get in line with `eval-source-map`
|
||||
if (webpackConfig.mode === 'development' && process.env.IN_GAME_DEV) {
|
||||
webpackConfig.devtool = 'eval-source-map';
|
||||
webpackConfig.output.path = path.join(__dirname, 'build');
|
||||
}
|
||||
|
||||
return webpackConfig;
|
||||
},
|
||||
},
|
||||
|
||||
devServer: (devServerConfig) => {
|
||||
if (process.env.IN_GAME_DEV) {
|
||||
// Used for in-game dev mode
|
||||
devServerConfig.devMiddleware.writeToDisk = true;
|
||||
}
|
||||
|
||||
return devServerConfig;
|
||||
},
|
||||
};
|
||||
@@ -1,69 +0,0 @@
|
||||
{
|
||||
"name": "ui",
|
||||
"version": "1.0.0",
|
||||
"homepage": "ui/build",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@chakra-ui/icons": "^1.1.1",
|
||||
"@chakra-ui/react": "^1.7.3",
|
||||
"@emotion/react": "^11",
|
||||
"@emotion/styled": "^11",
|
||||
"@types/jest": "^26.0.24",
|
||||
"@types/node": "^16.11.18",
|
||||
"@types/react": "^17.0.38",
|
||||
"@types/react-dom": "^17.0.11",
|
||||
"@types/react-table": "^7.7.9",
|
||||
"framer-motion": "4.1.17",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-router-dom": "6",
|
||||
"react-scripts": "5.0.0",
|
||||
"react-table": "^7.7.0",
|
||||
"typescript": "^4.5.4",
|
||||
"victory": "^36.2.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "cross-env PUBLIC_URL=/ craco start",
|
||||
"start:game": "cross-env IN_GAME_DEV=1 craco start",
|
||||
"build": "rimraf build && craco build",
|
||||
"test": "craco test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": ">=7.0.0 <8.0.0",
|
||||
"@babel/plugin-syntax-flow": "^7.14.5",
|
||||
"@babel/plugin-transform-react-jsx": "^7.14.9",
|
||||
"@chakra-ui/system": "^1.11.2",
|
||||
"@craco/craco": "^6.4.3",
|
||||
"autoprefixer": "^10.0.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"postcss": "^8.1.0",
|
||||
"rimraf": "^3.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": ">=7.0.0 <8.0.0",
|
||||
"@babel/plugin-syntax-flow": "^7.14.5",
|
||||
"@babel/plugin-transform-react-jsx": "^7.14.9",
|
||||
"@chakra-ui/system": "^1.11.2",
|
||||
"autoprefixer": "^10.0.2",
|
||||
"postcss": "^8.1.0"
|
||||
}
|
||||
}
|
||||
Generated
-11261
File diff suppressed because it is too large.
Load diff
@@ -1,23 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<title>NUI React Boilerplate</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,58 +0,0 @@
|
||||
import { Flex, Box } from '@chakra-ui/react';
|
||||
import { debugData } from '../utils/debugData';
|
||||
import TopBar from './NavBars/TopBar';
|
||||
import LeftBar from './NavBars/LeftBar';
|
||||
import { Routes, Route, useNavigate } from 'react-router-dom';
|
||||
import Resource from './Resource';
|
||||
import RightBar from './NavBars/RightBar';
|
||||
import MainContent from './MainContent';
|
||||
import { useNuiEvent } from '../hooks/useNuiEvent';
|
||||
|
||||
debugData([
|
||||
{
|
||||
action: 'openUI',
|
||||
data: {
|
||||
resources: ['ox_inventory', 'luke_garages', 'es_extended'],
|
||||
totalQueries: 732,
|
||||
totalTime: 258,
|
||||
slowQueries: 6,
|
||||
chartData: [
|
||||
{ x: 13, y: 350, z: 'ox_inventory' },
|
||||
{ x: 27, y: 752, z: 'es_extended' },
|
||||
{ x: 41, y: 52, z: 'luke_garages' },
|
||||
],
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const App: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
useNuiEvent('openUI', () => navigate('/'));
|
||||
|
||||
return (
|
||||
<Flex w="100%" h="100%" alignItems="center" justifyContent="center">
|
||||
<Box
|
||||
width="6xl"
|
||||
height="lg"
|
||||
backgroundColor="#191E26"
|
||||
borderRadius="lg"
|
||||
color="white"
|
||||
fontFamily="Poppins"
|
||||
userSelect="none"
|
||||
>
|
||||
<TopBar />
|
||||
<LeftBar />
|
||||
<RightBar />
|
||||
<MainContent>
|
||||
<Routes>
|
||||
<Route path="/:resource" element={<Resource />} />
|
||||
<Route path="/" element={<></>} />
|
||||
</Routes>
|
||||
</MainContent>
|
||||
</Box>
|
||||
</Flex>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
@@ -1,14 +0,0 @@
|
||||
import React from 'react';
|
||||
import { Box, Center } from '@chakra-ui/react';
|
||||
|
||||
const MainContent: React.FC = ({ children }) => {
|
||||
return (
|
||||
<Center>
|
||||
<Box h="30.3rem" w="50%" backgroundColor="#1B2129" flex="1">
|
||||
{children}
|
||||
</Box>
|
||||
</Center>
|
||||
);
|
||||
};
|
||||
|
||||
export default MainContent;
|
||||
@@ -1,42 +0,0 @@
|
||||
import { Box, VStack } from '@chakra-ui/react';
|
||||
import { useState } from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
||||
import type { InitData } from '../../types';
|
||||
|
||||
const LeftBar: React.FC = () => {
|
||||
const [initData, setInitData] = useState<InitData>({
|
||||
resources: [''],
|
||||
totalQueries: 0,
|
||||
totalTime: 0,
|
||||
slowQueries: 0,
|
||||
chartData: [{ x: 0, y: 0, z: '' }],
|
||||
});
|
||||
|
||||
useNuiEvent<InitData>('openUI', (data) => {
|
||||
setInitData(data);
|
||||
});
|
||||
|
||||
return (
|
||||
<Box pl={3} pr={3} pb={3} pt={2} fontSize="md" float="left" w={150} height="90%" overflowY="scroll">
|
||||
<VStack align="left">
|
||||
{initData.resources.map((resource, index) => (
|
||||
<Box isTruncated key={`${resource}-${index}`}>
|
||||
<NavLink
|
||||
to={resource}
|
||||
style={(state) => ({
|
||||
color: state.isActive ? 'white' : 'grey',
|
||||
})}
|
||||
>
|
||||
<Box _hover={{ color: 'white' }} isTruncated>
|
||||
{resource}
|
||||
</Box>
|
||||
</NavLink>
|
||||
</Box>
|
||||
))}
|
||||
</VStack>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default LeftBar;
|
||||
@@ -1,56 +0,0 @@
|
||||
import { useState } from 'react';
|
||||
import { Box, VStack, Center, Spacer, Flex, Text } from '@chakra-ui/react';
|
||||
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
||||
import { VictoryPie, VictoryTooltip } from 'victory';
|
||||
import type { InitData } from '../../types';
|
||||
|
||||
const RightBar: React.FC = () => {
|
||||
const [initData, setInitData] = useState<InitData>({
|
||||
totalQueries: 0,
|
||||
totalTime: 0,
|
||||
slowQueries: 0,
|
||||
resources: [''],
|
||||
chartData: [{ x: 0, y: 0, z: '' }],
|
||||
});
|
||||
|
||||
// Debug data defined in LeftBar.tsx
|
||||
|
||||
useNuiEvent<InitData>('openUI', (data) => {
|
||||
setInitData(data);
|
||||
});
|
||||
|
||||
return (
|
||||
<Box float="right" w="3xs" h="100%" p={3}>
|
||||
<Center h="100%">
|
||||
<Flex direction="column" h="100%">
|
||||
<Box>
|
||||
<VStack align="left">
|
||||
<Text>Number of queries: {initData.totalQueries.toLocaleString('en-US')}</Text>
|
||||
<Text>Time querying: {Math.trunc(initData.totalTime).toLocaleString('en-US')} ms</Text>
|
||||
<Text color="#f3eca1">Slow queries: {initData.slowQueries.toLocaleString('en-US')}</Text>
|
||||
</VStack>
|
||||
</Box>
|
||||
<Spacer />
|
||||
<Box>
|
||||
<VictoryPie
|
||||
colorScale="qualitative"
|
||||
data={initData.chartData}
|
||||
labelComponent={<VictoryTooltip flyoutPadding={18} style={{ fontSize: 24 }} cornerRadius={15} />}
|
||||
style={{
|
||||
labels: {
|
||||
fill: 'black',
|
||||
fontFamily: 'Poppins',
|
||||
fontSize: 28,
|
||||
},
|
||||
}}
|
||||
labels={({ datum }) => `${datum.z}: ${datum.x} (${Math.trunc(datum.y)}ms)`}
|
||||
labelPlacement="parallel"
|
||||
/>
|
||||
</Box>
|
||||
</Flex>
|
||||
</Center>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default RightBar;
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Box, Text } from '@chakra-ui/react';
|
||||
|
||||
const TopBar: React.FC = () => {
|
||||
return (
|
||||
<Box w="full" h="4xs">
|
||||
<Text paddingLeft={3} fontSize="lg">
|
||||
Resources
|
||||
</Text>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default TopBar;
|
||||
@@ -1,257 +0,0 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import React, { useEffect, useState, useMemo } from 'react';
|
||||
import { fetchNui } from '../utils/fetchNui';
|
||||
import { useNuiEvent } from '../hooks/useNuiEvent';
|
||||
import {
|
||||
Table,
|
||||
Thead,
|
||||
Tbody,
|
||||
Tr,
|
||||
Th,
|
||||
Td,
|
||||
chakra,
|
||||
Flex,
|
||||
IconButton,
|
||||
Text,
|
||||
Spinner,
|
||||
Tooltip,
|
||||
useToast,
|
||||
} from '@chakra-ui/react';
|
||||
import {
|
||||
TriangleDownIcon,
|
||||
TriangleUpIcon,
|
||||
ArrowLeftIcon,
|
||||
ChevronLeftIcon,
|
||||
ArrowRightIcon,
|
||||
ChevronRightIcon,
|
||||
} from '@chakra-ui/icons';
|
||||
import { useTable, useSortBy, Column, usePagination, useFlexLayout } from 'react-table';
|
||||
import { debugData } from '../utils/debugData';
|
||||
import { setClipboard } from '../utils/setClipboard';
|
||||
|
||||
interface QueryData {
|
||||
date: number;
|
||||
query: string;
|
||||
executionTime: number;
|
||||
slow?: boolean;
|
||||
}
|
||||
|
||||
interface TableData {
|
||||
query: string;
|
||||
executionTime: number;
|
||||
slow?: boolean;
|
||||
}
|
||||
|
||||
interface NuiData {
|
||||
queries: QueryData[];
|
||||
pageCount: number;
|
||||
}
|
||||
|
||||
const Resource: React.FC = () => {
|
||||
const { resource } = useParams();
|
||||
const toast = useToast();
|
||||
|
||||
const [isLoaded, setIsLoaded] = useState(false);
|
||||
const [resourceData, setResourceData] = useState<QueryData[]>([
|
||||
{
|
||||
date: 0,
|
||||
query: '',
|
||||
executionTime: 0,
|
||||
},
|
||||
]);
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
|
||||
const data = useMemo<TableData[]>(() => resourceData, [resourceData]);
|
||||
|
||||
const columns = useMemo<Column<TableData>[]>(
|
||||
() => [
|
||||
{
|
||||
Header: 'Query',
|
||||
accessor: 'query',
|
||||
},
|
||||
{
|
||||
Header: 'Execution time (ms)',
|
||||
accessor: 'executionTime',
|
||||
},
|
||||
{
|
||||
Header: 'Slow',
|
||||
accessor: 'slow',
|
||||
},
|
||||
],
|
||||
[]
|
||||
);
|
||||
|
||||
const {
|
||||
getTableProps,
|
||||
getTableBodyProps,
|
||||
headerGroups,
|
||||
page,
|
||||
canPreviousPage,
|
||||
canNextPage,
|
||||
pageOptions,
|
||||
pageCount,
|
||||
gotoPage,
|
||||
nextPage,
|
||||
previousPage,
|
||||
state: { pageIndex, sortBy },
|
||||
prepareRow,
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
data,
|
||||
initialState: { pageSize: 12, hiddenColumns: ['slow'] },
|
||||
manualPagination: true,
|
||||
manualSortBy: true,
|
||||
pageCount: totalPages,
|
||||
autoResetPage: false,
|
||||
},
|
||||
useSortBy,
|
||||
usePagination,
|
||||
useFlexLayout
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
fetchNui('fetchResource', { resource, pageIndex, sortBy });
|
||||
setIsLoaded(false);
|
||||
debugData<NuiData>([
|
||||
{
|
||||
action: 'loadResource',
|
||||
data: {
|
||||
queries: [
|
||||
{ query: 'SELECT * FROM `owned_vehicles`', date: 0, executionTime: 3.5 },
|
||||
{ query: 'SELECT * FROM `users`', date: 0, executionTime: 7.3 },
|
||||
{ query: 'SELECT * FROM `properties`', date: 0, executionTime: 25.7 },
|
||||
],
|
||||
pageCount: 1,
|
||||
},
|
||||
},
|
||||
]);
|
||||
}, [resource, pageIndex, sortBy]);
|
||||
|
||||
useNuiEvent<NuiData>('loadResource', (data) => {
|
||||
setResourceData(data.queries);
|
||||
setTotalPages(data.pageCount);
|
||||
setIsLoaded(true);
|
||||
});
|
||||
|
||||
const handleClick = (value: string) => {
|
||||
setClipboard(value);
|
||||
toast({
|
||||
title: 'Query copied to clipboard',
|
||||
duration: 2500,
|
||||
status: 'success',
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Flex direction="column" justifyContent="space-between" alignItems="center" h="full">
|
||||
<Table {...getTableProps()} size="sm">
|
||||
<Thead>
|
||||
{headerGroups.map((header): any => (
|
||||
<Tr {...header.getHeaderGroupProps()}>
|
||||
{header.headers.map((column) => (
|
||||
<Th
|
||||
{...column.getHeaderProps(column.getSortByToggleProps())}
|
||||
color="white"
|
||||
fontFamily="Poppins"
|
||||
borderBottomColor="#313C4A"
|
||||
textAlign="center"
|
||||
>
|
||||
{column.render('Header')}
|
||||
<chakra.span pl="4">
|
||||
{column.isSorted ? (
|
||||
column.isSortedDesc ? (
|
||||
<TriangleDownIcon aria-label="sorted descending" />
|
||||
) : (
|
||||
<TriangleUpIcon aria-label="sorted ascending" />
|
||||
)
|
||||
) : null}
|
||||
</chakra.span>
|
||||
</Th>
|
||||
))}
|
||||
</Tr>
|
||||
))}
|
||||
</Thead>
|
||||
<Tbody {...getTableBodyProps()}>
|
||||
{isLoaded && (
|
||||
<>
|
||||
{page.map((row, index) => {
|
||||
prepareRow(row);
|
||||
return (
|
||||
<Tr {...row.getRowProps()} key={`row-${index}`}>
|
||||
{row.cells.map((cell, index) => (
|
||||
<React.Fragment key={`row-${index}`}>
|
||||
<Tooltip
|
||||
isDisabled={cell.column.id === 'executionTime'}
|
||||
label={cell.value}
|
||||
openDelay={500}
|
||||
key={`cell-${index}`}
|
||||
>
|
||||
<Td
|
||||
{...cell.getCellProps()}
|
||||
fontFamily="Poppins"
|
||||
borderBottomColor="#313C4A"
|
||||
color={row.values.slow && '#f3eca1'}
|
||||
isTruncated={cell.column.id === 'query'}
|
||||
textAlign={cell.column.id === 'executionTime' ? 'center' : 'left'}
|
||||
onClick={(e) => cell.column.id === 'query' && handleClick(cell.value)}
|
||||
>
|
||||
{cell.render('Cell')}
|
||||
</Td>
|
||||
</Tooltip>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</Tr>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
</Tbody>
|
||||
</Table>
|
||||
|
||||
{!isLoaded && <Spinner />}
|
||||
|
||||
<Flex justifyContent="center" alignItems="center" p={3}>
|
||||
<Flex>
|
||||
<IconButton
|
||||
icon={<ArrowLeftIcon h={3} w={3} color="black" />}
|
||||
aria-label="Last page"
|
||||
onClick={() => gotoPage(0)}
|
||||
size="sm"
|
||||
isDisabled={!canPreviousPage}
|
||||
/>
|
||||
<IconButton
|
||||
aria-label="Previous page"
|
||||
onClick={previousPage}
|
||||
isDisabled={!canPreviousPage}
|
||||
icon={<ChevronLeftIcon h={6} w={6} color="black" />}
|
||||
size="sm"
|
||||
ml={4}
|
||||
/>
|
||||
</Flex>
|
||||
<Text align="center" pl={4} pr={4}>
|
||||
Page {pageIndex + 1} of {pageOptions.length}
|
||||
</Text>
|
||||
<Flex>
|
||||
<IconButton
|
||||
aria-label="Next page"
|
||||
onClick={nextPage}
|
||||
size="sm"
|
||||
isDisabled={!canNextPage}
|
||||
icon={<ChevronRightIcon h={6} w={6} color="black" />}
|
||||
/>
|
||||
<IconButton
|
||||
aria-label="Last page"
|
||||
onClick={() => gotoPage(pageCount - 1)}
|
||||
isDisabled={!canNextPage}
|
||||
icon={<ArrowRightIcon h={3} w={3} color="black" />}
|
||||
size="sm"
|
||||
ml={4}
|
||||
/>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Flex>
|
||||
);
|
||||
};
|
||||
|
||||
export default Resource;
|
||||
@@ -1,46 +0,0 @@
|
||||
import { MutableRefObject, useEffect, useRef } from 'react';
|
||||
import { noop } from '../utils/misc';
|
||||
|
||||
interface NuiMessageData<T = unknown> {
|
||||
action: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
type NuiHandlerSignature<T> = (data: T) => void;
|
||||
|
||||
/**
|
||||
* A hook that manage events listeners for receiving data from the client scripts
|
||||
* @param action The specific `action` that should be listened for.
|
||||
* @param handler The callback function that will handle data relayed by this hook
|
||||
*
|
||||
* @example
|
||||
* useNuiEvent<{visibility: true, wasVisible: 'something'}>('setVisible', (data) => {
|
||||
* // whatever logic you want
|
||||
* })
|
||||
*
|
||||
**/
|
||||
|
||||
export const useNuiEvent = <T = any>(action: string, handler: (data: T) => void) => {
|
||||
const savedHandler: MutableRefObject<NuiHandlerSignature<T>> = useRef(noop);
|
||||
|
||||
// Make sure we handle for a reactive handler
|
||||
useEffect(() => {
|
||||
savedHandler.current = handler;
|
||||
}, [handler]);
|
||||
|
||||
useEffect(() => {
|
||||
const eventListener = (event: MessageEvent<NuiMessageData<T>>) => {
|
||||
const { action: eventAction, data } = event.data;
|
||||
|
||||
if (savedHandler.current) {
|
||||
if (eventAction === action) {
|
||||
savedHandler.current(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('message', eventListener);
|
||||
// Remove Event Listener on component cleanup
|
||||
return () => window.removeEventListener('message', eventListener);
|
||||
}, [action]);
|
||||
};
|
||||
@@ -1,32 +0,0 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
|
||||
'Droid Sans', 'Helvetica Neue', sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
height: 100vh;
|
||||
background: none !important;
|
||||
}
|
||||
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 2px;
|
||||
border-radius: 1vh;
|
||||
background-color: transparent;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: grey;
|
||||
border-radius: 1vh;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import './index.css';
|
||||
import App from './components/App';
|
||||
import { VisibilityProvider } from './providers/VisibilityProvider';
|
||||
import { ChakraProvider } from '@chakra-ui/react';
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<VisibilityProvider>
|
||||
<ChakraProvider>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</ChakraProvider>
|
||||
</VisibilityProvider>
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
@@ -1,49 +0,0 @@
|
||||
import React, { Context, createContext, useContext, useEffect, useState } from 'react';
|
||||
import { useNuiEvent } from '../hooks/useNuiEvent';
|
||||
import { fetchNui } from '../utils/fetchNui';
|
||||
|
||||
const VisibilityCtx = createContext<VisibilityProviderValue | null>(null);
|
||||
|
||||
interface VisibilityProviderValue {
|
||||
setVisible: (visible: boolean) => void;
|
||||
visible: boolean;
|
||||
}
|
||||
|
||||
// This should be mounted at the top level of your application, it is currently set to
|
||||
// apply a CSS visibility value. If this is non-performant, this should be customized.
|
||||
export const VisibilityProvider: React.FC = ({ children }) => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
useNuiEvent<boolean>('openUI', setVisible);
|
||||
|
||||
// Handle pressing escape/backspace
|
||||
useEffect(() => {
|
||||
// Only attach listener when we are visible
|
||||
if (!visible) return;
|
||||
|
||||
const keyHandler = (e: KeyboardEvent) => {
|
||||
if (['Escape'].includes(e.code)) {
|
||||
fetchNui('exit');
|
||||
setVisible(false);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('keydown', keyHandler);
|
||||
|
||||
return () => window.removeEventListener('keydown', keyHandler);
|
||||
}, [visible]);
|
||||
|
||||
return (
|
||||
<VisibilityCtx.Provider
|
||||
value={{
|
||||
visible,
|
||||
setVisible,
|
||||
}}
|
||||
>
|
||||
<div style={{ visibility: visible ? 'visible' : 'hidden', height: '100%' }}>{children}</div>
|
||||
</VisibilityCtx.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useVisibility = () =>
|
||||
useContext<VisibilityProviderValue>(VisibilityCtx as Context<VisibilityProviderValue>);
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
/// <reference types="react-scripts" />
|
||||
@@ -1,13 +0,0 @@
|
||||
interface ChartData {
|
||||
x: number;
|
||||
y: number;
|
||||
z: string;
|
||||
}
|
||||
|
||||
export type InitData = {
|
||||
resources: string[];
|
||||
totalQueries: number;
|
||||
totalTime: number;
|
||||
slowQueries: number;
|
||||
chartData: ChartData[];
|
||||
};
|
||||
Vendored
-122
@@ -1,122 +0,0 @@
|
||||
import {
|
||||
UseColumnOrderInstanceProps,
|
||||
UseColumnOrderState,
|
||||
UseExpandedHooks,
|
||||
UseExpandedInstanceProps,
|
||||
UseExpandedOptions,
|
||||
UseExpandedRowProps,
|
||||
UseExpandedState,
|
||||
UseFiltersColumnOptions,
|
||||
UseFiltersColumnProps,
|
||||
UseFiltersInstanceProps,
|
||||
UseFiltersOptions,
|
||||
UseFiltersState,
|
||||
UseGlobalFiltersColumnOptions,
|
||||
UseGlobalFiltersInstanceProps,
|
||||
UseGlobalFiltersOptions,
|
||||
UseGlobalFiltersState,
|
||||
UseGroupByCellProps,
|
||||
UseGroupByColumnOptions,
|
||||
UseGroupByColumnProps,
|
||||
UseGroupByHooks,
|
||||
UseGroupByInstanceProps,
|
||||
UseGroupByOptions,
|
||||
UseGroupByRowProps,
|
||||
UseGroupByState,
|
||||
UsePaginationInstanceProps,
|
||||
UsePaginationOptions,
|
||||
UsePaginationState,
|
||||
UseResizeColumnsColumnOptions,
|
||||
UseResizeColumnsColumnProps,
|
||||
UseResizeColumnsOptions,
|
||||
UseResizeColumnsState,
|
||||
UseRowSelectHooks,
|
||||
UseRowSelectInstanceProps,
|
||||
UseRowSelectOptions,
|
||||
UseRowSelectRowProps,
|
||||
UseRowSelectState,
|
||||
UseRowStateCellProps,
|
||||
UseRowStateInstanceProps,
|
||||
UseRowStateOptions,
|
||||
UseRowStateRowProps,
|
||||
UseRowStateState,
|
||||
UseSortByColumnOptions,
|
||||
UseSortByColumnProps,
|
||||
UseSortByHooks,
|
||||
UseSortByInstanceProps,
|
||||
UseSortByOptions,
|
||||
UseSortByState,
|
||||
} from 'react-table';
|
||||
|
||||
declare module 'react-table' {
|
||||
// take this file as-is, or comment out the sections that don't apply to your plugin configuration
|
||||
|
||||
export interface TableOptions<D extends Record<string, unknown>>
|
||||
extends UseExpandedOptions<D>,
|
||||
UseFiltersOptions<D>,
|
||||
UseGlobalFiltersOptions<D>,
|
||||
UseGroupByOptions<D>,
|
||||
UsePaginationOptions<D>,
|
||||
UseResizeColumnsOptions<D>,
|
||||
UseRowSelectOptions<D>,
|
||||
UseRowStateOptions<D>,
|
||||
UseSortByOptions<D>,
|
||||
// note that having Record here allows you to add anything to the options, this matches the spirit of the
|
||||
// underlying js library, but might be cleaner if it's replaced by a more specific type that matches your
|
||||
// feature set, this is a safe default.
|
||||
Record<string, any> {}
|
||||
|
||||
export interface Hooks<D extends Record<string, unknown> = Record<string, unknown>>
|
||||
extends UseExpandedHooks<D>,
|
||||
UseGroupByHooks<D>,
|
||||
UseRowSelectHooks<D>,
|
||||
UseSortByHooks<D> {}
|
||||
|
||||
export interface TableInstance<D extends Record<string, unknown> = Record<string, unknown>>
|
||||
extends UseColumnOrderInstanceProps<D>,
|
||||
UseExpandedInstanceProps<D>,
|
||||
UseFiltersInstanceProps<D>,
|
||||
UseGlobalFiltersInstanceProps<D>,
|
||||
UseGroupByInstanceProps<D>,
|
||||
UsePaginationInstanceProps<D>,
|
||||
UseRowSelectInstanceProps<D>,
|
||||
UseRowStateInstanceProps<D>,
|
||||
UseSortByInstanceProps<D> {}
|
||||
|
||||
export interface TableState<D extends Record<string, unknown> = Record<string, unknown>>
|
||||
extends UseColumnOrderState<D>,
|
||||
UseExpandedState<D>,
|
||||
UseFiltersState<D>,
|
||||
UseGlobalFiltersState<D>,
|
||||
UseGroupByState<D>,
|
||||
UsePaginationState<D>,
|
||||
UseResizeColumnsState<D>,
|
||||
UseRowSelectState<D>,
|
||||
UseRowStateState<D>,
|
||||
UseSortByState<D> {}
|
||||
|
||||
export interface ColumnInterface<D extends Record<string, unknown> = Record<string, unknown>>
|
||||
extends UseFiltersColumnOptions<D>,
|
||||
UseGlobalFiltersColumnOptions<D>,
|
||||
UseGroupByColumnOptions<D>,
|
||||
UseResizeColumnsColumnOptions<D>,
|
||||
UseSortByColumnOptions<D> {}
|
||||
|
||||
export interface ColumnInstance<D extends Record<string, unknown> = Record<string, unknown>>
|
||||
extends UseFiltersColumnProps<D>,
|
||||
UseGroupByColumnProps<D>,
|
||||
UseResizeColumnsColumnProps<D>,
|
||||
UseSortByColumnProps<D> {
|
||||
getSortByToggleProps: (props?: Partial<TableSortByToggleProps> | undefined) => TableSortByToggleProps;
|
||||
}
|
||||
|
||||
export interface Cell<D extends Record<string, unknown> = Record<string, unknown>, V = any>
|
||||
extends UseGroupByCellProps<D>,
|
||||
UseRowStateCellProps<D> {}
|
||||
|
||||
export interface Row<D extends Record<string, unknown> = Record<string, unknown>>
|
||||
extends UseExpandedRowProps<D>,
|
||||
UseGroupByRowProps<D>,
|
||||
UseRowSelectRowProps<D>,
|
||||
UseRowStateRowProps<D> {}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
// Will return whether the current environment is in a regular browser
|
||||
// and not CEF
|
||||
export const isEnvBrowser = (): boolean => !(window as any).invokeNative;
|
||||
|
||||
// Basic no operation function
|
||||
export const noop = () => {};
|
||||
@@ -1,9 +0,0 @@
|
||||
// yoinked from https://github.com/project-error/npwd/blob/d8dc5b7f47faf5fc581ffee30f31ff61d184cfe7/phone/src/os/phone/hooks/useClipboard.ts#L1
|
||||
export const setClipboard = (value: string) => {
|
||||
const clipElem = document.createElement('input');
|
||||
clipElem.value = value;
|
||||
document.body.appendChild(clipElem);
|
||||
clipElem.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(clipElem);
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
build
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"singleQuote": true,
|
||||
"useTabs": false,
|
||||
"tabWidth": 2,
|
||||
"semi": true,
|
||||
"bracketSpacing": true,
|
||||
"trailingComma": "es5",
|
||||
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
|
||||
"pluginSearchDirs": false
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Svelte + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "oxmysql",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
"start:game": "vite build --watch",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"check": "svelte-check --tsconfig ./tsconfig.json"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "^2.0.3",
|
||||
"@tsconfig/svelte": "^3.0.0",
|
||||
"svelte": "^3.55.1",
|
||||
"svelte-check": "^2.10.3",
|
||||
"tslib": "^2.5.0",
|
||||
"typescript": "^4.9.3",
|
||||
"vite": "^4.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tabler/icons-svelte": "^2.10.0",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"postcss": "^8.4.21",
|
||||
"prettier": "^2.8.4",
|
||||
"prettier-plugin-svelte": "^2.9.0",
|
||||
"prettier-plugin-tailwindcss": "^0.2.5",
|
||||
"svelte-headless-table": "^0.17.2",
|
||||
"tailwindcss": "^3.2.7",
|
||||
"tinro": "^0.6.12"
|
||||
}
|
||||
}
|
||||
Generated
+1274
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,60 @@
|
||||
<script lang="ts">
|
||||
import { Route, router } from 'tinro';
|
||||
import Resource from './pages/resource/Resource.svelte';
|
||||
import Root from './pages/root/Root.svelte';
|
||||
import { useNuiEvent } from './utils/useNuiEvent';
|
||||
import { resources, generalData } from './store';
|
||||
import { debugData } from './utils/debugData';
|
||||
|
||||
interface OpenData {
|
||||
resources: string[];
|
||||
totalQueries: number;
|
||||
slowQueries: number;
|
||||
totalTime: number;
|
||||
chartData: {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
};
|
||||
}
|
||||
|
||||
router.mode.hash();
|
||||
router.goto('/');
|
||||
|
||||
useNuiEvent('openUI', (data: OpenData) => {
|
||||
$resources = data.resources;
|
||||
$generalData = {
|
||||
queries: data.totalQueries,
|
||||
slowQueries: data.slowQueries,
|
||||
timeQuerying: data.totalTime,
|
||||
};
|
||||
});
|
||||
|
||||
debugData<OpenData>([
|
||||
{
|
||||
action: 'openUI',
|
||||
data: {
|
||||
resources: ['ox_core', 'oxmysql', 'ox_inventory', 'ox_doorlock', 'ox_lib', 'ox_vehicleshop', 'ox_target'],
|
||||
slowQueries: 13,
|
||||
totalQueries: 332,
|
||||
totalTime: 230123,
|
||||
chartData: {
|
||||
x: 2,
|
||||
y: 5,
|
||||
z: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
</script>
|
||||
|
||||
<main class="w-full h-full flex justify-center items-center font-main">
|
||||
<div class="bg-dark-800 text-white w-[1000px] h-[600px] flex rounded-md">
|
||||
<Route path="/">
|
||||
<Root />
|
||||
</Route>
|
||||
<Route path="/:resource">
|
||||
<Resource />
|
||||
</Route>
|
||||
</div>
|
||||
</main>
|
||||
@@ -0,0 +1,31 @@
|
||||
@import url(https://use.typekit.net/wxh5ury.css);
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#app {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 2px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: #25262b;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #909296;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #a6a7ab;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import './index.css';
|
||||
import App from './App.svelte';
|
||||
import { isEnvBrowser } from './utils/misc';
|
||||
|
||||
const app = new App({
|
||||
target: document.getElementById('app'),
|
||||
});
|
||||
|
||||
if (isEnvBrowser()) {
|
||||
const root = document.getElementById('app');
|
||||
|
||||
// https://i.imgur.com/iPTAdYV.png - Night time img
|
||||
root!.style.backgroundImage = 'url("https://i.imgur.com/3pzRj9n.png")';
|
||||
root!.style.backgroundSize = 'cover';
|
||||
root!.style.backgroundRepeat = 'no-repeat';
|
||||
root!.style.backgroundPosition = 'center';
|
||||
}
|
||||
|
||||
export default app;
|
||||
@@ -0,0 +1,13 @@
|
||||
<script lang="ts">
|
||||
import Pagination from './components/Pagination.svelte';
|
||||
import QueryTable from './components/QueryTable.svelte';
|
||||
import ResourceHeader from './components/ResourceHeader.svelte';
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col w-full justify-between">
|
||||
<div>
|
||||
<ResourceHeader />
|
||||
<QueryTable />
|
||||
</div>
|
||||
<Pagination />
|
||||
</div>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script lang="ts">
|
||||
import { IconChevronLeft, IconChevronRight, IconChevronsLeft, IconChevronsRight } from '@tabler/icons-svelte';
|
||||
</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"
|
||||
>
|
||||
<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"
|
||||
>
|
||||
<IconChevronLeft />
|
||||
</button>
|
||||
<p>Page 1 of 13</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"
|
||||
>
|
||||
<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"
|
||||
>
|
||||
<IconChevronsRight />
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,90 @@
|
||||
<script lang="ts">
|
||||
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';
|
||||
|
||||
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, {
|
||||
sort: addSortBy(),
|
||||
});
|
||||
|
||||
const columns = table.createColumns([
|
||||
table.column({
|
||||
header: 'Query',
|
||||
accessor: 'query',
|
||||
plugins: {
|
||||
sort: {},
|
||||
},
|
||||
}),
|
||||
table.column({
|
||||
header: 'Time (ms)',
|
||||
accessor: 'time',
|
||||
plugins: {
|
||||
sort: {},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
const { headerRows, rows, tableAttrs, tableBodyAttrs } = table.createViewModel(columns);
|
||||
</script>
|
||||
|
||||
<table {...$tableAttrs} class="w-full">
|
||||
<thead class="bg-dark-600">
|
||||
{#each $headerRows as headerRow (headerRow.id)}
|
||||
<Subscribe rowAttrs={headerRow.attrs()} let:rowAttrs>
|
||||
<tr {...rowAttrs}>
|
||||
{#each headerRow.cells as cell (cell.id)}
|
||||
<Subscribe attrs={cell.attrs()} let:attrs props={cell.props()} let:props>
|
||||
<th {...attrs} on:click={props.sort.toggle} class="p-1 border-b-[1px] border-dark-400">
|
||||
<div class="flex justify-center items-center gap-2 select-none cursor-pointer">
|
||||
<Render of={cell.render()} />
|
||||
{#if props.sort.order === 'asc'}
|
||||
<IconChevronDown />
|
||||
{:else if props.sort.order === 'desc'}
|
||||
<IconChevronUp />
|
||||
{/if}
|
||||
</div>
|
||||
</th>
|
||||
</Subscribe>
|
||||
{/each}
|
||||
</tr>
|
||||
</Subscribe>
|
||||
{/each}
|
||||
</thead>
|
||||
<tbody {...$tableBodyAttrs}>
|
||||
{#each $rows as row (row.id)}
|
||||
<Subscribe rowAttrs={row.attrs()} let:rowAttrs>
|
||||
<tr {...rowAttrs}>
|
||||
{#each row.cells as cell (cell.id)}
|
||||
<Subscribe attrs={cell.attrs()} let:attrs>
|
||||
<td
|
||||
{...attrs}
|
||||
class={`${
|
||||
cell.id === 'time' && 'text-center'
|
||||
} p-2 bg-dark-700 border-b-[1px] border-dark-400 truncate max-w-[200px]`}
|
||||
>
|
||||
<Render of={cell.render()} />
|
||||
</td>
|
||||
</Subscribe>
|
||||
{/each}
|
||||
</tr>
|
||||
</Subscribe>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { IconChevronLeft } from '@tabler/icons-svelte';
|
||||
|
||||
import { router } from 'tinro';
|
||||
</script>
|
||||
|
||||
<div class="p-4 flex items-center">
|
||||
<button
|
||||
on:click={() => router.goto('/')}
|
||||
class="flex p-2 bg-dark-600 text-dark-100 hover:text-white rounded-md justify-center items-center hover:bg-dark-500 outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||
>
|
||||
<IconChevronLeft />
|
||||
Resources
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import Search from './components/Search.svelte';
|
||||
import { IconFileAnalytics, IconSearch, IconSourceCode } from '@tabler/icons-svelte';
|
||||
import { router } from 'tinro';
|
||||
import { search, filteredResources, generalData } from '../../store';
|
||||
</script>
|
||||
|
||||
<div class="p-2 w-full h-full flex justify-between gap-2">
|
||||
<div class="bg-dark-700 p-4 pr-0 flex flex-col w-2/3 rounded-md">
|
||||
<div class="pr-4 flex justify-between items-center">
|
||||
<div class="flex gap-3 items-center ">
|
||||
<p class="text-2xl">Resources</p>
|
||||
<IconSourceCode />
|
||||
</div>
|
||||
<Search icon={IconSearch} bind:value={$search} />
|
||||
</div>
|
||||
<div class="flex flex-col gap-3 mt-6 overflow-y-auto pr-4">
|
||||
{#each $filteredResources as resource}
|
||||
<button
|
||||
on:click={() => router.goto(`/${resource}`)}
|
||||
class="bg-dark-600 p-3 border-[1px] outline-none border-transparent focus-visible:border-cyan-600 text-left hover:bg-dark-400 rounded-md"
|
||||
>
|
||||
{resource}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-dark-700 p-4 flex flex-col w-1/3 rounded-md">
|
||||
<div class="flex gap-3 items-center mb-4">
|
||||
<p class="text-2xl">General data</p>
|
||||
<IconFileAnalytics />
|
||||
</div>
|
||||
<div class="flex flex-col text-dark-50">
|
||||
<p>Queries: {$generalData.queries}</p>
|
||||
<p>Time querying: {$generalData.timeQuerying} ms</p>
|
||||
<p class="text-yellow-500">Slow queries: {$generalData.slowQueries}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script lang="ts">
|
||||
export let icon: ConstructorOfATypedSvelteComponent;
|
||||
export let value: string;
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="p-2 flex items-center outline-none border-[1px] border-transparent transition-all duration-100 focus-within:border-cyan-600 rounded-md bg-dark-600"
|
||||
>
|
||||
<div class="pr-2">
|
||||
<svelte:component this={icon} class="text-dark-300" />
|
||||
</div>
|
||||
<input type="text" bind:value class="bg-transparent outline-none w-full" placeholder="Search resources..." />
|
||||
</div>
|
||||
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
return () => clearTimeout(timeout);
|
||||
});
|
||||
|
||||
export const resources = writable<string[]>([]);
|
||||
|
||||
export const filteredResources = derived(
|
||||
[resources, debouncedSearch],
|
||||
([$resources, $debouncedSearch], set: (value: string[]) => void) => {
|
||||
if ($debouncedSearch === '' || !$debouncedSearch) return set($resources);
|
||||
|
||||
const query = $debouncedSearch.toLowerCase();
|
||||
|
||||
return set($resources.filter((resource) => resource.toLowerCase().includes(query)));
|
||||
}
|
||||
);
|
||||
|
||||
export const generalData = writable({
|
||||
queries: 0,
|
||||
timeQuerying: 0,
|
||||
slowQueries: 0,
|
||||
});
|
||||
@@ -13,7 +13,7 @@ interface DebugEvent<T = any> {
|
||||
* @param timer - How long until it should trigger (ms)
|
||||
*/
|
||||
export const debugData = <P>(events: DebugEvent<P>[], timer = 1000): void => {
|
||||
if (process.env.NODE_ENV === 'development' && isEnvBrowser()) {
|
||||
if (isEnvBrowser()) {
|
||||
for (const event of events) {
|
||||
setTimeout(() => {
|
||||
window.dispatchEvent(
|
||||
@@ -1,17 +1,11 @@
|
||||
/**
|
||||
* Simple wrapper around fetch API tailored for CEF/NUI use. This abstraction
|
||||
* can be extended to include AbortController if needed or if the response isn't
|
||||
* JSON. Tailor it to your needs.
|
||||
*
|
||||
* @param eventName - The endpoint eventname to target
|
||||
* @param data - Data you wish to send in the NUI Callback
|
||||
*
|
||||
* @return returnData - A promise for the data sent back by the NuiCallbacks CB argument
|
||||
*/
|
||||
|
||||
import { isEnvBrowser } from './misc';
|
||||
|
||||
export async function fetchNui<T = any>(eventName: string, data?: any): Promise<T> {
|
||||
export async function fetchNui<T = any>(eventName: string, data: unknown = {}): Promise<T> {
|
||||
const options = {
|
||||
method: 'post',
|
||||
headers: {
|
||||
@@ -20,15 +14,11 @@ export async function fetchNui<T = any>(eventName: string, data?: any): Promise<
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
|
||||
if (isEnvBrowser()) return undefined as any;
|
||||
|
||||
const resourceName = (window as any).GetParentResourceName
|
||||
? (window as any).GetParentResourceName()
|
||||
: 'nui-frame-app';
|
||||
|
||||
const resp = await fetch(`https://${resourceName}/${eventName}`, options);
|
||||
|
||||
const respFormatted = await resp.json();
|
||||
|
||||
return respFormatted;
|
||||
return await resp.json();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export const isEnvBrowser = (): boolean => !(window as any).invokeNative;
|
||||
@@ -0,0 +1,28 @@
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
|
||||
interface NuiMessage<T = unknown> {
|
||||
action: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* A function that manage events listeners for receiving data from the client scripts
|
||||
* @param action The specific `action` that should be listened for.
|
||||
* @param handler The callback function that will handle data relayed by this function
|
||||
*
|
||||
* @example
|
||||
* useNuiEvent<{visibility: true, wasVisible: 'something'}>('setVisible', (data) => {
|
||||
* // whatever logic you want
|
||||
* })
|
||||
*
|
||||
**/
|
||||
|
||||
export function useNuiEvent<T = unknown>(action: string, handler: (data: T) => void) {
|
||||
const eventListener = (event: MessageEvent<NuiMessage<T>>) => {
|
||||
const { action: eventAction, data } = event.data;
|
||||
|
||||
eventAction === action && handler(data);
|
||||
};
|
||||
onMount(() => window.addEventListener('message', eventListener));
|
||||
onDestroy(() => window.removeEventListener('message', eventListener));
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/// <reference types="svelte" />
|
||||
/// <reference types="vite/client" />
|
||||
@@ -0,0 +1,7 @@
|
||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
export default {
|
||||
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ['./index.html', './src/**/*.{js,ts,svelte}'],
|
||||
theme: {
|
||||
extend: {
|
||||
fontFamily: {
|
||||
main: 'Roboto',
|
||||
},
|
||||
colors: {
|
||||
// Mantine dark colours
|
||||
dark: {
|
||||
50: '#C1C2C5',
|
||||
100: '#A6A7AB',
|
||||
200: '#909296',
|
||||
300: '#5C5F66',
|
||||
400: '#373A40',
|
||||
500: '#2C2E33',
|
||||
600: '#25262B',
|
||||
700: '#1A1B1E',
|
||||
800: '#141517',
|
||||
900: '#101113',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"resolveJsonModule": true,
|
||||
/**
|
||||
* Typecheck JS in `.svelte` and `.js` files by default.
|
||||
* Disable checkJs if you'd like to use dynamic types in JS.
|
||||
* Note that setting allowJs false does not prevent the use
|
||||
* of JS in `.svelte` files.
|
||||
*/
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"isolatedModules": true
|
||||
},
|
||||
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node"
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [svelte()],
|
||||
base: './',
|
||||
server: {
|
||||
port: 3000,
|
||||
},
|
||||
build: {
|
||||
outDir: 'build',
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user