add element child list
This commit is contained in:
parent
aa746fe3f0
commit
7350d747f3
9 changed files with 186 additions and 10 deletions
|
|
@ -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 }
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue