From b133635e8b75f120fbda95d566de1c28500c7021 Mon Sep 17 00:00:00 2001 From: Dennis Keil Date: Fri, 18 Aug 2023 19:54:16 +0200 Subject: [PATCH] twitch live --- app/src/api/following.ts | 3 +- app/src/view/components/profile.tsx | 120 ++++++++++++++-------------- data/src/helper/reference.ts | 2 +- 3 files changed, 63 insertions(+), 62 deletions(-) diff --git a/app/src/api/following.ts b/app/src/api/following.ts index 5f16b90a8..a3d024d3f 100644 --- a/app/src/api/following.ts +++ b/app/src/api/following.ts @@ -186,7 +186,8 @@ export interface ITwitchChannel { tag_ids: string[]; } -export async function twitchLive(channel: string): Promise { +export async function twitchLive(channel?: string): Promise { + if (channel == null || channel.length === 0) return {} as any; // return new Promise((resolve) => resolve({ // type: 'live', // viewer_count: 320, diff --git a/app/src/view/components/profile.tsx b/app/src/view/components/profile.tsx index ccb8c4174..812abefa5 100644 --- a/app/src/view/components/profile.tsx +++ b/app/src/view/components/profile.tsx @@ -4,7 +4,7 @@ import { } from '@nex/data'; import { ILeaderboardNew, - IPlayer, IProfileResponse + IPlayer, IPlayerNew, IProfileResponse } from '@nex/data/api'; import React, {useEffect} from 'react'; import {getLeaderboardTextColor} from '../../helper/colors'; @@ -120,40 +120,38 @@ interface IProfileProps { ready: boolean; } -export function ProfileLive({data} : {data: IPlayer}) { +export function ProfileLive({data} : {data: IPlayerNew}) { const styles = useStyles(); - // const verifiedPlayer = data ? getVerifiedPlayer(data?.profileId!) : null; - // - // const playerTwitchLive = useLazyApi( - // {}, - // twitchLive, verifiedPlayer ? getTwitchChannel(verifiedPlayer) : '' - // ); - // - // useEffect(() => { - // if (verifiedPlayer && getTwitchChannel(verifiedPlayer)) { - // playerTwitchLive.reload(); - // } - // }, [verifiedPlayer]); - - return ; - - // if (!verifiedPlayer?.['twitch']) { - // return ; - // } - // - // return ( - // openLink(verifiedPlayer?.twitch)}> - // { - // playerTwitchLive.data?.type === 'live' && - // <> - // - // {playerTwitchLive.data.viewerCount} - // - // - // - // } - // - // ) + const verifiedPlayer = data ? getVerifiedPlayer(data?.profileId!) : null; + + const playerTwitchLive = useLazyApi( + {}, + twitchLive, verifiedPlayer ? getTwitchChannel(verifiedPlayer) : '' + ); + + useEffect(() => { + if (verifiedPlayer && getTwitchChannel(verifiedPlayer)) { + playerTwitchLive.reload(); + } + }, [verifiedPlayer]); + + if (!verifiedPlayer?.['twitch']) { + return ; + } + + return ( + openLink(verifiedPlayer?.twitch)}> + { + playerTwitchLive.data?.type === 'live' && + <> + + {playerTwitchLive.data.viewer_count} + + + + } + + ) } export default function Profile({data, ready}: IProfileProps) { @@ -167,6 +165,8 @@ export default function Profile({data, ready}: IProfileProps) { const followingThisUser = !!following.find(f => data && f.profileId === data.profileId); const authCountry = useSelector(state => state.prefs.country); + const verifiedPlayer = data ? getVerifiedPlayer(data?.profileId!) : null; + // console.log('==> data', data); const ToggleFollowing = async () => { @@ -230,32 +230,32 @@ export default function Profile({data, ready}: IProfileProps) { - {/**/} - {/* {*/} - {/* verifiedPlayer?.discord &&*/} - {/* */} - {/* */} - {/* */} - {/* }*/} - {/* {*/} - {/* verifiedPlayer?.youtube &&*/} - {/* */} - {/* */} - {/* */} - {/* }*/} - {/* {*/} - {/* verifiedPlayer?.douyu &&*/} - {/* */} - {/* */} - {/* */} - {/* }*/} - {/* {*/} - {/* verifiedPlayer?.twitch != null &&*/} - {/* */} - {/* */} - {/* */} - {/* }*/} - {/**/} + + { + verifiedPlayer?.discord && + + + + } + { + verifiedPlayer?.youtube && + + + + } + { + verifiedPlayer?.douyu && + + + + } + { + verifiedPlayer?.twitch != null && + + + + } + diff --git a/data/src/helper/reference.ts b/data/src/helper/reference.ts index 5a1fb00db..8f16f901e 100644 --- a/data/src/helper/reference.ts +++ b/data/src/helper/reference.ts @@ -67,7 +67,7 @@ export function getVerifiedPlayer(profileId: number) { return verifiedPlayer; } -export function getTwitchChannel(verifiedPlayer: IReferencePlayer) { +export function getTwitchChannel(verifiedPlayer?: IReferencePlayer) { try { return verifiedPlayer?.twitch?.[0] ?.replace('http://', '')