Skip to content

Commit 8eb9faf

Browse files
authored
fix: when multi-streaming kick button opens twitch #15 (#16)
* fix: kick button opening twitch stream when multistreaming #15 * chore(extension): bump version to 1.2.3 in package.json and constants.ts * refactor(extension): enhance opening stream logic * refactor: remove bad import * refactor: type narrow some types for better safety
1 parent 710fb40 commit 8eb9faf

4 files changed

Lines changed: 55 additions & 41 deletions

File tree

apps/extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@lgamila/extension",
33
"displayName": "LGamila Live",
4-
"version": "1.2.2",
4+
"version": "1.2.3",
55
"description": "This extension shows you a real-time list of all Moroccan Twitch and Kick streamers who are currently live.",
66
"author": "Stormix <hello@stormix.dev>",
77
"scripts": {

apps/extension/src/components/molecules/streamer-card.tsx

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { Eye, EyeOff } from 'lucide-react';
2-
import { FaRegStar, FaStar } from 'react-icons/fa6';
3-
import { FiTwitch } from 'react-icons/fi';
4-
import { GoDotFill } from 'react-icons/go';
5-
import { RiKickLine } from 'react-icons/ri';
6-
import type { Streamer } from '@/lib/types';
7-
import { cn } from '@/lib/utils';
8-
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar';
9-
import { Button } from '../ui/button';
10-
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip';
1+
import { Eye, EyeOff } from "lucide-react";
2+
import { FaRegStar, FaStar } from "react-icons/fa6";
3+
import { FiTwitch } from "react-icons/fi";
4+
import { GoDotFill } from "react-icons/go";
5+
import { RiKickLine } from "react-icons/ri";
6+
import type { Streamer, Platform } from "@/lib/types";
7+
import { cn } from "@/lib/utils";
8+
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
9+
import { Button } from "../ui/button";
10+
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
1111

1212
const streamerDescription = (streamer: Streamer) => {
1313
if (streamer.category) {
@@ -17,7 +17,7 @@ const streamerDescription = (streamer: Streamer) => {
1717
return `${streamer.viewerCount} viewers`;
1818
}
1919

20-
return '';
20+
return "";
2121
};
2222

2323
export function StreamerCard({
@@ -36,7 +36,7 @@ export function StreamerCard({
3636
const StarIcon = isFavorite ? FaStar : FaRegStar;
3737
const BlockIcon = isBlocked ? EyeOff : Eye;
3838

39-
const onClick = () => {
39+
const openStreamer = (selectedPlatform?: Platform) => {
4040
const twitchUrl = streamer.twitchUsername
4141
? `https://www.twitch.tv/${streamer.twitchUsername}`
4242
: null;
@@ -49,20 +49,32 @@ export function StreamerCard({
4949
}
5050

5151
if (streamer.isLive) {
52-
window.open(
53-
streamer.livePlatform === 'twitch' ? twitchUrl : kickUrl,
54-
'_blank'
55-
);
52+
if (streamer.livePlatforms?.length > 1) {
53+
const url =
54+
selectedPlatform === "twitch"
55+
? twitchUrl ?? kickUrl
56+
: selectedPlatform === "kick"
57+
? kickUrl ?? twitchUrl
58+
: twitchUrl ?? kickUrl;
59+
if (url) window.open(url, "_blank", "noopener,noreferrer");
60+
} else {
61+
const active =
62+
streamer.livePlatforms?.[0] ?? streamer.livePlatform ?? null;
63+
const url =
64+
active === "twitch" ? twitchUrl ?? kickUrl : kickUrl ?? twitchUrl;
65+
if (url) window.open(url, "_blank", "noopener,noreferrer");
66+
}
5667
} else {
57-
window.open(twitchUrl || kickUrl, '_blank');
68+
const url = twitchUrl ?? kickUrl;
69+
if (url) window.open(url, "_blank", "noopener,noreferrer");
5870
}
5971
};
6072
return (
6173
<div
6274
className={cn(
63-
'flex flex-row gap-2 items-center transition-opacity duration-300',
75+
"flex flex-row gap-2 items-center transition-opacity duration-300",
6476
{
65-
'opacity-30': !streamer.isLive,
77+
"opacity-30": !streamer.isLive,
6678
}
6779
)}
6880
>
@@ -77,7 +89,7 @@ export function StreamerCard({
7789
</div>
7890
</TooltipTrigger>
7991
<TooltipContent>
80-
{isFavorite ? 'Remove from favorites' : 'Add to favorites'}
92+
{isFavorite ? "Remove from favorites" : "Add to favorites"}
8193
</TooltipContent>
8294
</Tooltip>
8395
<Tooltip>
@@ -90,7 +102,7 @@ export function StreamerCard({
90102
</div>
91103
</TooltipTrigger>
92104
<TooltipContent>
93-
{isBlocked ? 'Show streamer' : 'Hide streamer'}
105+
{isBlocked ? "Show streamer" : "Hide streamer"}
94106
</TooltipContent>
95107
</Tooltip>
96108
</div>
@@ -100,7 +112,7 @@ export function StreamerCard({
100112
<TooltipTrigger>
101113
<div
102114
className="flex flex-row gap-2 justify-start items-center"
103-
onClick={onClick}
115+
onClick={() => openStreamer()}
104116
>
105117
<Avatar>
106118
<AvatarImage src={streamer.avatarUrl} />
@@ -124,32 +136,32 @@ export function StreamerCard({
124136
<TooltipContent>{streamer.title ?? streamer.name}</TooltipContent>
125137
</Tooltip>
126138
</div>
127-
<div className={cn('flex flex-row gap-1 items-center px-4 w-fit')}>
139+
<div className={cn("flex flex-row gap-1 items-center px-4 w-fit")}>
128140
{!streamer.livePlatforms && streamer.livePlatform && (
129141
<Button
130142
icon={
131-
streamer.livePlatform === 'twitch' ? <FiTwitch /> : <RiKickLine />
143+
streamer.livePlatform === "twitch" ? <FiTwitch /> : <RiKickLine />
132144
}
133-
onClick={onClick}
134-
variant={streamer.isLive ? 'outline' : 'ghost'}
145+
onClick={() => openStreamer()}
146+
variant={streamer.isLive ? "outline" : "ghost"}
135147
>
136148
<span className="text-xs">{streamer.livePlatform}</span>
137149
</Button>
138150
)}
139-
{streamer.livePlatforms?.map((platform) => (
151+
{streamer.livePlatforms?.map((platform: Platform) => (
140152
<Button
141-
icon={platform === 'twitch' ? <FiTwitch /> : <RiKickLine />}
153+
icon={platform === "twitch" ? <FiTwitch /> : <RiKickLine />}
142154
key={platform}
143-
onClick={onClick}
144-
variant={streamer.isLive ? 'outline' : 'ghost'}
155+
onClick={() => openStreamer(platform)}
156+
variant={streamer.isLive ? "outline" : "ghost"}
145157
>
146158
{streamer.livePlatforms.length === 1 && (
147159
<span className="text-xs">{platform}</span>
148160
)}
149161
</Button>
150162
))}
151163
{!streamer.isLive && (
152-
<Button onClick={onClick} variant="ghost">
164+
<Button onClick={() => openStreamer()} variant="ghost">
153165
<span className="text-xs">Offline</span>
154166
</Button>
155167
)}

apps/extension/src/lib/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const APP_NAME = "LGamila Live";
2-
export const APP_VERSION = "1.2.2";
2+
export const APP_VERSION = "1.2.3";
33
export const APP_DESCRIPTION =
44
"This extension shows you a real-time list of all Moroccan Twitch and Kick streamers who are currently live.";
55
export const APP_AUTHOR = "Stormix <hello@s.dev>";

apps/extension/src/lib/types.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Streamer {
99
avatarUrl: string;
1010

1111
/** Twitch username, if they stream on Twitch */
12-
twitchUsername: string;
12+
twitchUsername: string | null;
1313

1414
/** Kick username, if they stream on Kick */
1515
kickUsername: string | null;
@@ -18,10 +18,10 @@ export interface Streamer {
1818
isLive: boolean;
1919

2020
/** Platform the streamer is currently live on, if any */
21-
livePlatform: string | null;
21+
livePlatform: Platform | null;
2222

2323
/** Platforms the streamer is currently live on, if any */
24-
livePlatforms: string[] | null;
24+
livePlatforms: Platform[] | null;
2525

2626
/** Current viewer count if live, 0 if offline */
2727
viewerCount: number;
@@ -48,8 +48,10 @@ export interface Settings {
4848
}
4949

5050
export type SortOption =
51-
| 'default'
52-
| 'viewers-desc'
53-
| 'viewers-asc'
54-
| 'name-asc'
55-
| 'name-desc';
51+
| "default"
52+
| "viewers-desc"
53+
| "viewers-asc"
54+
| "name-asc"
55+
| "name-desc";
56+
57+
export type Platform = "twitch" | "kick";

0 commit comments

Comments
 (0)