From b8ef827e62663bdc22a9fa56f58363181351cc70 Mon Sep 17 00:00:00 2001 From: Kee Jefferys Date: Wed, 18 Oct 2023 13:38:36 +1100 Subject: [PATCH] fix: update usage of string and bool in radio group --- ts/components/basic/SessionRadio.tsx | 6 ++--- ts/components/basic/SessionRadioGroup.tsx | 12 +++++----- .../composition/CompositionBox.tsx | 6 +++-- .../SessionNotificationGroupSettings.tsx | 2 +- .../section/CategoryConversations.tsx | 22 +++++++++---------- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/ts/components/basic/SessionRadio.tsx b/ts/components/basic/SessionRadio.tsx index 7f9379b52..d45fb6682 100644 --- a/ts/components/basic/SessionRadio.tsx +++ b/ts/components/basic/SessionRadio.tsx @@ -4,11 +4,11 @@ import { Flex } from './Flex'; type Props = { label: string; - value: string | boolean; + value: string; active: boolean; inputName?: string; beforeMargins?: string; - onClick?: (value: string | boolean) => void; + onClick?: (value: string) => void; }; const StyledInput = styled.input<{ @@ -68,7 +68,7 @@ export const SessionRadio = (props: Props) => { ; + initialItem: string; + items: Array<{ value: string; label: string }>; group: string; - onClick: (selectedValue: string | boolean) => void; + onClick: (selectedValue: string) => any; style?: CSSProperties; } @@ -30,7 +30,7 @@ const StyledFieldSet = styled.fieldset` export const SessionRadioGroup = (props: Props) => { const { items, group, initialItem, style } = props; - const [activeItem, setActiveItem] = useState(initialItem); + const [activeItem, setActiveItem] = useState(''); useMount(() => { setActiveItem(initialItem); @@ -43,12 +43,12 @@ export const SessionRadioGroup = (props: Props) => { return ( { + onClick={(value: string) => { setActiveItem(value); props.onClick(value); }} diff --git a/ts/components/conversation/composition/CompositionBox.tsx b/ts/components/conversation/composition/CompositionBox.tsx index e1e0019dd..466a9aeb0 100644 --- a/ts/components/conversation/composition/CompositionBox.tsx +++ b/ts/components/conversation/composition/CompositionBox.tsx @@ -875,10 +875,12 @@ class CompositionBoxInner extends React.Component { const before = draft.slice(0, realSelectionStart); const after = draft.slice(realSelectionStart); - this.setState({ draft: `${before}\n${after}` }); + const updatedDraft = `${before}\n${after}`; + + this.setState({ draft: updatedDraft }); updateDraftForConversation({ conversationKey: selectedConversationKey, - draft: `${before}\n${after}`, + draft: updatedDraft, }); } diff --git a/ts/components/settings/SessionNotificationGroupSettings.tsx b/ts/components/settings/SessionNotificationGroupSettings.tsx index c28009247..1fd73d430 100644 --- a/ts/components/settings/SessionNotificationGroupSettings.tsx +++ b/ts/components/settings/SessionNotificationGroupSettings.tsx @@ -109,7 +109,7 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean | initialItem={initialNotificationEnabled} group={SettingsKey.settingsNotification} items={items} - onClick={async (selectedRadioValue: string | boolean) => { + onClick={async (selectedRadioValue: string) => { await window.setSettingValue(SettingsKey.settingsNotification, selectedRadioValue); forceUpdate(); }} diff --git a/ts/components/settings/section/CategoryConversations.tsx b/ts/components/settings/section/CategoryConversations.tsx index 25853b621..4fd0a2074 100644 --- a/ts/components/settings/section/CategoryConversations.tsx +++ b/ts/components/settings/section/CategoryConversations.tsx @@ -12,6 +12,7 @@ import { SessionSettingsItemWrapper, SessionToggleWithDescription, } from '../SessionSettingListItem'; +import { useHasEnterSendEnabled } from '../../../state/selectors/settings'; async function toggleCommunitiesPruning() { try { @@ -84,18 +85,17 @@ const AudioMessageAutoPlaySetting = () => { }; const EnterKeyFunctionSetting = () => { - const forceUpdate = useUpdate(); - - const initialSetting = window.getSettingValue(SettingsKey.hasShiftSendEnabled) || false; + const initialSetting = useHasEnterSendEnabled(); + const selectedWithSettingTrue = 'enterForNewLine'; const items = [ { label: window.i18n('enterSendNewMessageDescription'), - value: false, + value: 'enterForSend', }, { label: window.i18n('enterNewLineDescription'), - value: true, + value: selectedWithSettingTrue, }, ]; @@ -106,15 +106,15 @@ const EnterKeyFunctionSetting = () => { inline={false} > { - await window.setSettingValue(SettingsKey.hasShiftSendEnabled, selectedRadioValue); - forceUpdate(); + onClick={(selectedRadioValue: string) => { + void window.setSettingValue( + SettingsKey.hasShiftSendEnabled, + selectedRadioValue === selectedWithSettingTrue + ); }} - /* eslint-enable @typescript-eslint/no-misused-promises */ /> );