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
1212const 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
2323export 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 ) }
0 commit comments