Browse Source

refactor(gui): use table list to verify tables loaded successfully

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3708/head
Pranav C 2 years ago
parent
commit
6543b87429
  1. 8
      packages/nc-gui/composables/useProject.ts
  2. 7
      packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue

8
packages/nc-gui/composables/useProject.ts

@ -42,8 +42,6 @@ const [setup, use] = useInjectionState((_projectId?: MaybeRef<string>) => {
const projectId = computed(() => (_projectId ? unref(_projectId) : (route.params.projectId as string)))
const projectAndTablesLoaded = ref(false)
// todo: refactor path param name and variable name
const projectType = $computed(() => route.params.projectType as string)
@ -95,7 +93,6 @@ const [setup, use] = useInjectionState((_projectId?: MaybeRef<string>) => {
}
async function loadTables() {
projectAndTablesLoaded.value = false
if (project.value.id) {
const tablesResponse = await api.dbTable.list(project.value.id, {
includeM2M: includeM2M.value,
@ -103,11 +100,9 @@ const [setup, use] = useInjectionState((_projectId?: MaybeRef<string>) => {
if (tablesResponse.list) tables.value = tablesResponse.list
}
projectAndTablesLoaded.value = true
}
async function loadProject(id?: string) {
projectAndTablesLoaded.value = false
if (id) {
project.value = await api.project.read(projectId.value)
} else if (projectType === 'base') {
@ -133,8 +128,6 @@ const [setup, use] = useInjectionState((_projectId?: MaybeRef<string>) => {
setTheme(projectMeta.value?.theme)
projectLoadedHook.trigger(project.value)
projectAndTablesLoaded.value = true
}
async function updateProject(data: Partial<ProjectType>) {
@ -203,7 +196,6 @@ const [setup, use] = useInjectionState((_projectId?: MaybeRef<string>) => {
projectLoadedHook: projectLoadedHook.on,
reset,
isLoading,
projectAndTablesLoaded,
}
}, 'useProject')

7
packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue

@ -4,7 +4,7 @@ import { TabMetaInj } from '#imports'
const { getMeta } = useMetas()
const { project, projectLoadedHook, projectAndTablesLoaded } = useProject()
const { tables } = useProject()
const route = useRoute()
@ -15,11 +15,12 @@ const activeTab = inject(
computed(() => ({} as TabItem)),
)
/** wait until project and table loads since meta load requires table list **/
/** wait until table list loads since meta load requires table list **/
watch(
projectAndTablesLoaded,
() => tables.value.length,
(nextVal) => {
if (!nextVal) return
getMeta(route.params.title as string, true).finally(() => (loading.value = false))
loading.value = false
},

Loading…
Cancel
Save