Skip to content

Commit 0ba9027

Browse files
kakomonnmiyayaLora
authored andcommitted
fix: add types for constants to avoid type errors when empty (satnaing#501)
Add types for `constants` to avoid type errors when either `SOCIALS` or `SHARE_LINKS` is empty. --------- Co-authored-by: satnaing <satnaingdev@gmail.com> (cherry picked from commit bd94860)
1 parent 7a66b6e commit 0ba9027

2 files changed

Lines changed: 33 additions & 25 deletions

File tree

src/components/ShareLinks.astro

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ import IconShare from "@/assets/icons/IconShare.svg";
66
const URL = Astro.url;
77
---
88

9-
<div
10-
class="flex flex-col flex-wrap items-center justify-center gap-1 sm:items-start"
11-
>
12-
<label class="flex flex-auto flex-row items-center-safe gap-1">
13-
<IconShare />
14-
<span class="italic">Share this post on</span>
15-
</label>
16-
<div class="text-center">
17-
{
18-
SHARE_LINKS.map(social => (
19-
<LinkButton
20-
href={`${social.href + URL}`}
21-
class="scale-90 p-2 hover:rotate-6 sm:p-1"
22-
title={social.linkTitle}
23-
>
24-
<social.icon class="inline-block size-6 scale-125 fill-transparent stroke-current stroke-2 opacity-90 group-hover:fill-transparent sm:scale-110" />
25-
<span class="sr-only">{social.linkTitle}</span>
26-
</LinkButton>
27-
))
28-
}
29-
</div>
30-
</div>
9+
{
10+
SHARE_LINKS.length > 0 && (
11+
<div class="flex flex-none flex-col items-center justify-center gap-1 sm:items-start">
12+
<label class="flex flex-auto flex-row items-center-safe gap-1">
13+
<IconShare />
14+
<span class="italic">Share this post on</span>
15+
</label>
16+
<div class="text-center">
17+
{SHARE_LINKS.map(social => (
18+
<LinkButton
19+
href={`${social.href + URL}`}
20+
class="scale-90 p-2 hover:rotate-6 sm:p-1"
21+
title={social.linkTitle}
22+
>
23+
<social.icon class="inline-block size-6 scale-125 fill-transparent stroke-current stroke-2 opacity-90 group-hover:fill-transparent sm:scale-110" />
24+
<span class="sr-only">{social.linkTitle}</span>
25+
</LinkButton>
26+
))}
27+
</div>
28+
</div>
29+
)
30+
}

src/constants.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Props } from "astro";
12
import IconMail from "@/assets/icons/IconMail.svg";
23
import IconGitHub from "@/assets/icons/IconGitHub.svg";
34
import IconBrandX from "@/assets/icons/IconBrandX.svg";
@@ -8,11 +9,18 @@ import IconTelegram from "@/assets/icons/IconTelegram.svg";
89
import IconPinterest from "@/assets/icons/IconPinterest.svg";
910
import { SITE } from "@/config";
1011

11-
export const SOCIALS = [
12+
interface Social {
13+
name: string;
14+
href: string;
15+
linkTitle: string;
16+
icon: (_props: Props) => Element;
17+
}
18+
19+
export const SOCIALS: Social[] = [
1220
{
1321
name: "Github",
1422
href: "https://github.com/satnaing/astro-paper",
15-
linkTitle: ` ${SITE.title} on Github`,
23+
linkTitle: `${SITE.title} on Github`,
1624
icon: IconGitHub,
1725
},
1826
{
@@ -35,7 +43,7 @@ export const SOCIALS = [
3543
},
3644
] as const;
3745

38-
export const SHARE_LINKS = [
46+
export const SHARE_LINKS: Social[] = [
3947
{
4048
name: "WhatsApp",
4149
href: "https://wa.me/?text=",

0 commit comments

Comments
 (0)