1 import axios from 'axios';
2 import React from 'react';
3 import { Alert, Button, Col, Form, Row } from 'react-bootstrap';
4 import { useTranslation } from 'react-i18next';
5 import toastr from 'toastr';
7 import ChannelSelect from '../common/ChannelSelect';
8 import ToggleSwitch from '../common/ToggleSwitch';
10 const Controls = () => {
11 const [channel, setChannel] = React.useState(null);
12 const [chatText, setChatText] = React.useState('');
14 const { t } = useTranslation();
16 const chat = React.useCallback(async (text, bot_nick) => {
18 await axios.post(`/api/channels/${channel.id}/chat`, {
22 toastr.success(t('twitchBot.chatSuccess'));
24 toastr.error(t('twitchBot.chatError'));
26 }, [channel, chatText, t]);
28 const join = React.useCallback(async (bot_nick) => {
30 const rsp = await axios.post(`/api/channels/${channel.id}/join`, { bot_nick });
32 toastr.success(t('twitchBot.joinSuccess'));
34 toastr.error(t('twitchBot.joinError'));
38 const part = React.useCallback(async (bot_nick) => {
40 const rsp = await axios.post(`/api/channels/${channel.id}/part`, { bot_nick });
42 toastr.success(t('twitchBot.partSuccess'));
44 toastr.error(t('twitchBot.partError'));
49 <Row className="mb-4">
50 <Form.Group as={Col} md={6}>
51 <Form.Label>{t('twitchBot.channel')}</Form.Label>
56 onChange={({ channel }) => { setChannel(channel); }}
57 value={channel ? channel.id : ''}
61 <Form.Group as={Col} md={3}>
62 <Form.Label>{t('twitchBot.joinApp')}</Form.Label>
66 onChange={({ target: { value } }) => {
77 <Form.Group as={Col} md={3}>
78 <Form.Label>{t('twitchBot.joinChat')}</Form.Label>
82 onChange={({ target: { value } }) => {
97 <Form.Group as={Col} md={6}>
98 <Form.Label>{t('twitchBot.chat')}</Form.Label>
101 onChange={({ target: { value } }) => {
106 <div className="button-bar">
109 disabled={!chatText || !channel.join}
111 if (chatText) chat(chatText, 'localhorsttv');
115 {t('twitchBot.sendApp')}
119 disabled={!chatText || !channel.chat}
121 if (chatText) chat(chatText, 'horstiebot');
125 {t('twitchBot.sendChat')}
131 <Alert variant="info">
132 {t('twitchBot.selectChannel')}
138 export default Controls;