Skip to content

Commit bd94860

Browse files
kakomonnsatnaing
andauthored
fix: add types for constants to avoid type errors when empty (#501)
Add types for `constants` to avoid type errors when either `SOCIALS` or `SHARE_LINKS` is empty. --------- Co-authored-by: satnaing <[email protected]>
1 parent 21bcca8 commit bd94860

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

src/components/ShareLinks.astro

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import LinkButton from "./LinkButton.astro";
55
const URL = Astro.url;
66
---
77

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

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)