diff --git a/src/states/Manage/pages/ManageChannel/components/SettingsItem/SettingsItem.jsx b/src/states/Manage/pages/ManageChannel/components/SettingsItem/SettingsItem.jsx new file mode 100644 index 0000000..69e1e99 --- /dev/null +++ b/src/states/Manage/pages/ManageChannel/components/SettingsItem/SettingsItem.jsx @@ -0,0 +1,44 @@ +import "./styles.sass"; +import {useParams} from "react-router-dom"; +import {useContext, useEffect, useState} from "react"; +import {ChannelContext} from "@/states/Manage/pages/Channels/contexts/ChannelContext"; +import {patchRequest} from "@/common/util/RequestUtil.js"; +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; +import {faFloppyDisk} from "@fortawesome/free-solid-svg-icons"; + +export const SettingsItem = ({name, description, options, type, current}) => { + const params = useParams(); + const {channels, getChannelById, updateChannels} = useContext(ChannelContext); + const [currentChannel, setCurrentChannel] = useState(); + + const [settingUpdated, setSettingUpdated] = useState(false); + + useEffect(() => { + if (channels) setCurrentChannel(getChannelById(params.channel)); + }, [channels]); + + if (!currentChannel) return; + + const pathSetting = (e) => patchRequest("/channels/" + params.channel, {[type]: e.target.value}).then(() => { + updateChannels(); + setSettingUpdated(true); + setTimeout(() => setSettingUpdated(false), 1000); + }); + + return ( +
{description}
+