diff --git a/ts/components/basic/SessionRadio.tsx b/ts/components/basic/SessionRadio.tsx index d45fb6682..7f9379b52 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; + value: string | boolean; active: boolean; inputName?: string; beforeMargins?: string; - onClick?: (value: string) => void; + onClick?: (value: string | boolean) => void; }; const StyledInput = styled.input<{ @@ -68,7 +68,7 @@ export const SessionRadio = (props: Props) => { ; + initialItem: string | boolean; + items: Array<{ value: string | boolean; label: string }>; group: string; - onClick: (selectedValue: string) => any; + onClick: (selectedValue: string | boolean) => void; 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(''); + const [activeItem, setActiveItem] = useState(initialItem); useMount(() => { setActiveItem(initialItem); @@ -43,12 +43,12 @@ export const SessionRadioGroup = (props: Props) => { return ( { + onClick={(value: string | boolean) => { setActiveItem(value); props.onClick(value); }} diff --git a/ts/components/conversation/composition/CompositionBox.tsx b/ts/components/conversation/composition/CompositionBox.tsx index c1d2d05e4..e1e0019dd 100644 --- a/ts/components/conversation/composition/CompositionBox.tsx +++ b/ts/components/conversation/composition/CompositionBox.tsx @@ -834,10 +834,10 @@ class CompositionBoxInner extends React.Component { private async onKeyDown(event: any) { const isEnter = event.key === 'Enter'; const isShiftEnter = event.shiftKey && isEnter; - const isEnterNewLineSetting = (window.getSettingValue(SettingsKey.settingsEnterKeyFunction) as string) === 'enterNewLine'; + const isShiftSendEnabled = window.getSettingValue(SettingsKey.hasShiftSendEnabled) as boolean; const isNotComposing = !event.nativeEvent.isComposing; - - if (isEnterNewLineSetting && isEnter && isNotComposing) { + + if (isShiftSendEnabled && isEnter && isNotComposing) { event.preventDefault(); if (isShiftEnter) { await this.onSendMessage(); @@ -861,27 +861,27 @@ class CompositionBoxInner extends React.Component { if (!messageBox) { return; } - + const { draft } = this.state; const { selectedConversationKey } = this.props; - + if (!selectedConversationKey) { - return; // add this check to prevent undefined from being used + return; // add this check to prevent undefined from being used } - + const currentSelectionStart = Number(messageBox.selectionStart); const realSelectionStart = getSelectionBasedOnMentions(draft, currentSelectionStart); - + const before = draft.slice(0, realSelectionStart); const after = draft.slice(realSelectionStart); - + this.setState({ draft: `${before}\n${after}` }); updateDraftForConversation({ conversationKey: selectedConversationKey, draft: `${before}\n${after}`, }); } - + private async onKeyUp() { if (!this.props.selectedConversationKey) { throw new Error('selectedConversationKey is needed'); diff --git a/ts/components/settings/SessionNotificationGroupSettings.tsx b/ts/components/settings/SessionNotificationGroupSettings.tsx index 1fd73d430..c28009247 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) => { + onClick={async (selectedRadioValue: string | boolean) => { await window.setSettingValue(SettingsKey.settingsNotification, selectedRadioValue); forceUpdate(); }} diff --git a/ts/components/settings/section/CategoryConversations.tsx b/ts/components/settings/section/CategoryConversations.tsx index b0335af4d..dd04a9115 100644 --- a/ts/components/settings/section/CategoryConversations.tsx +++ b/ts/components/settings/section/CategoryConversations.tsx @@ -8,7 +8,10 @@ import { toggleAudioAutoplay } from '../../../state/ducks/userConfig'; import { getAudioAutoplay } from '../../../state/selectors/userConfig'; import { SessionRadioGroup } from '../../basic/SessionRadioGroup'; import { BlockedContactsList } from '../BlockedList'; -import { SessionSettingsItemWrapper, SessionToggleWithDescription } from '../SessionSettingListItem'; +import { + SessionSettingsItemWrapper, + SessionToggleWithDescription, +} from '../SessionSettingListItem'; async function toggleCommunitiesPruning() { try { @@ -83,16 +86,16 @@ const AudioMessageAutoPlaySetting = () => { const EnterKeyFunctionSetting = () => { const forceUpdate = useUpdate(); - const initialSetting = window.getSettingValue(SettingsKey.settingsEnterKeyFunction) || true; + const initialSetting = window.getSettingValue(SettingsKey.hasShiftSendEnabled) || false; const items = [ { label: window.i18n('enterSendNewMessageDescription'), - value: 'enterSend', + value: false, }, { label: window.i18n('enterNewLineDescription'), - value: 'enterNewLine', + value: true, }, ]; @@ -104,11 +107,14 @@ const EnterKeyFunctionSetting = () => { > { - await window.setSettingValue(SettingsKey.settingsEnterKeyFunction, selectedRadioValue); - forceUpdate(); + onClick={(selectedRadioValue: string | boolean) => { + async function updateSetting() { + await window.setSettingValue(SettingsKey.hasShiftSendEnabled, selectedRadioValue); + forceUpdate(); + } + updateSetting().catch(error => window.log.error('Error updating setting:', error)); }} /> diff --git a/ts/data/settings-key.ts b/ts/data/settings-key.ts index a34782706..b5e9ea8c1 100644 --- a/ts/data/settings-key.ts +++ b/ts/data/settings-key.ts @@ -1,7 +1,7 @@ const settingsReadReceipt = 'read-receipt-setting'; const settingsTypingIndicator = 'typing-indicators-setting'; const settingsAutoUpdate = 'auto-update'; -const settingsEnterKeyFunction = 'enter-key-function-setting'; +const hasShiftSendEnabled = 'hasShiftSendEnabled'; const settingsMenuBar = 'hide-menu-bar'; const settingsSpellCheck = 'spell-check'; const settingsLinkPreview = 'link-preview-setting'; @@ -24,7 +24,7 @@ export const SettingsKey = { settingsReadReceipt, settingsTypingIndicator, settingsAutoUpdate, - settingsEnterKeyFunction, + hasShiftSendEnabled, settingsMenuBar, settingsSpellCheck, settingsLinkPreview, diff --git a/ts/state/ducks/settings.tsx b/ts/state/ducks/settings.tsx index 43868f4c1..b8b0e3a5f 100644 --- a/ts/state/ducks/settings.tsx +++ b/ts/state/ducks/settings.tsx @@ -8,6 +8,7 @@ const SettingsBoolsKeyTrackedInRedux = [ SettingsKey.someDeviceOutdatedSyncing, SettingsKey.settingsLinkPreview, SettingsKey.hasBlindedMsgRequestsEnabled, + SettingsKey.hasShiftSendEnabled, ] as const; export type SettingsState = { @@ -20,6 +21,7 @@ export function getSettingsInitialState() { someDeviceOutdatedSyncing: false, 'link-preview-setting': false, // this is the value of SettingsKey.settingsLinkPreview hasBlindedMsgRequestsEnabled: false, + hasShiftSendEnabled: false, }, }; } @@ -47,6 +49,8 @@ const settingsSlice = createSlice({ SettingsKey.hasBlindedMsgRequestsEnabled, false ); + const hasShiftSendEnabled = Storage.get(SettingsKey.hasShiftSendEnabled); + state.settingsBools.someDeviceOutdatedSyncing = isBoolean(outdatedSync) ? outdatedSync : false; @@ -54,6 +58,9 @@ const settingsSlice = createSlice({ state.settingsBools.hasBlindedMsgRequestsEnabled = isBoolean(hasBlindedMsgRequestsEnabled) ? hasBlindedMsgRequestsEnabled : false; + state.settingsBools.hasShiftSendEnabled = isBoolean(hasShiftSendEnabled) + ? hasShiftSendEnabled + : false; return state; }, updateSettingsBoolValue(state, action: PayloadAction<{ id: string; value: boolean }>) { diff --git a/ts/state/selectors/settings.ts b/ts/state/selectors/settings.ts index eb70ef9b1..19a5580b2 100644 --- a/ts/state/selectors/settings.ts +++ b/ts/state/selectors/settings.ts @@ -11,6 +11,9 @@ const getHasDeviceOutdatedSyncing = (state: StateType) => const getHasBlindedMsgRequestsEnabled = (state: StateType) => state.settings.settingsBools[SettingsKey.hasBlindedMsgRequestsEnabled]; +const getHasShiftSendEnabled = (state: StateType) => + state.settings.settingsBools[SettingsKey.hasShiftSendEnabled]; + export const useHasLinkPreviewEnabled = () => { const value = useSelector(getLinkPreviewEnabled); return Boolean(value); @@ -25,3 +28,8 @@ export const useHasBlindedMsgRequestsEnabled = () => { const value = useSelector(getHasBlindedMsgRequestsEnabled); return Boolean(value); }; + +export const useHasEnterSendEnabled = () => { + const value = useSelector(getHasShiftSendEnabled); + return Boolean(value); +};