diff --git a/src/ModManUi/src/stores/AssetStore.ts b/src/ModManUi/src/stores/AssetStore.ts new file mode 100644 index 00000000..52762b02 --- /dev/null +++ b/src/ModManUi/src/stores/AssetStore.ts @@ -0,0 +1,26 @@ +import { computed, ref } from "vue"; +import { defineStore } from "pinia"; +import type { ZoneAssetsDto } from "@/native/AssetBinds"; +import { webviewBinds } from "@/native"; + +export const useAssetStore = defineStore("asset", () => { + const zoneName = ref(null); + const assetsOfZone = ref(null); + + const isLoading = computed(() => Boolean(assetsOfZone.value)); + const assetCount = computed(() => assetsOfZone.value?.assets.length ?? 0); + const referenceCount = computed(() => assetsOfZone.value?.references.length ?? 0); + + function loadAssetsForZone(newZoneName: string | null) { + zoneName.value = newZoneName; + assetsOfZone.value = null; + if (!newZoneName) return; + webviewBinds.getAssetsForZone(newZoneName).then((res) => { + if (zoneName.value === newZoneName) { + assetsOfZone.value = res; + } + }); + } + + return { zoneName, isLoading, assetsOfZone, assetCount, referenceCount, loadAssetsForZone }; +}); diff --git a/src/ModManUi/src/view/inspect/ZoneInspectorDetails.vue b/src/ModManUi/src/view/inspect/ZoneInspectorDetails.vue index 7652fa01..89f0c61e 100644 --- a/src/ModManUi/src/view/inspect/ZoneInspectorDetails.vue +++ b/src/ModManUi/src/view/inspect/ZoneInspectorDetails.vue @@ -6,23 +6,23 @@ import Skeleton from "primevue/skeleton"; import { dt } from "@primeuix/themes"; import type { ZoneDto } from "@/native/ZoneBinds"; import { useZoneStore } from "@/stores/ZoneStore"; -import { computed, ref, watch } from "vue"; -import type { CommonAssetType, ZoneAssetsDto } from "@/native/AssetBinds"; -import { webviewBinds } from "@/native"; +import { computed, watch } from "vue"; +import type { CommonAssetType } from "@/native/AssetBinds"; import { getAssetTypeNameCapitalized } from "@/utils/AssetTypeName"; import { useRouter } from "vue-router"; import { PAGE } from "@/router/Page"; +import { useAssetStore } from "@/stores/AssetStore"; +import { storeToRefs } from "pinia"; +const assetStore = useAssetStore(); const zoneStore = useZoneStore(); +const { assetsOfZone, assetCount, referenceCount } = storeToRefs(assetStore); + const props = defineProps<{ selectedZone: string | null; }>(); -const assets = ref(null); -const assetCount = computed(() => assets.value?.assets.length ?? 0); -const referenceCount = computed(() => assets.value?.references.length ?? 0); - const METER_COLORS = [ dt("blue.600"), dt("red.600"), @@ -37,7 +37,7 @@ const METER_COLORS = [ const meterItems = computed(() => { const assetTypeCounts: Partial> = {}; - for (const asset of assets.value?.assets ?? []) { + for (const asset of assetsOfZone.value?.assets ?? []) { if (!assetTypeCounts[asset.type]) { assetTypeCounts[asset.type] = 1; } else { @@ -94,13 +94,7 @@ function onClickShowAssets() { watch( () => props.selectedZone, (newValue) => { - assets.value = null; - if (!newValue) return; - webviewBinds.getAssetsForZone(newValue).then((res) => { - if (props.selectedZone === newValue) { - assets.value = res; - } - }); + assetStore.loadAssetsForZone(newValue); }, { immediate: true }, ); @@ -115,7 +109,7 @@ watch(
-