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.
51 lines
1.3 KiB
51 lines
1.3 KiB
3 weeks ago
|
import type { ComputedRef, Ref } from 'vue'
|
||
|
import type { GalleryType, TableType, ViewType } from 'nocodb-sdk'
|
||
|
import type { EventHook } from '@vueuse/core'
|
||
|
|
||
|
export function useGalleryViewData(
|
||
|
_meta: Ref<TableType | undefined> | ComputedRef<TableType | undefined>,
|
||
|
viewMeta: Ref<ViewType | undefined> | ComputedRef<(ViewType & { id: string }) | undefined>,
|
||
|
where?: ComputedRef<string | undefined>,
|
||
|
) {
|
||
|
const isPublic = inject(IsPublicInj, ref(false))
|
||
|
|
||
|
const { $api } = useNuxtApp()
|
||
|
|
||
|
const tablesStore = useTablesStore()
|
||
|
|
||
|
const { activeTable } = storeToRefs(tablesStore)
|
||
|
|
||
|
const { sharedView } = useSharedView()
|
||
|
|
||
|
const meta = computed(() => _meta.value || activeTable.value)
|
||
|
|
||
|
const viewData = ref<GalleryType | undefined>()
|
||
|
|
||
|
const { cachedRows, syncCount, clearCache, deleteRow, loadData, navigateToSiblingRow, totalRows, fetchChunk, chunkStates } =
|
||
|
useInfiniteData({
|
||
|
meta,
|
||
|
viewMeta,
|
||
|
callbacks: {},
|
||
|
where,
|
||
|
})
|
||
|
|
||
|
async function loadGalleryData() {
|
||
|
if (!viewMeta?.value?.id) return
|
||
|
viewData.value = isPublic.value ? (sharedView.value?.view as GalleryType) : await $api.dbView.galleryRead(viewMeta.value.id)
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
cachedRows,
|
||
|
deleteRow,
|
||
|
loadData,
|
||
|
navigateToSiblingRow,
|
||
|
loadGalleryData,
|
||
|
viewData,
|
||
|
totalRows,
|
||
|
clearCache,
|
||
|
chunkStates,
|
||
|
syncCount,
|
||
|
fetchChunk,
|
||
|
}
|
||
|
}
|