mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-04 14:38:50 +00:00
refactor: Use store to set current resource
This commit is contained in:
1 parent
023023555a
commit
7ac6de6b26
3 files changed
+37
-2
No files matched your search
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { currentResource } from '../../store/stores';
|
||||||
const executingResources = ['luke_garages', 'ox_inventory', 'npwd'];
|
const executingResources = ['luke_garages', 'ox_inventory', 'npwd'];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -7,7 +8,7 @@
|
|||||||
{#each executingResources as resource}
|
{#each executingResources as resource}
|
||||||
<div class="resource-wrapper">
|
<div class="resource-wrapper">
|
||||||
<a href={`#/${resource}`}>
|
<a href={`#/${resource}`}>
|
||||||
<div class="resource">
|
<div class="resource" on:click={() => currentResource.set(resource)}>
|
||||||
{resource}
|
{resource}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -1,5 +1,38 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { currentResource } from '../../store/stores';
|
||||||
|
import { fetchNui } from '../../utils/fetchNui';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
export let params: { wild: string };
|
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>
|
</script>
|
||||||
|
|
||||||
<div>{params.wild}</div>
|
<div>
|
||||||
|
{resource}
|
||||||
|
{queryData}
|
||||||
|
</div>
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
|
|
||||||
export const visibility = writable(false);
|
export const visibility = writable(false);
|
||||||
|
export const currentResource = writable('');
|
||||||
Reference in new issue
Block a user