import { useEffect, useState } from 'react'; import { Modal, SmallModal } from './Modal'; import { AccountList, AddPage, Login, OpenAccount, OpenChannel, PageStatus, } from '../../wailsjs/go/main/App'; import { EventsOff, EventsOn } from '../../wailsjs/runtime/runtime'; import { ChevronRight, CircleGreenBackground, CircleRedBackground, Eye, EyeSlash, PlusCircle, } from '../assets'; import './PageSideBar.css'; function PageSideBar(props) { const [accounts, setAccounts] = useState({}); const [error, setError] = useState(''); const [addOpen, setAddOpen] = useState(false); const [refresh, setRefresh] = useState(false); const [scrollY, setScrollY] = useState(0); useEffect(() => { EventsOn('PageSideBarAccounts', (event) => { setAccounts(event); }); }, []); useEffect(() => { AccountList() .then((response) => { setAccounts(response); }) .catch((error) => { setError(error); }); }, [refresh]); const sortAccounts = () => { let keys = Object.keys(accounts); let sorted = [...keys].sort((a, b) => accounts[a].account.username.toLowerCase() > accounts[b].account.username.toLowerCase() ? 1 : -1 ); return sorted; }; const handleScroll = (event) => { setScrollY(event.target.scrollTop); }; const openAccount = (account) => { OpenAccount(account.id).catch((error) => setError(error)); }; const openChannel = (channel) => { OpenChannel(channel.id).catch((error) => setError(error)); }; return ( <> {addOpen && ( setAddOpen(false)} onRefresh={() => { setRefresh(!refresh); }} show={addOpen} /> )}
{sortAccounts().map((account, index) => ( ))}
setAddOpen(true)} scrollY={0} />
); } export default PageSideBar; function AccountChannels(props) { const sortChannels = () => { let sorted = [...props.account.channels].sort((a, b) => a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1 ); return sorted; }; if (props.account.account !== undefined) { return (
{sortChannels().map((channel, index) => ( ))}
); } } function AccountIcon(props) { const [apiActive, setApiActive] = useState(false); const [hover, setHover] = useState(false); const [isLive, setIsLive] = useState(false); const [loggedIn, setLoggedIn] = useState(props.account.cookies !== null); const [username, setUsername] = useState(props.account.username); const iconBorder = () => { if (!apiActive) { return '3px solid #3377cc'; } if (isLive) { return '3px solid #85c742'; } else { return '3px solid #f23160'; } }; const pageName = (name) => { if (name === undefined) return; return '/user/' + name; }; useEffect(() => { if (username !== props.account.username) { EventsOff( 'ApiActive-' + pageName(username), 'LoggedIn-' + pageName(username), 'PageLive-' + pageName(username) ); setApiActive(false); setIsLive(false); } EventsOn('ApiActive-' + pageName(props.account.username), (event) => { setApiActive(event); }); EventsOn('LoggedIn-' + pageName(props.account.username), (event) => { setLoggedIn(event); }); EventsOn('PageLive-' + pageName(props.account.username), (event) => { setIsLive(event); }); setUsername(props.account.username); }, [props.account.username]); useEffect(() => { if (username !== '') { PageStatus(pageName(username)); } }, [username]); return (
setHover(true)} onMouseLeave={() => setHover(false)} > {props.account.profile_image === null ? ( {props.account.username[0].toUpperCase()} ) : ( )} {hover && }
); } function ButtonIcon(props) { const [hover, setHover] = useState(false); return (
setHover(true)} onMouseLeave={() => setHover(false)} > {hover && }
); } function ChannelIcon(props) { const [apiActive, setApiActive] = useState(false); const [channelName, setChannelName] = useState(props.channel.name); const [hover, setHover] = useState(false); const [isLive, setIsLive] = useState(false); const iconBorder = () => { if (!apiActive) { return '3px solid #3377cc'; } if (isLive) { return '3px solid #85c742'; } else { return '3px solid #f23160'; } }; const pageName = (name) => { if (name === undefined) return; return '/c/' + name.replace(/\s/g, ''); }; useEffect(() => { if (channelName !== props.channel.name) { EventsOff('PageLive-' + pageName(channelName), 'ApiActive-' + pageName(channelName)); setApiActive(false); setIsLive(false); } EventsOn('PageLive-' + pageName(props.channel.name), (event) => { setIsLive(event); }); EventsOn('ApiActive-' + pageName(props.channel.name), (event) => { setApiActive(event); }); setChannelName(props.channel.name); }, [props.channel.name]); useEffect(() => { if (channelName !== '') { PageStatus(pageName(channelName)); } }, [channelName]); return (
setHover(true)} onMouseLeave={() => setHover(false)} > {props.channel.profile_image === null ? ( {props.channel.name[0].toUpperCase()} ) : ( )} {hover && }
); } function HoverName(props) { return (
{props.name}
); } function ModalAdd(props) { const [accountPassword, setAccountPassword] = useState(''); const [accountPasswordValid, setAccountPasswordValid] = useState(true); const updateAccountPassword = (event) => { if (loading()) { return; } setAccountPassword(event.target.value); }; const [accountUsername, setAccountUsername] = useState(''); const [accountUsernameValid, setAccountUsernameValid] = useState(true); const updateAccountUsername = (event) => { if (loading()) { return; } setAccountUsername(event.target.value); }; const [addAccountLoading, setAddAccountLoading] = useState(false); const [addChannelLoading, setAddChannelLoading] = useState(false); const [channelKey, setChannelKey] = useState(''); const [channelKeyValid, setChannelKeyValid] = useState(true); const updateChannelKey = (event) => { if (loading()) { return; } setChannelKey(event.target.value); }; const [error, setError] = useState(''); const [stage, setStage] = useState('start'); useEffect(() => { if (addAccountLoading) { Login(accountUsername, accountPassword) .then(() => { reset(); props.onClose(); props.onRefresh(); }) .catch((error) => { setAddAccountLoading(false); setError(error); }); } }, [addAccountLoading]); useEffect(() => { if (addChannelLoading) { AddPage(channelKey) .then(() => { reset(); props.onClose(); props.onRefresh(); }) .catch((error) => { setAddChannelLoading(false); setError(error); }); } }, [addChannelLoading]); const back = () => { if (loading()) { return; } reset(); }; const close = () => { if (loading()) { return; } reset(); props.onClose(); }; const reset = () => { setStage('start'); resetAccount(); resetChannel(); }; const add = () => { switch (stage) { case 'account': addAccount(); break; case 'channel': addChannel(); break; default: close(); } }; const addAccount = () => { if (loading()) { return; } if (accountUsername === '') { setAccountUsernameValid(false); return; } if (accountPassword === '') { setAccountPasswordValid(false); return; } setAddAccountLoading(true); }; const addChannel = () => { if (loading()) { return; } if (channelKey === '') { setChannelKeyValid(false); return; } setAddChannelLoading(true); }; const loading = () => { return addAccountLoading || addChannelLoading; }; const resetAccount = () => { setAccountPassword(''); setAccountPasswordValid(true); setAccountUsername(''); setAccountUsernameValid(true); setAddAccountLoading(false); }; const resetChannel = () => { setChannelKey(''); setChannelKeyValid(true); setAddChannelLoading(false); }; return ( <> {error !== '' && ( setError('')} show={error !== ''} style={{ minWidth: '300px', maxWidth: '200px', maxHeight: '200px' }} title={'Error'} message={error} submitButton={'OK'} onSubmit={() => setError('')} /> )} {stage === 'start' && } {stage === 'account' && ( )} {stage === 'channel' && ( )} ); } function ModalAddAccount(props) { const [showKey, setShowKey] = useState(false); const updateShowKey = () => setShowKey(!showKey); const [showPassword, setShowPassword] = useState(false); const updateShowPassword = () => setShowPassword(!showPassword); return (
Add Account Log into your Rumble account
{props.accountUsernameValid === false ? ( ) : ( )}
{props.accountPasswordValid === false ? ( ) : ( )}
); } function ModalAddChannel(props) { const [showKey, setShowKey] = useState(false); const updateShowKey = () => setShowKey(!showKey); return (
Add Channel Copy an API key below to add a channel
{props.channelKeyValid === false ? ( ) : ( )}
API KEYS SHOULD LOOK LIKE https://rumble.com/-livestream-api/get-data?key=really-long_string-of_random-characters
); } function ModalAddStart(props) { return (
Add an Account or Channel
); }