Fix dissmissible banner typo
This commit is contained in:
@@ -1,58 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div
|
|
||||||
v-if="visible && banner && banner.active"
|
|
||||||
class="web-dismissable-banner"
|
|
||||||
>
|
|
||||||
<div class="web-dismissable-banner-content">
|
|
||||||
<a :href="banner.link" target="_blank" rel="noopener">
|
|
||||||
{{ banner.message }}
|
|
||||||
</a>
|
|
||||||
<button class="btn btn-secondary btn-sm" @click="dismiss"><span class="material-symbols-outlined">close</span></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { ref, onMounted } from 'vue'
|
|
||||||
|
|
||||||
// 🍪 Cookies
|
|
||||||
const bannerDismissedCookie = useCookie('web_banner_dismissed', { maxAge: 60 * 60 * 24 * 30 }) // 30 days
|
|
||||||
const bannerLastIdCookie = useCookie('web_banner_last_id', { maxAge: 60 * 60 * 24 * 30 }) // 30 days
|
|
||||||
|
|
||||||
// 🔹 State
|
|
||||||
const banner = ref<any>(null)
|
|
||||||
const visible = ref(false)
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
try {
|
|
||||||
const data = await $fetch('https://files.thawia.ng/files/config/web/banner/tmp/index.json')
|
|
||||||
|
|
||||||
// If no data or inactive, bail
|
|
||||||
if (!data || !data.active) return
|
|
||||||
|
|
||||||
banner.value = data
|
|
||||||
|
|
||||||
// Check if the banner is new or dismissed
|
|
||||||
const currentId = data.id?.toString() || ''
|
|
||||||
const lastSeenId = bannerLastIdCookie.value?.toString() || ''
|
|
||||||
const dismissed = bannerDismissedCookie.value === currentId
|
|
||||||
|
|
||||||
// Show banner only if new or not dismissed yet
|
|
||||||
if (currentId && (currentId !== lastSeenId || !dismissed)) {
|
|
||||||
visible.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update last seen id
|
|
||||||
bannerLastIdCookie.value = currentId
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Banner fetch failed:', err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function dismiss() {
|
|
||||||
if (banner.value?.id) {
|
|
||||||
bannerDismissedCookie.value = banner.value.id.toString()
|
|
||||||
}
|
|
||||||
visible.value = false
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-if="visible && banner && banner.active"
|
||||||
|
class="web-dismissible-banner"
|
||||||
|
>
|
||||||
|
<div class="web-dismissible-banner-content">
|
||||||
|
<a :href="banner.link" target="_blank" rel="noopener">
|
||||||
|
{{ banner.message }}
|
||||||
|
</a>
|
||||||
|
<button class="btn btn-secondary btn-sm" @click="dismiss"><span class="material-symbols-outlined">close</span></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, onMounted } from 'vue'
|
||||||
|
|
||||||
|
const banner = ref<any>(null)
|
||||||
|
const visible = ref(false)
|
||||||
|
|
||||||
|
const STORAGE_KEY_DISMISSED = 'web_banner_dismissed'
|
||||||
|
const STORAGE_KEY_LAST_ID = 'web_banner_last_id'
|
||||||
|
|
||||||
|
function getStorageItem(key: string): string | null {
|
||||||
|
if (typeof window === 'undefined') return null
|
||||||
|
return localStorage.getItem(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setStorageItem(key: string, value: string) {
|
||||||
|
if (typeof window === 'undefined') return
|
||||||
|
localStorage.setItem(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeStorageItem(key: string) {
|
||||||
|
if (typeof window === 'undefined') return
|
||||||
|
localStorage.removeItem(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
const data = await $fetch('https://files.thawia.ng/files/config/web/banner/tmp/index.json')
|
||||||
|
|
||||||
|
// If no data or inactive, bail
|
||||||
|
if (!data) return
|
||||||
|
|
||||||
|
banner.value = data
|
||||||
|
|
||||||
|
const currentId = data.id?.toString() || ''
|
||||||
|
const lastSeenId = getStorageItem(STORAGE_KEY_LAST_ID) || ''
|
||||||
|
const dismissedId = getStorageItem(STORAGE_KEY_DISMISSED)
|
||||||
|
|
||||||
|
// Show banner only if new or not dismissed yet
|
||||||
|
if (currentId && (currentId !== lastSeenId || dismissedId !== currentId)) {
|
||||||
|
visible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update last seen ID
|
||||||
|
setStorageItem(STORAGE_KEY_LAST_ID, currentId)
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Banner fetch failed:', err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function dismiss() {
|
||||||
|
if (banner.value?.id) {
|
||||||
|
setStorageItem(STORAGE_KEY_DISMISSED, banner.value.id.toString())
|
||||||
|
}
|
||||||
|
visible.value = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<WebDismissableGlobalBanner/>
|
<WebDismissibleGlobalBanner/>
|
||||||
<WebHeader/>
|
<WebHeader/>
|
||||||
<slot/>
|
<slot/>
|
||||||
<WebFooter/>
|
<WebFooter/>
|
||||||
|
|||||||
Reference in New Issue
Block a user