X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftwitch-bot%2FControls.js;fp=resources%2Fjs%2Fcomponents%2Ftwitch-bot%2FControls.js;h=0aea916cf04d698a879bc6bed886a88ebb426e08;hb=e10222af705e3475fcea6e0b17d1c9984a62db26;hp=158fb7c7ab5d8a58df9972e19f4162e1c8b5762b;hpb=5dc7faa01ad96732b0ea126e945f215a9d0490af;p=alttp.git diff --git a/resources/js/components/twitch-bot/Controls.js b/resources/js/components/twitch-bot/Controls.js index 158fb7c..0aea916 100644 --- a/resources/js/components/twitch-bot/Controls.js +++ b/resources/js/components/twitch-bot/Controls.js @@ -1,7 +1,76 @@ +import axios from 'axios'; import React from 'react'; +import { Alert, 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 { t } = useTranslation(); + + 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.selectChannel')} + + } + ; }; export default Controls;