mirror of https://github.com/nocodb/nocodb
braks
2 years ago
5 changed files with 16 additions and 27 deletions
@ -1,28 +1,28 @@
|
||||
import type { TableType, ViewType } from 'nocodb-sdk' |
||||
import type { MaybeRef } from '@vueuse/core' |
||||
import { unref, useNuxtApp, watch } from '#imports' |
||||
import { ref, unref, useNuxtApp, watch } from '#imports' |
||||
|
||||
export function useViews(meta: MaybeRef<TableType | undefined>) { |
||||
let views = $ref<ViewType[]>([]) |
||||
let isLoading = $ref(false) |
||||
const views = ref<ViewType[]>([]) |
||||
const isLoading = ref(false) |
||||
|
||||
const { $api } = useNuxtApp() |
||||
|
||||
const loadViews = async () => { |
||||
isLoading = true |
||||
isLoading.value = true |
||||
const _meta = unref(meta) |
||||
|
||||
if (_meta && _meta.id) { |
||||
const response = (await $api.dbView.list(_meta.id)).list as ViewType[] |
||||
if (response) { |
||||
views = response.sort((a, b) => a.order! - b.order!) |
||||
views.value = response.sort((a, b) => a.order! - b.order!) |
||||
} |
||||
} |
||||
|
||||
isLoading = false |
||||
isLoading.value = false |
||||
} |
||||
|
||||
watch(() => meta, loadViews, { immediate: true }) |
||||
|
||||
return { views: $$(views), isLoading: $$(isLoading), loadViews } |
||||
return { views, isLoading, loadViews } |
||||
} |
||||
|
Loading…
Reference in new issue