chore(nui): WIP React rewrite

This commit is contained in:
Luke committed 2021-12-30 20:05:07 +01:00
1 parent ce802e7553
commit b2b1a64c8f
35 files changed
+391 -460

No files matched your search

View File
Whitespace-only changes.
+25
View File
@@ -0,0 +1,25 @@
import './App.css';
import { Center, Box } from '@chakra-ui/react';
import { debugData } from '../utils/debugData';
import TopBar from './NavBars/TopBar';
import SideBar from './NavBars/SideBar';
debugData([
{
action: 'setVisible',
data: true,
},
]);
const App: React.FC = () => {
return (
<Center w="100%" h="100%">
<Box width="60%" height="60%" backgroundColor="#191E26" borderRadius="1vh" color="white" fontFamily="Poppins">
<TopBar />
<SideBar />
</Box>
</Center>
);
};
export default App;
-49
View File
@@ -1,49 +0,0 @@
<script lang="ts">
import Router from 'svelte-spa-router';
import Resources from './menu/NavMenu.svelte';
import Home from './routes/Home.svelte';
import ResourceData from './routes/ResourceData.svelte';
const routes = {
'/': Home,
'/*': ResourceData,
};
</script>
<div class="container">
<Resources />
<div class="content-wrapper">
<div class="content-container">
<Router {routes} />
</div>
</div>
</div>
<style>
.container {
width: 55%;
height: 65%;
background-color: rgb(44, 62, 80);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 0.25vh;
}
.content-wrapper {
margin-left: 18vh;
height: 100%;
display: grid;
place-items: center;
}
.content-container {
width: 85%;
height: 85%;
background-color: #34495e;
border-radius: 0.25vh;
color: white;
font-family: 'Inter', sans-serif;
}
</style>
+15
View File
@@ -0,0 +1,15 @@
import { Box, VStack } from '@chakra-ui/react';
const SideBar: React.FC = () => {
return (
<Box p="1.2vh" fontSize="1.5vh" position="fixed">
<VStack align="left">
<Box>es_extended</Box>
<Box>ox_inventory</Box>
<Box>luke_garages</Box>
</VStack>
</Box>
);
};
export default SideBar;
+13
View File
@@ -0,0 +1,13 @@
import { Box } from '@chakra-ui/react';
const TopBar: React.FC = () => {
return (
<Box w="100%" h="5%">
<Box p="1.2vh" fontSize="2.2vh">
Resources
</Box>
</Box>
);
};
export default TopBar;
-64
View File
@@ -1,64 +0,0 @@
<script lang="ts">
import { currentResource } from '../../store/stores';
import { resources } from '../../store/stores';
</script>
<div class="container">
<a href="#/"><div class="home-header">Home</div></a>
{#each $resources as resource}
<div class="resource-wrapper">
<a href={`#/${resource}`}>
<div class="resource" on:click={() => currentResource.set(resource)}>
{resource}
</div>
</a>
</div>
{/each}
</div>
<style>
.container {
width: 18vh;
position: fixed;
left: 0;
top: 0;
background-color: #34495e;
height: 100%;
border-top-left-radius: 0.25vh;
border-bottom-left-radius: 0.25vh;
color: white;
font-family: 'Inter', sans-serif;
user-select: none;
}
.home-header {
font-size: 2.2vh;
text-align: left;
padding: 1vh;
border-bottom: 0.25vh solid grey;
}
.resource-wrapper {
padding: 1vh;
}
.resource {
font-family: 'Inter', sans-serif;
font-size: 2.2vh;
width: 100%;
height: 5%;
display: block;
}
.resource-wrapper:hover,
.home-header:hover {
background-color: grey;
}
a,
a:visited,
a:active,
a:focus {
color: white;
}
</style>
-18
View File
@@ -1,18 +0,0 @@
<script lang="ts">
import { useNuiEvent } from '../../utils/useNuiEvent';
import type { InitData } from '../../types/init';
let initData: InitData;
useNuiEvent<InitData>('init', (data) => {
initData = data;
});
</script>
<div>
{#if initData}
<div>Resources: {initData.resources}</div>
<div>Total queries: {initData.totalQueries}</div>
<div>Total time: {initData.totalTime}</div>
{/if}
</div>
@@ -1,40 +0,0 @@
<script lang="ts">
import { currentResource } from '../../store/stores';
import { fetchNui } from '../../utils/fetchNui';
import { onMount } from 'svelte';
import { useNuiEvent } from '../../utils/useNuiEvent';
import { debugData } from '../../utils/debugData';
import type { QueryData } from '../../types/query';
export let params: { wild: string };
let queryData: QueryData[];
let isDataLoaded: boolean = false;
onMount(() => currentResource.set(params.wild));
currentResource.subscribe((resource) => {
isDataLoaded = false;
fetchNui('fetchResource', resource);
debugData([
{
action: 'loadResource',
data: [
{ date: Date.now(), query: 'SELECT * FROM `somewhere`', executionTime: 2 },
{ date: Date.now(), query: 'SELECT * FROM `elsewhere`', executionTime: 5 },
{ date: Date.now(), query: 'SELECT * FROM `somewhere_elsewhere`', executionTime: 3 },
{ date: Date.now(), query: 'SELECT * FROM `selsewhere`', executionTime: 7 },
],
},
]);
});
useNuiEvent('loadResource', (data: QueryData[]) => {
queryData = data;
isDataLoaded = true;
});
</script>
{#if isDataLoaded === true}
{JSON.stringify(queryData)}
{/if}