Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: initial basic data in App.vue (#12766)

boojackc691a820a9e8
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index 3ff61ef504..66de7640da 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -15,7 +15,13 @@
<OverlayStackManager>
<KBarWrapper>
<NotificationContext>
- <router-view />
+ <router-view v-if="initialized" />
+ <div
+ v-else
+ class="fixed inset-0 bg-white flex flex-col items-center justify-center"
+ >
+ <NSpin />
+ </div>
</NotificationContext>
</KBarWrapper>
</OverlayStackManager>
@@ -31,9 +37,10 @@ import {
NDialogProvider,
NNotificationProvider,
} from "naive-ui";
+import { NSpin } from "naive-ui";
import { ServerError } from "nice-grpc-common";
import { ClientError, Status } from "nice-grpc-web";
-import { reactive, onErrorCaptured } from "vue";
+import { onErrorCaptured, onMounted, ref } from "vue";
import { watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import Watermark from "@/components/misc/Watermark.vue";
@@ -44,7 +51,12 @@ import KBarWrapper from "./components/KBar/KBarWrapper.vue";
import OverlayStackManager from "./components/misc/OverlayStackManager.vue";
import { t } from "./plugins/i18n";
import { AUTH_SIGNIN_MODULE } from "./router/auth";
-import { useAuthStore, useNotificationStore } from "./store";
+import {
+ useActuatorV1Store,
+ useAuthStore,
+ useNotificationStore,
+ useSubscriptionV1Store,
+} from "./store";
import { isDev } from "./utils";
// Show at most 3 notifications to prevent excessive notification when shit hits the fan.
@@ -53,31 +65,57 @@ const MAX_NOTIFICATION_DISPLAY_COUNT = 3;
// Check expiration every 30 sec and logout if expired
const CHECK_LOGGEDIN_STATE_DURATION = 30 * 1000;
-interface LocalState {
- prevLoggedIn: boolean;
-}
-
const route = useRoute();
const router = useRouter();
const { key } = provideAppRootContext();
const authStore = useAuthStore();
const notificationStore = useNotificationStore();
+const initialized = ref(false);
+const prevLoggedIn = ref(false);
-const state = reactive<LocalState>({
- prevLoggedIn: authStore.isLoggedIn(),
-});
+onMounted(async () => {
+ const initActuator = async () => {
+ useActuatorV1Store().fetchServerInfo();
+ };
+ const initSubscription = async () => {
+ await useSubscriptionV1Store().fetchSubscription();
+ };
+ const initFeatureMatrix = async () => {
+ await useSubscriptionV1Store().fetchFeatureMatrix();
+ };
+ const restoreUser = async () => {
+ await useAuthStore().restoreUser();
+ };
+ const initBasicModules = async () => {
+ await Promise.all([
+ initActuator(),
+ initFeatureMatrix(),
+ initSubscription(),
+ // We need to restore the basic info in order to perform route authentication.
+ restoreUser(),
+ ]);
+ };
+
+ await initBasicModules();
+ initialized.value = true;
+ prevLoggedIn.value = authStore.isLoggedIn();
-setInterval(() => {
- const loggedIn = authStore.isLoggedIn();
- if (state.prevLoggedIn != loggedIn) {
- state.prevLoggedIn = loggedIn;
- if (!loggedIn) {
- authStore.logout().then(() => {
- router.push({ name: AUTH_SIGNIN_MODULE });
- });
+ setInterval(() => {
+ if (!initialized.value) {
+ return;
}
- }
-}, CHECK_LOGGEDIN_STATE_DURATION);
+
+ const loggedIn = authStore.isLoggedIn();
+ if (prevLoggedIn.value != loggedIn) {
+ prevLoggedIn.value = loggedIn;
+ if (!loggedIn) {
+ authStore.logout().then(() => {
+ router.push({ name: AUTH_SIGNIN_MODULE });
+ });
+ }
+ }
+ }, CHECK_LOGGEDIN_STATE_DURATION);
+});
onErrorCaptured((error: any /* , _, info */) => {
// Handle grpc request error.
diff --git a/frontend/src/Splash.vue b/frontend/src/Splash.vue
deleted file mode 100644
index b7439254f9..0000000000
--- a/frontend/src/Splash.vue
+++ /dev/null
@@ -1,33 +0,0 @@
-<template>
- <NConfigProvider
- :locale="generalLang"
- :date-locale="dateLang"
- :theme-overrides="themeOverrides"
- >
- <NNotificationProvider
- :max="MAX_NOTIFICATION_DISPLAY_COUNT"
- placement="bottom-right"
- >
- <NDialogProvider>
- <NotificationContext>
- <div class="fixed inset-0 bg-white flex flex-col items-center justify-center">
- <NSpin />
- </div>
- </NotificationContext>
- </NDialogProvider>
- </NNotificationProvider>
- </NConfigProvider>
-</template>
-
-<script lang="ts" setup>
-import {
- NConfigProvider,
- NDialogProvider,
- NNotificationProvider,
- NSpin,
-} from "naive-ui";
-import { themeOverrides, dateLang, generalLang } from "../naive-ui.config";
-import NotificationContext from "./NotificationContext.vue";
-
-const MAX_NOTIFICATION_DISPLAY_COUNT = 3;
-</script>
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 1c983e052f..4b022c07f9 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -4,7 +4,6 @@ import Long from "long";
import protobufjs from "protobufjs";
import { createApp } from "vue";
import App from "./App.vue";
-import Splash from "./Splash.vue";
import "./assets/css/github-markdown-style.css";
import "./assets/css/inter.css";
import "./assets/css/tailwind.css";
@@ -22,7 +21,6 @@ import {
pushNotification,
useActuatorV1Store,
useAuthStore,
- useSubscriptionV1Store,
} from "./store";
import {
environmentName,
@@ -173,39 +171,7 @@ const initSearchParams = () => {
}
};
-// We need to restore the basic info in order to perform route authentication.
-// Even using the <suspense>, it's still too late, thus we do the fetch here.
-// We use finally because we always want to mount the app regardless of the error.
-const initActuator = async () => {
- useActuatorV1Store().fetchServerInfo();
-};
-const initSubscription = async () => {
- await useSubscriptionV1Store().fetchSubscription();
-};
-const initFeatureMatrix = async () => {
- await useSubscriptionV1Store().fetchFeatureMatrix();
-};
-const restoreUser = async () => {
- await useAuthStore().restoreUser();
-};
-const initBasicModules = async () => {
- await Promise.all([
- initActuator(),
- initFeatureMatrix(),
- initSubscription(),
- restoreUser(),
- ]);
-};
-
initSearchParams();
-const splash = createApp(Splash);
-splash.use(pinia).use(NaiveUI).mount("#app");
-
-initBasicModules().finally(() => {
- splash.unmount();
-
- // Install router after the necessary data fetching is complete.
- app.use(router).use(highlight).use(i18n).use(NaiveUI);
- app.mount("#app");
-});
+app.use(router).use(highlight).use(i18n).use(NaiveUI);
+app.mount("#app");