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

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 }
}
+22
View File
@@ -0,0 +1,22 @@
import { usePartsCatalog } from '@/composables/usePartsCatalog'
export async function resolveTopic(source, id) {
if (source === 'parts') {
const { loadParts, getPartById } = usePartsCatalog()
await loadParts()
const part = getPartById(Number(id))
if (!part) {
return null
}
return {
title: part.name,
subtitle: part.category,
image: part.image,
description: part.description,
}
}
return null
}