Skip to content

Commit 6b5ea88

Browse files
committed
chore: add banner placeholder
1 parent 4b950ee commit 6b5ea88

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

frontend/src/components/content/ContentServerPane.vue

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ const onOpenSponsor = (link) => {
1515
BrowserOpenURL(link)
1616
}
1717
18+
const openBanner = (link) => {
19+
BrowserOpenURL(link)
20+
}
21+
22+
const skipBanner = () => {
23+
// Show again after 30 days
24+
localStorage.setItem('banner_next_time', Date.now() + 30 * 24 * 60 * 60 * 1000)
25+
}
26+
1827
const sponsorAd = computed(() => {
1928
try {
2029
const content = localStorage.getItem('sponsor_ad')
@@ -27,10 +36,54 @@ const sponsorAd = computed(() => {
2736
return null
2837
}
2938
})
39+
40+
const banner = computed(() => {
41+
try {
42+
const nextTime = localStorage.getItem('banner_next_time') || 0
43+
if (nextTime > 0 && nextTime > Date.now()) {
44+
return null
45+
}
46+
47+
const content = localStorage.getItem('banner')
48+
const banners = JSON.parse(content)
49+
let banner = find(banners, ({ lang }) => {
50+
return lang === prefStore.currentLanguage
51+
})
52+
if (banner == null) {
53+
banner = find(banners, ({ lang }) => {
54+
return lang === 'en'
55+
})
56+
}
57+
return banner || null
58+
// return {
59+
// lang: 'zh',
60+
// title: 'title',
61+
// content: 'content',
62+
// button: 'button',
63+
// link: 'https://redis.tinycraft.cc',
64+
// }
65+
} catch {
66+
return null
67+
}
68+
})
3069
</script>
3170

3271
<template>
3372
<div class="content-container flex-box-v">
73+
<n-alert
74+
v-if="banner != null"
75+
:bordered="false"
76+
:on-close="skipBanner"
77+
:title="banner.title"
78+
class="banner"
79+
closable
80+
type="warning">
81+
<span style="margin: 0 10px 0 0">{{ banner.content }}</span>
82+
<n-button size="small" tertiary type="warning" @click="openBanner(banner.link)">
83+
{{ banner.button }}
84+
</n-button>
85+
</n-alert>
86+
3487
<!-- TODO: replace icon to app icon -->
3588
<n-empty :description="$t('interface.empty_server_content')">
3689
<template #extra>
@@ -56,6 +109,14 @@ const sponsorAd = computed(() => {
56109
justify-content: center;
57110
padding: 5px;
58111
box-sizing: border-box;
112+
position: relative;
113+
114+
& > .banner {
115+
position: absolute;
116+
top: 0;
117+
left: 0;
118+
width: 100%;
119+
}
59120
60121
& > .sponsor-ad {
61122
text-align: center;

frontend/src/stores/preferences.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,17 @@ const usePreferencesStore = defineStore('preferences', {
473473
download_page: pageUrl = {},
474474
description = {},
475475
sponsor = [],
476+
banner = [],
476477
} = data
477478
const downUrl = pageUrl[this.currentLanguage] || pageUrl['en']
478479
const descStr = description[this.currentLanguage] || description['en']
479480
// save sponsor ad
480481
if (!isEmpty(sponsor)) {
481482
localStorage.setItem('sponsor_ad', JSON.stringify(sponsor))
482483
}
484+
if (!isEmpty(banner)) {
485+
localStorage.setItem('banner', JSON.stringify(banner))
486+
}
483487
if (
484488
(manual || compareVersion(latest, this.general.skipVersion) !== 0) &&
485489
compareVersion(latest, version) > 0 &&

0 commit comments

Comments
 (0)