From d59168190132c1fe9dc04b576fe77c9cf1d3f1cc Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Wed, 29 Mar 2023 15:24:31 +0800 Subject: [PATCH 1/3] Fix is initialized logic in postgresmeta interace --- studio/pages/projects.tsx | 5 +++++ studio/stores/common/PostgresMetaInterface.ts | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/studio/pages/projects.tsx b/studio/pages/projects.tsx index c3da53796bb..c67987910e6 100644 --- a/studio/pages/projects.tsx +++ b/studio/pages/projects.tsx @@ -10,6 +10,11 @@ import { NextPageWithLayout } from 'types' const ProjectsPage: NextPageWithLayout = () => { const { app } = useStore() + console.log({ + isInitialized: app.organizations.isInitialized, + isLoading: app.organizations.isLoading, + }) + return ( <> {!app.organizations.isInitialized ? ( diff --git a/studio/stores/common/PostgresMetaInterface.ts b/studio/stores/common/PostgresMetaInterface.ts index bd51fd319d5..d73b33ed6a3 100644 --- a/studio/stores/common/PostgresMetaInterface.ts +++ b/studio/stores/common/PostgresMetaInterface.ts @@ -47,6 +47,7 @@ export default class PostgresMetaInterface implements IPostgresMetaInterface< state = this.STATES.INITIAL data: { [key in DataKeys]: T } = {} headers: any = {} + isInitialized: boolean = false constructor( rootStore: IRootStore, @@ -90,10 +91,6 @@ export default class PostgresMetaInterface implements IPostgresMetaInterface< return this.state === this.STATES.INITIAL || this.state === this.STATES.LOADING } - get isInitialized() { - return this.state === this.STATES.LOADED || this.state === this.STATES.ERROR - } - async fetchData() { const headers = { 'Content-Type': 'application/json', ...this.headers } const response = await get(this.url, { headers }) @@ -109,6 +106,7 @@ export default class PostgresMetaInterface implements IPostgresMetaInterface< this.setError(null) this.setState(LOADING) await this.fetchData() + if (!this.isInitialized) this.isInitialized = true this.setState(LOADED) } catch (e: any) { console.error('Load error message', e.message) From ac822e30f8086c2f33c5eefc78b547c54035b060 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Wed, 29 Mar 2023 15:24:59 +0800 Subject: [PATCH 2/3] Remove console log --- studio/pages/projects.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/studio/pages/projects.tsx b/studio/pages/projects.tsx index c67987910e6..c3da53796bb 100644 --- a/studio/pages/projects.tsx +++ b/studio/pages/projects.tsx @@ -10,11 +10,6 @@ import { NextPageWithLayout } from 'types' const ProjectsPage: NextPageWithLayout = () => { const { app } = useStore() - console.log({ - isInitialized: app.organizations.isInitialized, - isLoading: app.organizations.isLoading, - }) - return ( <> {!app.organizations.isInitialized ? ( From ff91fc73f49f5c27b1e93d3fb0b1e5b6661051d0 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Wed, 29 Mar 2023 15:27:01 +0800 Subject: [PATCH 3/3] Shift setting isInitialized into the finally block --- studio/stores/common/PostgresMetaInterface.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/studio/stores/common/PostgresMetaInterface.ts b/studio/stores/common/PostgresMetaInterface.ts index d73b33ed6a3..72496fa116e 100644 --- a/studio/stores/common/PostgresMetaInterface.ts +++ b/studio/stores/common/PostgresMetaInterface.ts @@ -106,12 +106,13 @@ export default class PostgresMetaInterface implements IPostgresMetaInterface< this.setError(null) this.setState(LOADING) await this.fetchData() - if (!this.isInitialized) this.isInitialized = true this.setState(LOADED) } catch (e: any) { console.error('Load error message', e.message) this.setError(e) this.setState(ERROR) + } finally { + if (!this.isInitialized) this.isInitialized = true } }