add element child list

This commit is contained in:
Yisroel Baum 2026-05-26 20:16:22 +03:00
parent aa746fe3f0
commit 7350d747f3
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
9 changed files with 186 additions and 10 deletions

View file

@ -8,17 +8,20 @@ export interface Element {
interface ElementResponse {
element: Element
childElements: Element[]
}
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL as string
export const useElementsStore = defineStore('elements', () => {
const element = ref<Element | null>(null)
const childElements = ref<Element[]>([])
const isLoading = ref(false)
const error = ref<string | null>(null)
async function fetchElement(elementId: string): Promise<void> {
element.value = null
childElements.value = []
error.value = null
isLoading.value = true
@ -39,12 +42,14 @@ export const useElementsStore = defineStore('elements', () => {
const data: ElementResponse = await response.json()
element.value = data.element
childElements.value = data.childElements
} catch {
childElements.value = []
error.value = 'Network error - could not load element'
} finally {
isLoading.value = false
}
}
return { element, isLoading, error, fetchElement }
return { element, childElements, isLoading, error, fetchElement }
})