Вынес Запчасти в боковое меню

This commit is contained in:
Ilia Miheev
2026-06-02 22:59:06 +03:00
parent 9db8220fdb
commit 5272c1ddf7
7 changed files with 241 additions and 11 deletions
+36
View File
@@ -0,0 +1,36 @@
import { ref } from 'vue'
const parts = ref([])
let loadPromise = null
export function usePartsCatalog() {
async function loadParts() {
if (parts.value.length) {
return parts.value
}
if (!loadPromise) {
loadPromise = fetch('/droneComponents/components.json')
.then((response) => (response.ok ? response.json() : []))
.then((data) => {
parts.value = data
return data
})
.catch(() => {
parts.value = []
return []
})
.finally(() => {
loadPromise = null
})
}
return loadPromise
}
function getPartById(id) {
return parts.value.find((part) => part.id === id) ?? null
}
return { parts, loadParts, getPartById }
}