Skip to content

Commit

Permalink
feat(ui): Setting resource list from NUI message
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed Dec 28, 2021
1 parent 49bf5bb commit ce802e7
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 33 deletions.
18 changes: 18 additions & 0 deletions ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@
import VisibilityProvider from './providers/VisibilityProvider.svelte';
import Main from './components/Main.svelte';
import { debugData } from './utils/debugData';
import { useNuiEvent } from './utils/useNuiEvent';
import { resources } from './store/stores';
import type { InitData } from './types/init';
debugData([
{
action: 'setVisible',
data: true,
},
]);
debugData([
{
action: 'init',
data: {
resources: ['ox_inventory', 'luke_garages', 'npwd'],
totalQueries: 350,
totalTime: 75000,
},
},
]);
useNuiEvent<InitData>('init', (data) => {
resources.set(data.resources);
});
</script>

<main>
Expand Down
9 changes: 6 additions & 3 deletions ui/src/components/menu/NavMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts">
import { currentResource } from '../../store/stores';
const executingResources = ['luke_garages', 'ox_inventory', 'npwd'];
import { resources } from '../../store/stores';
</script>

<div class="container">
<a href="#/"><div class="home-header">Home</div></a>
{#each executingResources as resource}
{#each $resources as resource}
<div class="resource-wrapper">
<a href={`#/${resource}`}>
<div class="resource" on:click={() => currentResource.set(resource)}>
Expand Down Expand Up @@ -55,7 +55,10 @@
background-color: grey;
}
a:visited {
a,
a:visited,
a:active,
a:focus {
color: white;
}
</style>
25 changes: 3 additions & 22 deletions ui/src/components/routes/Home.svelte
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
<script lang="ts">
import { useNuiEvent } from '../../utils/useNuiEvent';
import { debugData } from '../../utils/debugData';
import type { InitData } from '../../types/init';
debugData([
{
action: 'init',
data: {
resources: ['ox_inventory', 'luke_garages', 'npwd'],
totalQueries: 350,
totalTime: 75000,
},
},
]);
let initData: InitData;
interface QueryData {
date: number;
query: string;
executionTime: number;
}
type QueryLog = Record<string, QueryData[]>;
let initData: QueryLog;
useNuiEvent('init', (data: QueryLog) => {
useNuiEvent<InitData>('init', (data) => {
initData = data;
});
</script>
Expand Down
9 changes: 2 additions & 7 deletions ui/src/components/routes/ResourceData.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
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 };
interface QueryData {
date: number;
query: string;
executionTime: number;
}
let queryData: QueryData[] | undefined;
let queryData: QueryData[];
let isDataLoaded: boolean = false;
onMount(() => currentResource.set(params.wild));
Expand Down
3 changes: 2 additions & 1 deletion ui/src/store/stores.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { writable } from "svelte/store";

export const visibility = writable(false);
export const currentResource = writable('');
export const currentResource = writable('');
export const resources = writable<string[]>([])
5 changes: 5 additions & 0 deletions ui/src/types/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type InitData = {
resources: string[];
totalQueries: number;
totalTime: number;
}
5 changes: 5 additions & 0 deletions ui/src/types/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type QueryData = {
date: number;
query: string;
executionTime: number;
}

0 comments on commit ce802e7

Please sign in to comment.