Вынес Запчасти в боковое меню
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user