Skip to content

Commit db838d5

Browse files
authored
Fix banner visibility (#509)
1 parent e6e7da2 commit db838d5

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

app/components/DocsBanner.vue

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,38 @@ const dismissedBanners = useCookie('directus-dismissed-banners', {
66
});
77
88
const bannerVisible = computed(() => {
9-
if (!unref(banner)) return false;
10-
return unref(dismissedBanners).includes(unref(banner)!.id) === false;
9+
const bannerValue = unref(banner);
10+
if (!bannerValue) return false;
11+
if (Object.keys(bannerValue).length === 0) return false;
12+
13+
if (!('id' in bannerValue) || !('content' in bannerValue)) return false;
14+
return unref(dismissedBanners).includes(bannerValue.id) === false;
1115
});
1216
1317
const dismiss = (id: string) => {
1418
dismissedBanners.value = [...unref(dismissedBanners), id];
1519
};
1620
1721
const iconName = computed(() => {
18-
if (!unref(banner)) return null;
19-
return getIconName(unref(banner)!.icon);
22+
const bannerValue = unref(banner);
23+
if (
24+
!bannerValue
25+
|| (typeof bannerValue === 'object' && Object.keys(bannerValue).length === 0)
26+
)
27+
return null;
28+
return getIconName(bannerValue.icon);
2029
});
2130
</script>
2231

2332
<template>
2433
<div
2534
v-if="banner && bannerVisible"
26-
class="bg-inverted text-inverted cursor-pointer h-8"
35+
class="bg-inverted text-inverted cursor-pointer h-8"
2736
>
2837
<UContainer class="h-full flex items-center gap-x-4">
2938
<NuxtLink
3039
class="flex-grow h-full flex items-center text-background no-underline text-xs leading-xs font-semibold group"
31-
:href="banner.link ?? undefined"
40+
:href="banner?.link ?? undefined"
3241
>
3342
<Icon
3443
v-if="iconName"
@@ -37,7 +46,7 @@ const iconName = computed(() => {
3746
/>
3847
<span
3948
class="whitespace-nowrap overflow-hidden text-ellipsis"
40-
v-html="banner.content"
49+
v-html="banner?.content"
4150
/>
4251
<Icon
4352
class="hidden md:block transform duration-150 ease-out ml-1 group-hover:translate-x-1 size-5"
@@ -49,7 +58,7 @@ const iconName = computed(() => {
4958
aria-label="Close"
5059
:padded="false"
5160
icon="material-symbols:close"
52-
@click="dismiss(banner.id)"
61+
@click="banner && dismiss(banner.id)"
5362
>
5463
<Icon
5564
name="material-symbols:close"

server/api/banner.get.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export default defineCachedEventHandler(async () => {
1212
limit: 1,
1313
}));
1414

15-
if (!data) return {};
15+
if (!data) return null;
1616

1717
return data;
1818
}
1919
catch (error) {
20-
console.error(error);
21-
return {};
20+
console.error('Banner API error:', error);
21+
return null;
2222
}
2323
}, {
2424
maxAge: 60 * 5, // 5 minutes

0 commit comments

Comments
 (0)