Skip to content

Commit

Permalink
refactor: Use store to set current resource
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed Dec 26, 2021
1 parent 0230235 commit 7ac6de6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ui/src/components/menu/NavMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { currentResource } from '../../store/stores';
const executingResources = ['luke_garages', 'ox_inventory', 'npwd'];
</script>

Expand All @@ -7,7 +8,7 @@
{#each executingResources as resource}
<div class="resource-wrapper">
<a href={`#/${resource}`}>
<div class="resource">
<div class="resource" on:click={() => currentResource.set(resource)}>
{resource}
</div>
</a>
Expand Down
35 changes: 34 additions & 1 deletion src/ui/src/components/routes/ResourceData.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
<script lang="ts">
import { currentResource } from '../../store/stores';
import { fetchNui } from '../../utils/fetchNui';
import { onMount } from 'svelte';
export let params: { wild: string };
interface Data {
[key: string]: number[];
}
let queryData: number[];
let resource: string;
const debugQueries: Data = {
['luke_garages']: [300, 200, 100],
['npwd']: [600, 300, 723],
['ox_inventory']: [30, 270, 350],
};
onMount(() => currentResource.set(params.wild));
currentResource.subscribe((value) => {
resource = value;
fetchNui('getResourceData', resource)
.then((retData) => {
queryData = retData;
})
.catch((e) => {
queryData = debugQueries[resource];
});
});
</script>

<div>{params.wild}</div>
<div>
{resource}
{queryData}
</div>
3 changes: 2 additions & 1 deletion src/ui/src/store/stores.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { writable } from "svelte/store";

export const visibility = writable(false);
export const visibility = writable(false);
export const currentResource = writable('');

0 comments on commit 7ac6de6

Please sign in to comment.