Skip to content

Commit de1966e

Browse files
authored
Fix icons in streamers table (#13)
1 parent 5a1945d commit de1966e

File tree

3 files changed

+79
-28
lines changed

3 files changed

+79
-28
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
type CountryCode =
3+
| 'AUS' // Australia
4+
| 'BEL' // Belgium
5+
| 'CAN' // Canada
6+
| 'CHE' // Switzerland
7+
| 'ESP' // Spain
8+
| 'FRA' // France
9+
| 'GBR' // United Kingdom
10+
| 'IDN' // Indonesia
11+
| 'ITA' // Italy
12+
| 'USA' // United States
13+
14+
function parseCountryCode(code: any): string | undefined
15+
{
16+
return typeof code === 'string' ? code.toUpperCase() : code
17+
}
18+
19+
const countryCode: CountryCode | undefined = parseCountryCode(Astro.props.country) as any
20+
---
21+
22+
{
23+
countryCode === 'AUS'
24+
? <span class="icon-[twemoji--flag-australia] icon-align icon-fw"></span>
25+
: countryCode === 'BEL'
26+
? <span class="icon-[twemoji--flag-belgium] icon-align icon-fw"></span>
27+
: countryCode === 'CAN'
28+
? <span class="icon-[twemoji--flag-canada] icon-align icon-fw"></span>
29+
: countryCode === 'CHE'
30+
? <span class="icon-[twemoji--flag-switzerland] icon-align icon-fw"></span>
31+
: countryCode === 'ESP'
32+
? <span class="icon-[twemoji--flag-spain] icon-align icon-fw"></span>
33+
: countryCode === 'FRA'
34+
? <span class="icon-[twemoji--flag-france] icon-align icon-fw"></span>
35+
: countryCode === 'GBR'
36+
? <span class="icon-[twemoji--flag-united-kingdom] icon-align icon-fw"></span>
37+
: countryCode === 'IDN'
38+
? <span class="icon-[twemoji--flag-indonesia] icon-align icon-fw"></span>
39+
: countryCode === 'ITA'
40+
? <span class="icon-[twemoji--flag-italy] icon-align icon-fw"></span>
41+
: countryCode === 'USA'
42+
? <span class="icon-[twemoji--flag-united-states] icon-align icon-fw"></span>
43+
:
44+
<em>{countryCode}</em>
45+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
type SocialPlatform =
3+
| 'twitch' // Twitch
4+
| 'twitter' // Twitter
5+
| 'youtube' // YouTube
6+
| 'tiktok' // TikTok
7+
| 'instagram' // Instagram
8+
9+
function parseSocialPlatform(code: any): string | undefined
10+
{
11+
return typeof code === 'string' ? code.toLowerCase() : code
12+
}
13+
14+
const socialPlatform: SocialPlatform | undefined = parseSocialPlatform(Astro.props.platform) as any
15+
---
16+
17+
{
18+
socialPlatform === 'twitch'
19+
? <span class="icon-[mdi--twitch] icon-align icon-fw"></span>
20+
: socialPlatform === 'twitter'
21+
? <span class="icon-[mdi--twitter] icon-align icon-fw"></span>
22+
: socialPlatform === 'youtube'
23+
? <span class="icon-[mdi--youtube] icon-align icon-fw"></span>
24+
: socialPlatform === 'tiktok'
25+
? <span class="icon-[ic--baseline-tiktok] icon-align icon-fw"></span>
26+
: socialPlatform === 'instagram'
27+
? <span class="icon-[mdi--instagram] icon-align icon-fw"></span>
28+
:
29+
<em>{socialPlatform}</em>
30+
}

app/app/src/components/StreamersTable.astro

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
import YAML from 'yaml'
33
4+
import CountryFlag from '~/components/CountryFlag.astro'
5+
import SocialPlatformIcon from '~/components/SocialPlatformIcon.astro'
46
import streamersSocialsYml from '~/data/streamers/socials.yml?raw'
57
68
interface StreamerSocials {
@@ -19,27 +21,6 @@ const streamersSocials = YAML.parse(streamersSocialsYml) as Record<string, Strea
1921
const streamers: Array<StreamerSocials> = streamersList.map(
2022
(name) => streamersSocials[name] || { name, country: '?', socials: [] }
2123
)
22-
23-
const countryFlag: Record<string, string> = {
24-
'AUS': 'australia',
25-
'BEL': 'belgium',
26-
'CAN': 'canada',
27-
'CHE': 'switzerland',
28-
'ESP': 'spain',
29-
'FRA': 'france',
30-
'GBR': 'united-kingdom',
31-
'IDN': 'indonesia',
32-
'ITA': 'italy',
33-
'USA': 'united-states',
34-
}
35-
36-
const socialIcons: Record<string, string> = {
37-
'twitch': 'mdi--twitch',
38-
'twitter': 'mdi--twitter',
39-
'youtube': 'mdi--youtube',
40-
'tiktok': 'ic--baseline-tiktok',
41-
'instagram': 'mdi--instagram',
42-
}
4324
---
4425

4526
<table>
@@ -56,19 +37,14 @@ const socialIcons: Record<string, string> = {
5637
{streamers.map((streamer) => (
5738
<tr>
5839
<td>
59-
{countryFlag[streamer.country] !== undefined
60-
? <span class={`icon-[twemoji--flag-${countryFlag[streamer.country]}] icon-align icon-fw`}></span>
61-
: <em>{streamer.country}</em>
62-
}
40+
<CountryFlag country={streamer.country} />
6341
</td>
6442
<td>{streamer.name}</td>
6543
<td>
6644
{streamer.socials?.map((social, index) => (
6745
<>
6846
<a href={social.url} target="_blank" rel="noopener noreferrer">{
69-
socialIcons[social.platform.toLowerCase()] !== undefined
70-
? <span class={`icon-[${socialIcons[social.platform.toLowerCase()]}] icon-align icon-fw`}></span>
71-
: <em>{social.platform}</em>
47+
}<SocialPlatformIcon platform={social.platform} />{
7248
}</a>{index < streamer.socials.length - 1 && ', '}
7349
</>
7450
))}

0 commit comments

Comments
 (0)