mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
656 B
25 lines
656 B
2 years ago
|
import type { TableType, ViewType } from 'nocodb-sdk'
|
||
2 years ago
|
import type { MaybeRef } from '@vueuse/core'
|
||
2 years ago
|
import { unref, useNuxtApp, watch } from '#imports'
|
||
2 years ago
|
|
||
2 years ago
|
export function useViews(meta: MaybeRef<TableType | undefined>) {
|
||
2 years ago
|
let views = $ref<ViewType[]>([])
|
||
2 years ago
|
|
||
2 years ago
|
const { $api } = useNuxtApp()
|
||
2 years ago
|
|
||
|
const loadViews = async () => {
|
||
2 years ago
|
const _meta = unref(meta)
|
||
|
|
||
|
if (_meta && _meta.id) {
|
||
2 years ago
|
const response = (await $api.dbView.list(_meta.id)).list as ViewType[]
|
||
2 years ago
|
if (response) {
|
||
2 years ago
|
views = response.sort((a, b) => a.order! - b.order!)
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
watch(() => meta, loadViews, { immediate: true })
|
||
2 years ago
|
|
||
|
return { views: $$(views), loadViews }
|
||
2 years ago
|
}
|