2023-12-13 21:07:40 +00:00
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { Navigate, useNavigate } from 'react-router-dom';
|
|
|
|
import { NavDashboard } from './Navigation';
|
2023-12-19 21:26:11 +00:00
|
|
|
import { AddChannel, Config } from '../../wailsjs/go/main/App';
|
2023-12-14 21:18:36 +00:00
|
|
|
import { Eye, EyeSlash } from '../assets/icons';
|
2023-12-13 21:07:40 +00:00
|
|
|
import './SignIn.css';
|
2023-12-19 21:26:11 +00:00
|
|
|
import ChannelList from '../components/ChannelList';
|
2024-01-05 21:24:54 +00:00
|
|
|
import { SmallModal } from '../components/Modal';
|
2023-12-13 21:07:40 +00:00
|
|
|
|
|
|
|
function SignIn() {
|
2024-01-05 21:24:54 +00:00
|
|
|
const [error, setError] = useState('');
|
2023-12-13 21:07:40 +00:00
|
|
|
const navigate = useNavigate();
|
2023-12-21 20:20:43 +00:00
|
|
|
const [config, setConfig] = useState({ channels: {} });
|
2023-12-24 21:18:42 +00:00
|
|
|
const [addChannelError, setAddChannelError] = useState('');
|
2023-12-13 21:07:40 +00:00
|
|
|
const [streamKey, setStreamKey] = useState('');
|
|
|
|
const updateStreamKey = (event) => setStreamKey(event.target.value);
|
2023-12-14 21:18:36 +00:00
|
|
|
const [showStreamKey, setShowStreamKey] = useState(false);
|
|
|
|
const updateShowStreamKey = () => setShowStreamKey(!showStreamKey);
|
2023-12-13 21:07:40 +00:00
|
|
|
|
2023-12-19 21:26:11 +00:00
|
|
|
useEffect(() => {
|
|
|
|
Config()
|
|
|
|
.then((response) => {
|
|
|
|
setConfig(response);
|
|
|
|
})
|
2024-01-05 21:24:54 +00:00
|
|
|
.catch((error) => {
|
2023-12-21 20:20:43 +00:00
|
|
|
// TODO: display error to user
|
2024-01-05 21:24:54 +00:00
|
|
|
setError('Error loading config: ' + error);
|
|
|
|
console.log('error getting config', error);
|
2023-12-19 21:26:11 +00:00
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
2023-12-13 21:07:40 +00:00
|
|
|
const saveStreamKey = () => {
|
2023-12-19 21:26:11 +00:00
|
|
|
AddChannel(streamKey)
|
|
|
|
.then((response) => {
|
|
|
|
console.log(response);
|
|
|
|
setConfig(response);
|
|
|
|
setStreamKey('');
|
|
|
|
})
|
2024-01-05 21:24:54 +00:00
|
|
|
.catch((error) => {
|
|
|
|
console.log('error adding channel', error);
|
|
|
|
setAddChannelError(error);
|
2023-12-19 21:26:11 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-12-21 20:20:43 +00:00
|
|
|
const openStreamDashboard = (cid) => {
|
|
|
|
navigate(NavDashboard, { state: { cid: cid } });
|
2023-12-13 21:07:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2024-01-05 21:24:54 +00:00
|
|
|
<>
|
|
|
|
{error !== '' && (
|
|
|
|
<SmallModal
|
|
|
|
onClose={() => setError('')}
|
|
|
|
show={error !== ''}
|
|
|
|
style={{ minWidth: '300px', maxWidth: '200px', maxHeight: '200px' }}
|
|
|
|
title={'Error'}
|
|
|
|
message={error}
|
|
|
|
submitButton={'OK'}
|
|
|
|
onSubmit={() => setError('')}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<div id='SignIn'>
|
|
|
|
<div className='signin-header'>
|
|
|
|
<span className='signin-title-text'>Rum Goggles</span>
|
|
|
|
<span className='signin-title-subtext'>Rumble Stream Dashboard</span>
|
|
|
|
</div>
|
|
|
|
<div className='signin-center'>
|
|
|
|
<ChannelList
|
|
|
|
channels={config.channels}
|
|
|
|
openStreamDashboard={openStreamDashboard}
|
2023-12-13 21:07:40 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2024-01-05 21:24:54 +00:00
|
|
|
<div className='signin-input-box'>
|
|
|
|
<label className='signin-label'>Add Channel</label>
|
|
|
|
<span className='add-channel-description'>
|
|
|
|
Copy your API key from your Rumble account
|
|
|
|
</span>
|
|
|
|
<div className='signin-input-button'>
|
|
|
|
<input
|
|
|
|
id='StreamKey'
|
|
|
|
className='signin-input'
|
|
|
|
onChange={updateStreamKey}
|
|
|
|
placeholder='Stream Key'
|
|
|
|
type={showStreamKey ? 'text' : 'password'}
|
|
|
|
value={streamKey}
|
|
|
|
/>
|
|
|
|
<button className='signin-show' onClick={updateShowStreamKey}>
|
|
|
|
<img
|
|
|
|
className='signin-show-icon'
|
|
|
|
src={showStreamKey ? EyeSlash : Eye}
|
|
|
|
></img>
|
|
|
|
</button>
|
|
|
|
<button className='signin-button' onClick={saveStreamKey}>
|
|
|
|
Save
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<span className='add-channel-error'>
|
|
|
|
{addChannelError ? addChannelError : '\u00A0'}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className='signin-footer'></div>
|
2023-12-13 21:07:40 +00:00
|
|
|
</div>
|
2024-01-05 21:24:54 +00:00
|
|
|
</>
|
2023-12-13 21:07:40 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SignIn;
|