X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftwitch-bot%2FControls.js;h=1faa912fa0c95525dcc7bf1983fac4113f0243f1;hb=51a752c7cce2465043dfb3d63a0152b64765b167;hp=158fb7c7ab5d8a58df9972e19f4162e1c8b5762b;hpb=3b545fa995c34c0ab8270ae495fedc24ddc2fe4d;p=alttp.git diff --git a/resources/js/components/twitch-bot/Controls.js b/resources/js/components/twitch-bot/Controls.js index 158fb7c..1faa912 100644 --- a/resources/js/components/twitch-bot/Controls.js +++ b/resources/js/components/twitch-bot/Controls.js @@ -1,7 +1,109 @@ +import axios from 'axios'; import React from 'react'; +import { Alert, Button, Col, Form, Row } from 'react-bootstrap'; +import { useTranslation } from 'react-i18next'; +import toastr from 'toastr'; + +import ChannelSelect from '../common/ChannelSelect'; +import ToggleSwitch from '../common/ToggleSwitch'; const Controls = () => { - return
; + const [channel, setChannel] = React.useState(null); + const [chatText, setChatText] = React.useState(''); + + const { t } = useTranslation(); + + const chat = React.useCallback(async text => { + try { + await axios.post(`/api/channels/${channel.id}/chat`, { + text, + }); + toastr.success(t('twitchBot.chatSuccess')); + } catch (e) { + toastr.error(t('twitchBot.chatError')); + } + }, [channel, chatText, t]); + + const join = React.useCallback(async () => { + try { + const rsp = await axios.post(`/api/channels/${channel.id}/join`); + setChannel(rsp.data); + toastr.success(t('twitchBot.joinSuccess')); + } catch (e) { + toastr.error(t('twitchBot.joinError')); + } + }, [channel, t]); + + const part = React.useCallback(async () => { + try { + const rsp = await axios.post(`/api/channels/${channel.id}/part`); + setChannel(rsp.data); + toastr.success(t('twitchBot.partSuccess')); + } catch (e) { + toastr.error(t('twitchBot.partError')); + } + }, [channel, t]); + + return <> + + + {t('twitchBot.channel')} + { setChannel(channel); }} + value={channel ? channel.id : ''} + /> + + {channel ? + + {t('twitchBot.join')} +
+ { + if (value) { + join(); + } else { + part(); + } + }} + value={channel.join} + /> +
+
+ : null} +
+ {channel ? + + + {t('twitchBot.chat')} + { + setChatText(value); + }} + value={chatText} + /> + + + + : + + {t('twitchBot.selectChannel')} + + } + ; }; export default Controls;