From 5e3bc019225aa9849934eb689e18631673becdc1 Mon Sep 17 00:00:00 2001 From: Joel Jacob Stephen <70131076+JoelJacobStephen@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:14:52 +0530 Subject: [PATCH] refactor(common): improvements to banner handling logic (#4123) --- .../src/components/app/Header.vue | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/hoppscotch-common/src/components/app/Header.vue b/packages/hoppscotch-common/src/components/app/Header.vue index e4378226..07ae5e73 100644 --- a/packages/hoppscotch-common/src/components/app/Header.vue +++ b/packages/hoppscotch-common/src/components/app/Header.vue @@ -214,7 +214,7 @@ banner.content.value?.content) -let bannerID: number | null = null +let offlineBannerID: number | null = null const offlineBanner: BannerContent = { type: "warning", text: (t) => t("helpers.offline"), alternateText: (t) => t("helpers.offline_short"), - score: BANNER_PRIORITY_HIGH, + score: BANNER_PRIORITY_LOW, dismissible: true, } +// Show the offline banner if the app is offline const network = reactive(useNetwork()) const isOnline = computed(() => network.isOnline) -// Show the offline banner if the user is offline watch(isOnline, () => { if (!isOnline.value) { - bannerID = banner.showBanner(offlineBanner) + offlineBannerID = banner.showBanner(offlineBanner) return } - if (banner.content && bannerID) { - banner.removeBanner(bannerID) + if (banner.content && offlineBannerID) { + banner.removeBanner(offlineBannerID) } }) -const dismissOfflineBanner = () => banner.removeBanner(bannerID!) +const dismissBanner = () => { + if (banner.content.value) { + banner.removeBanner(banner.content.value.id) + } else if (offlineBannerID) { + banner.removeBanner(offlineBannerID) + offlineBannerID = null + } +} const currentUser = useReadonlyStream( platform.auth.getProbableUserStream(),