2023-12-14 21:18:36 +00:00
|
|
|
import { useEffect, useState } from 'react';
|
2023-12-13 21:07:40 +00:00
|
|
|
import { useLocation } from 'react-router-dom';
|
2023-12-18 21:15:55 +00:00
|
|
|
import { Start, Stop } from '../../wailsjs/go/api/Api';
|
2023-12-13 21:07:40 +00:00
|
|
|
|
|
|
|
import './Dashboard.css';
|
2023-12-18 21:15:55 +00:00
|
|
|
import { EventsEmit, EventsOn } from '../../wailsjs/runtime/runtime';
|
|
|
|
import { Heart, Star } from '../assets/icons';
|
|
|
|
import Highlight from '../components/Highlight';
|
|
|
|
import StreamEvent from '../components/StreamEvent';
|
|
|
|
import StreamActivity from '../components/StreamActivity';
|
|
|
|
import StreamChat from '../components/StreamChat';
|
|
|
|
import StreamInfo from '../components/StreamInfo';
|
2023-12-13 21:07:40 +00:00
|
|
|
|
|
|
|
function Dashboard() {
|
|
|
|
const location = useLocation();
|
2023-12-18 21:15:55 +00:00
|
|
|
const [refresh, setRefresh] = useState(false);
|
|
|
|
const [active, setActive] = useState(false);
|
2023-12-13 21:07:40 +00:00
|
|
|
const [streamKey, setStreamKey] = useState(location.state.streamKey);
|
2023-12-18 21:15:55 +00:00
|
|
|
const [channelName, setChannelName] = useState('');
|
2023-12-14 21:18:36 +00:00
|
|
|
const [followers, setFollowers] = useState({});
|
2023-12-18 21:15:55 +00:00
|
|
|
const [totalFollowers, setTotalFollowers] = useState(0);
|
|
|
|
const [channelFollowers, setChannelFollowers] = useState(0);
|
2023-12-14 21:18:36 +00:00
|
|
|
const [recentFollowers, setRecentFollowers] = useState([]);
|
2023-12-18 21:15:55 +00:00
|
|
|
const [subscribers, setSubscribers] = useState({});
|
|
|
|
const [subscriberCount, setSubscriberCount] = useState(0);
|
|
|
|
const [recentSubscribers, setRecentSubscribers] = useState([]);
|
|
|
|
const [streamCategories, setStreamCategories] = useState({
|
|
|
|
primary: { title: '' },
|
|
|
|
secondary: { title: '' },
|
|
|
|
});
|
|
|
|
const [streamLikes, setStreamLikes] = useState(0);
|
|
|
|
const [streamLive, setStreamLive] = useState(false);
|
|
|
|
const [streamDislikes, setStreamDislikes] = useState(0);
|
|
|
|
const [streamTitle, setStreamTitle] = useState('');
|
|
|
|
const [watchingNow, setWatchingNow] = useState(0);
|
|
|
|
const [createdOn, setCreatedOn] = useState('');
|
2023-12-14 21:18:36 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-12-18 21:15:55 +00:00
|
|
|
console.log('use effect start');
|
|
|
|
Start(streamKey);
|
|
|
|
setActive(true);
|
|
|
|
|
|
|
|
EventsOn('QueryResponse', (response) => {
|
|
|
|
console.log('query response received');
|
|
|
|
setRefresh(!refresh);
|
|
|
|
setActive(true);
|
|
|
|
setChannelName(response.channel_name);
|
|
|
|
setFollowers(response.followers);
|
|
|
|
setChannelFollowers(response.followers.num_followers);
|
|
|
|
setTotalFollowers(response.followers.num_followers_total);
|
|
|
|
setRecentFollowers(response.followers.recent_followers);
|
|
|
|
setSubscribers(response.subscribers);
|
|
|
|
setSubscriberCount(response.subscribers.num_subscribers);
|
|
|
|
setRecentSubscribers(response.subscribers.recent_subscribers);
|
|
|
|
if (response.livestreams.length > 0) {
|
|
|
|
setStreamLive(true);
|
|
|
|
setStreamCategories(response.livestreams[0].categories);
|
|
|
|
setStreamLikes(response.livestreams[0].likes);
|
|
|
|
setStreamDislikes(response.livestreams[0].dislikes);
|
|
|
|
setStreamTitle(response.livestreams[0].title);
|
|
|
|
setCreatedOn(response.livestreams[0].created_on);
|
|
|
|
setWatchingNow(response.livestreams[0].watching_now);
|
|
|
|
} else {
|
|
|
|
setStreamLive(false);
|
|
|
|
}
|
|
|
|
});
|
2023-12-14 21:18:36 +00:00
|
|
|
}, []);
|
|
|
|
|
2023-12-18 21:15:55 +00:00
|
|
|
const startQuery = () => {
|
|
|
|
console.log('start');
|
|
|
|
Start(streamKey);
|
|
|
|
setActive(true);
|
2023-12-14 21:18:36 +00:00
|
|
|
};
|
|
|
|
|
2023-12-18 21:15:55 +00:00
|
|
|
const stopQuery = () => {
|
|
|
|
console.log('stop');
|
|
|
|
Stop();
|
|
|
|
// EventsEmit('StopQuery');
|
|
|
|
setActive(false);
|
2023-12-14 21:18:36 +00:00
|
|
|
};
|
|
|
|
|
2023-12-18 21:15:55 +00:00
|
|
|
const activityDate = (activity) => {
|
|
|
|
if (activity.followed_on) {
|
|
|
|
return activity.followed_on;
|
2023-12-14 21:18:36 +00:00
|
|
|
}
|
2023-12-18 21:15:55 +00:00
|
|
|
if (activity.subscribed_on) {
|
|
|
|
return activity.subscribed_on;
|
2023-12-14 21:18:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-12-18 21:15:55 +00:00
|
|
|
const activityEvents = () => {
|
|
|
|
let sorted = [...recentFollowers, ...recentSubscribers].sort((a, b) =>
|
|
|
|
activityDate(a) < activityDate(b) ? 1 : -1
|
|
|
|
);
|
|
|
|
return sorted;
|
2023-12-14 21:18:36 +00:00
|
|
|
};
|
|
|
|
|
2023-12-13 21:07:40 +00:00
|
|
|
return (
|
|
|
|
<div id='Dashboard'>
|
2023-12-18 21:15:55 +00:00
|
|
|
<div className='header'>
|
|
|
|
<div className='header-left'></div>
|
|
|
|
<div className='highlights'>
|
|
|
|
{/* <Highlight description={'Session'} type={'stopwatch'} value={createdOn} /> */}
|
|
|
|
<Highlight description={'Viewers'} type={'count'} value={watchingNow} />
|
|
|
|
<Highlight description={'Followers'} type={'count'} value={channelFollowers} />
|
|
|
|
<Highlight description={'Subscribers'} type={'count'} value={subscriberCount} />
|
|
|
|
</div>
|
|
|
|
<div className='header-right'></div>
|
|
|
|
</div>
|
|
|
|
<div className='main'>
|
|
|
|
<div className='main-left'>
|
|
|
|
<StreamActivity title={'Stream Activity'} events={activityEvents()} />
|
2023-12-14 21:18:36 +00:00
|
|
|
</div>
|
2023-12-18 21:15:55 +00:00
|
|
|
<div className='main-right'>
|
|
|
|
<StreamChat title={'Stream Chat'} />
|
2023-12-14 21:18:36 +00:00
|
|
|
</div>
|
2023-12-18 21:15:55 +00:00
|
|
|
<div></div>
|
2023-12-14 21:18:36 +00:00
|
|
|
</div>
|
2023-12-18 21:15:55 +00:00
|
|
|
<StreamInfo
|
|
|
|
active={active}
|
|
|
|
channel={channelName}
|
|
|
|
title={streamTitle}
|
|
|
|
categories={streamCategories}
|
|
|
|
likes={streamLikes}
|
|
|
|
live={streamLive}
|
|
|
|
dislikes={streamDislikes}
|
|
|
|
play={startQuery}
|
|
|
|
pause={stopQuery}
|
|
|
|
/>
|
2023-12-13 21:07:40 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Dashboard;
|