Skip to content

Commit

Permalink
twitch live
Browse files Browse the repository at this point in the history
  • Loading branch information
denniske committed Aug 18, 2023
1 parent 6f9e45d commit b133635
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 62 deletions.
3 changes: 2 additions & 1 deletion app/src/api/following.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export interface ITwitchChannel {
tag_ids: string[];
}

export async function twitchLive(channel: string): Promise<ITwitchChannel> {
export async function twitchLive(channel?: string): Promise<ITwitchChannel> {
if (channel == null || channel.length === 0) return {} as any;
// return new Promise((resolve) => resolve({
// type: 'live',
// viewer_count: 320,
Expand Down
120 changes: 60 additions & 60 deletions app/src/view/components/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 <MyText/>;

// if (!verifiedPlayer?.['twitch']) {
// return <MyText/>;
// }
//
// return (
// <MyText style={styles.row} onPress={() => openLink(verifiedPlayer?.twitch)}>
// {
// playerTwitchLive.data?.type === 'live' &&
// <>
// <MyText style={{color: '#e91a16'}}> ● </MyText>
// <MyText>{playerTwitchLive.data.viewerCount} </MyText>
// <FontAwesome5 solid name="twitch" size={14} style={styles.twitchIcon} />
// <MyText> </MyText>
// </>
// }
// </MyText>
// )
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 <MyText/>;
}

return (
<MyText style={styles.row} onPress={() => openLink(verifiedPlayer?.twitch)}>
{
playerTwitchLive.data?.type === 'live' &&
<>
<MyText style={{color: '#e91a16'}}></MyText>
<MyText>{playerTwitchLive.data.viewer_count} </MyText>
<FontAwesome5 solid name="twitch" size={14} style={styles.twitchIcon} />
<MyText> </MyText>
</>
}
</MyText>
)
}

export default function Profile({data, ready}: IProfileProps) {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -230,32 +230,32 @@ export default function Profile({data, ready}: IProfileProps) {

<Space/>

{/*<View style={styles.row}>*/}
{/* {*/}
{/* verifiedPlayer?.discord &&*/}
{/* <View style={styles.badge}>*/}
{/* <DiscordBadge serverId={verifiedPlayer?.discordServerId} invitationId={getDiscordInvitationId(verifiedPlayer)} />*/}
{/* </View>*/}
{/* }*/}
{/* {*/}
{/* verifiedPlayer?.youtube &&*/}
{/* <View style={styles.badge}>*/}
{/* <YoutubeBadge channel={getYoutubeChannel(verifiedPlayer)} />*/}
{/* </View>*/}
{/* }*/}
{/* {*/}
{/* verifiedPlayer?.douyu &&*/}
{/* <View style={styles.badge}>*/}
{/* <DouyuBadge channel={getDoyouChannel(verifiedPlayer)} />*/}
{/* </View>*/}
{/* }*/}
{/* {*/}
{/* verifiedPlayer?.twitch != null &&*/}
{/* <View style={styles.badge}>*/}
{/* <TwitchBadge channel={getTwitchChannel(verifiedPlayer)} />*/}
{/* </View>*/}
{/* }*/}
{/*</View>*/}
<View style={styles.row}>
{
verifiedPlayer?.discord &&
<View style={styles.badge}>
<DiscordBadge serverId={verifiedPlayer?.discordServerId} invitationId={getDiscordInvitationId(verifiedPlayer)} />
</View>
}
{
verifiedPlayer?.youtube &&
<View style={styles.badge}>
<YoutubeBadge channel={getYoutubeChannel(verifiedPlayer)} />
</View>
}
{
verifiedPlayer?.douyu &&
<View style={styles.badge}>
<DouyuBadge channel={getDoyouChannel(verifiedPlayer)} />
</View>
}
{
verifiedPlayer?.twitch != null &&
<View style={styles.badge}>
<TwitchBadge channel={getTwitchChannel(verifiedPlayer)} />
</View>
}
</View>

<Space/>

Expand Down
2 changes: 1 addition & 1 deletion data/src/helper/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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://', '')
Expand Down

0 comments on commit b133635

Please sign in to comment.