rename the "Disable chat" switch to a simple "Chat" (#286)

* change chat config lable

* reverse the chat enable UI

* add reversed to toggle switch props
This commit is contained in:
Meisam
2021-09-11 00:08:15 +02:00
committed by GitHub
parent 718ced0fda
commit 9589c8e11a
3 changed files with 11 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ interface ToggleSwitchProps {
apiPath?: string; apiPath?: string;
checked?: boolean; checked?: boolean;
reversed?: boolean;
configPath?: string; configPath?: string;
disabled?: boolean; disabled?: boolean;
label?: string; label?: string;
@@ -40,6 +41,7 @@ export default function ToggleSwitch(props: ToggleSwitchProps) {
const { const {
apiPath, apiPath,
checked, checked,
reversed = false,
configPath = '', configPath = '',
disabled = false, disabled = false,
fieldName, fieldName,
@@ -58,12 +60,13 @@ export default function ToggleSwitch(props: ToggleSwitchProps) {
const handleChange = async (isChecked: boolean) => { const handleChange = async (isChecked: boolean) => {
if (useSubmit) { if (useSubmit) {
setSubmitStatus(createInputStatus(STATUS_PROCESSING)); setSubmitStatus(createInputStatus(STATUS_PROCESSING));
const isCheckedSend = reversed ? !isChecked : isChecked;
await postConfigUpdateToAPI({ await postConfigUpdateToAPI({
apiPath, apiPath,
data: { value: isChecked }, data: { value: isCheckedSend },
onSuccess: () => { onSuccess: () => {
setFieldInConfigState({ fieldName, value: isChecked, path: configPath }); setFieldInConfigState({ fieldName, value: isCheckedSend, path: configPath });
setSubmitStatus(createInputStatus(STATUS_SUCCESS)); setSubmitStatus(createInputStatus(STATUS_SUCCESS));
}, },
onError: (message: string) => { onError: (message: string) => {
@@ -109,6 +112,7 @@ export default function ToggleSwitch(props: ToggleSwitchProps) {
ToggleSwitch.defaultProps = { ToggleSwitch.defaultProps = {
apiPath: '', apiPath: '',
checked: false, checked: false,
reversed: false,
configPath: '', configPath: '',
disabled: false, disabled: false,
label: '', label: '',

View File

@@ -36,7 +36,7 @@ export default function ConfigChat() {
}; };
function handleChatDisableChange(disabled: boolean) { function handleChatDisableChange(disabled: boolean) {
handleFieldChange({ fieldName: 'chatDisabled', value: disabled }); handleFieldChange({ fieldName: 'chatDisabled', value: !disabled });
} }
function resetForbiddenUsernameState() { function resetForbiddenUsernameState() {
@@ -95,7 +95,8 @@ export default function ConfigChat() {
<ToggleSwitch <ToggleSwitch
fieldName="chatDisabled" fieldName="chatDisabled"
{...FIELD_PROPS_DISABLE_CHAT} {...FIELD_PROPS_DISABLE_CHAT}
checked={formDataValues.chatDisabled} checked={!formDataValues.chatDisabled}
reversed
onChange={handleChatDisableChange} onChange={handleChatDisableChange}
/> />
<TextFieldWithSubmit <TextFieldWithSubmit

View File

@@ -178,8 +178,8 @@ export const DEFAULT_VARIANT_STATE: VideoVariant = {
export const FIELD_PROPS_DISABLE_CHAT = { export const FIELD_PROPS_DISABLE_CHAT = {
apiPath: API_CHAT_DISABLE, apiPath: API_CHAT_DISABLE,
configPath: '', configPath: '',
label: 'Disable chat', label: 'Chat',
tip: 'Disable chat functionality from your Owncast server.', tip: 'Turn the chat functionality on/off on your Owncast server.',
useSubmit: true, useSubmit: true,
}; };