import { useEffect, useState } from 'react'; import { Modal, SmallModal } from './Modal'; import { AccountList, AddChannel, Login } from '../../wailsjs/go/main/App'; import { ChevronRight, CircleGreenBackground, Eye, EyeSlash, PlusCircle } from '../assets'; import './ChannelSideBar.css'; function ChannelSideBar(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(() => { 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); }; return ( <> setAddOpen(false)} onRefresh={() => { setRefresh(!refresh); }} show={addOpen} />
{sortAccounts().map((account, index) => ( ))}
setAddOpen(true)} scrollY={0} />
); } export default ChannelSideBar; 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 [hover, setHover] = useState(false); 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 [hover, setHover] = useState(false); 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) { AddChannel(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 ( <> 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
); }