4040 <template #content >
4141 <AssetGrid
4242 :assets =" filteredAssets"
43+ :loading =" isLoading"
4344 @asset-select =" handleAssetSelectAndEmit"
4445 />
4546 </template >
4647 </BaseModalLayout >
4748</template >
4849
4950<script setup lang="ts">
50- import { computed , provide } from ' vue'
51+ import { useAsyncState } from ' @vueuse/core'
52+ import { computed , provide , watch } from ' vue'
53+ import { useI18n } from ' vue-i18n'
5154
5255import SearchBox from ' @/components/input/SearchBox.vue'
5356import BaseModalLayout from ' @/components/widget/layout/BaseModalLayout.vue'
@@ -57,6 +60,9 @@ import AssetGrid from '@/platform/assets/components/AssetGrid.vue'
5760import type { AssetDisplayItem } from ' @/platform/assets/composables/useAssetBrowser'
5861import { useAssetBrowser } from ' @/platform/assets/composables/useAssetBrowser'
5962import type { AssetItem } from ' @/platform/assets/schemas/assetSchema'
63+ import { assetService } from ' @/platform/assets/services/assetService'
64+ import { formatCategoryLabel } from ' @/platform/assets/utils/categoryLabel'
65+ import { useModelToNodeStore } from ' @/stores/modelToNodeStore'
6066import { OnCloseKey } from ' @/types/widgetTypes'
6167
6268const props = defineProps <{
@@ -65,29 +71,86 @@ const props = defineProps<{
6571 onSelect? : (asset : AssetItem ) => void
6672 onClose? : () => void
6773 showLeftPanel? : boolean
68- assets? : AssetItem []
6974 title? : string
75+ assetType? : string
7076}>()
7177
78+ const { t } = useI18n ()
79+
7280const emit = defineEmits <{
7381 ' asset-select' : [asset : AssetDisplayItem ]
7482 close: []
7583}>()
7684
7785provide (OnCloseKey , props .onClose ?? (() => {}))
7886
87+ const fetchAssets = async () => {
88+ if (props .nodeType ) {
89+ return (await assetService .getAssetsForNodeType (props .nodeType )) ?? []
90+ }
91+
92+ if (props .assetType ) {
93+ return (await assetService .getAssetsByTag (props .assetType )) ?? []
94+ }
95+
96+ return []
97+ }
98+
99+ const {
100+ state : fetchedAssets,
101+ isLoading,
102+ execute
103+ } = useAsyncState <AssetItem []>(fetchAssets , [], { immediate: false })
104+
105+ watch (
106+ () => [props .nodeType , props .assetType ],
107+ async () => {
108+ await execute ()
109+ },
110+ { immediate: true }
111+ )
112+
79113const {
80114 searchQuery,
81115 selectedCategory,
82116 availableCategories,
83- contentTitle,
84117 categoryFilteredAssets,
85118 filteredAssets,
86119 updateFilters
87- } = useAssetBrowser (props .assets )
120+ } = useAssetBrowser (fetchedAssets )
121+
122+ const modelToNodeStore = useModelToNodeStore ()
123+
124+ const primaryCategoryTag = computed (() => {
125+ const assets = fetchedAssets .value ?? []
126+ const tagFromAssets = assets
127+ .map ((asset ) => asset .tags ?.find ((tag ) => tag !== ' models' ))
128+ .find ((tag ): tag is string => typeof tag === ' string' && tag .length > 0 )
129+
130+ if (tagFromAssets ) return tagFromAssets
131+
132+ if (props .nodeType ) {
133+ const mapped = modelToNodeStore .getCategoryForNodeType (props .nodeType )
134+ if (mapped ) return mapped
135+ }
136+
137+ if (props .assetType ) return props .assetType
138+
139+ return ' models'
140+ })
141+
142+ const activeCategoryTag = computed (() => {
143+ if (selectedCategory .value !== ' all' ) {
144+ return selectedCategory .value
145+ }
146+ return primaryCategoryTag .value
147+ })
88148
89149const displayTitle = computed (() => {
90- return props .title ?? contentTitle .value
150+ if (props .title ) return props .title
151+
152+ const label = formatCategoryLabel (activeCategoryTag .value )
153+ return t (' assetBrowser.allCategory' , { category: label })
91154})
92155
93156const shouldShowLeftPanel = computed (() => {
0 commit comments