frontend: refactor of the new build viewer

extracting the logic into composables
This commit is contained in:
2026-02-28 13:29:33 +01:00
parent 20ccb20738
commit 7833780bcb
5 changed files with 241 additions and 152 deletions

View File

@@ -0,0 +1,30 @@
/**
* Composable for fetching and managing item data from CDragon API
* Returns a reactive Map of item ID to item data
*/
export const useItemMap = () => {
const { data: items } = useFetch<Array<Item>>('/api/cdragon/items', {
lazy: true,
server: false
})
const itemMap = ref<Map<number, Item>>(new Map())
watch(
items,
(newItems) => {
if (Array.isArray(newItems)) {
const map = new Map<number, Item>()
for (const item of newItems) {
if (item?.id) {
map.set(item.id, item)
}
}
itemMap.value = map
}
},
{ immediate: true }
)
return { itemMap }
}