refactor: allow banner service to hold multiple banners and display the banner with the highest score (#3556)

This commit is contained in:
Joel Jacob Stephen
2023-11-17 20:31:34 +05:30
committed by GitHub
parent a3aa9b68fc
commit 24ae090916
4 changed files with 112 additions and 48 deletions

View File

@@ -8,10 +8,10 @@
<span class="text-white">
<span v-if="banner.alternateText" class="md:hidden">
{{ banner.alternateText }}
{{ banner.alternateText(t) }}
</span>
<span class="<md:hidden">
{{ banner.text }}
<span :class="banner.alternateText ? '<md:hidden' : ''">
{{ banner.text(t) }}
</span>
</span>
</div>
@@ -19,8 +19,8 @@
<script setup lang="ts">
import { computed } from "vue"
import { BannerContent, BannerType } from "~/services/banner.service"
import { useI18n } from "@composables/i18n"
import IconAlertCircle from "~icons/lucide/alert-circle"
import IconAlertTriangle from "~icons/lucide/alert-triangle"
@@ -30,6 +30,8 @@ const props = defineProps<{
banner: BannerContent
}>()
const t = useI18n()
const ariaRoles: Record<BannerType, string> = {
error: "alert",
warning: "status",

View File

@@ -217,7 +217,7 @@
</div>
</div>
</header>
<AppBanner v-if="banner" :banner="banner" />
<AppBanner v-if="bannerContent" :banner="bannerContent" />
<TeamsModal :show="showTeamsModal" @hide-modal="showTeamsModal = false" />
<TeamsInvite
v-if="workspace.type === 'team' && workspace.teamID"
@@ -266,7 +266,11 @@ import IconUsers from "~icons/lucide/users"
import { pipe } from "fp-ts/function"
import * as TE from "fp-ts/TaskEither"
import { deleteTeam as backendDeleteTeam } from "~/helpers/backend/mutations/Team"
import { BannerService } from "~/services/banner.service"
import {
BannerService,
BannerContent,
BANNER_PRIORITY_HIGH,
} from "~/services/banner.service"
const t = useI18n()
const toast = useToast()
@@ -284,18 +288,29 @@ const showTeamsModal = ref(false)
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
const { content: banner } = useService(BannerService)
const network = reactive(useNetwork())
const banner = useService(BannerService)
const bannerContent = computed(() => banner.content.value?.content)
let bannerID: number | null = null
watch(network, () => {
if (network.isOnline) {
banner.value = null
const offlineBanner: BannerContent = {
type: "info",
text: (t) => t("helpers.offline"),
alternateText: (t) => t("helpers.offline_short"),
score: BANNER_PRIORITY_HIGH,
}
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)
return
}
banner.value = {
type: "info",
text: t("helpers.offline"),
alternateText: t("helpers.offline_short"),
} else {
if (banner.content && bannerID) {
banner.removeBanner(bannerID)
}
}
})