-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLA-1973] add dynamic banner (#177)
- Loading branch information
Showing
5 changed files
with
123 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<template> | ||
<Transition name="fade-down" appear> | ||
<div | ||
v-if="enabled && show" | ||
class="flex justify-between items-center px-4 md:px-10 text-light-content-white dark:text-dark-content-white notice-bg h-[72px] w-full z-10 text-white" | ||
> | ||
<span class="text-xs md:text-base">{{ banner.text }}</span> | ||
<div class="flex space-x-2 md:space-x-4"> | ||
<a | ||
v-if="banner.link" | ||
:href="banner.link" | ||
target="_blank" | ||
class="underline font-medium text-light-content-white dark:text-dark-content-white hover:text-light-content-white hover:dark:text-dark-content-white text-sm md:text-base truncate" | ||
> | ||
<span> | ||
{{ banner.linkText ?? 'Learn more' }} | ||
</span> | ||
</a> | ||
<XMarkIcon | ||
v-if="banner.dismissable" | ||
class="h-5 w-5 ml-auto my-auto cursor-pointer flex-shrink-0" | ||
@click="closeBanner" | ||
/> | ||
</div> | ||
</div> | ||
</Transition> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { XMarkIcon } from '@heroicons/vue/24/outline'; | ||
import { computed, ref } from 'vue'; | ||
import { ApiService } from '~/api'; | ||
|
||
const show = ref(true); | ||
const banner = ref(); | ||
|
||
const enabled = computed(() => { | ||
return banner.value && banner.value.enabled; | ||
}); | ||
|
||
const closeBanner = () => { | ||
deleteOutdated(); | ||
localStorage.setItem(banner.value.key, 'true'); | ||
show.value = false; | ||
}; | ||
|
||
const deleteOutdated = () => { | ||
const keys = Object.keys(localStorage).filter((key) => key.startsWith('banner')); | ||
keys.forEach((key) => { | ||
if (key !== banner.value.key) { | ||
const item = localStorage.getItem(key); | ||
if (item) { | ||
localStorage.removeItem(key); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
const fetchBanner = async () => { | ||
try { | ||
const resp = await ApiService.getBanners(); | ||
banner.value = resp.data.GetBanners[0]; | ||
} catch { | ||
// Do nothing | ||
} | ||
}; | ||
|
||
(() => { | ||
fetchBanner(); | ||
})(); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.fade-down-enter-active, | ||
.fade-down-leave-active { | ||
transition: all 0.3s ease-in-out; | ||
margin-top: 0; | ||
} | ||
.fade-down-enter-from, | ||
.fade-down-leave-to { | ||
opacity: 0; | ||
margin-top: -70px; | ||
} | ||
|
||
.notice-bg { | ||
background: linear-gradient(96deg, #4f40af -2.69%, #8c7fe0 98.64%); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default `query { | ||
GetBanners { | ||
key | ||
text | ||
link | ||
linkText | ||
dismissable | ||
} | ||
}`; |