fix: Refactor settings to use Redux
Refactor setting to use boolean which is stored in redux
This commit is contained in:
parent
8f2a41bc13
commit
95117afeea
|
@ -4,11 +4,11 @@ import { Flex } from './Flex';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string | boolean;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
inputName?: string;
|
inputName?: string;
|
||||||
beforeMargins?: string;
|
beforeMargins?: string;
|
||||||
onClick?: (value: string) => void;
|
onClick?: (value: string | boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledInput = styled.input<{
|
const StyledInput = styled.input<{
|
||||||
|
@ -68,7 +68,7 @@ export const SessionRadio = (props: Props) => {
|
||||||
<StyledInput
|
<StyledInput
|
||||||
type="radio"
|
type="radio"
|
||||||
name={inputName || ''}
|
name={inputName || ''}
|
||||||
value={value}
|
value={value.toString()}
|
||||||
aria-checked={active}
|
aria-checked={active}
|
||||||
checked={active}
|
checked={active}
|
||||||
onChange={clickHandler}
|
onChange={clickHandler}
|
||||||
|
|
|
@ -5,10 +5,10 @@ import styled, { CSSProperties } from 'styled-components';
|
||||||
import { SessionRadio } from './SessionRadio';
|
import { SessionRadio } from './SessionRadio';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
initialItem: string;
|
initialItem: string | boolean;
|
||||||
items: Array<{ value: string; label: string }>;
|
items: Array<{ value: string | boolean; label: string }>;
|
||||||
group: string;
|
group: string;
|
||||||
onClick: (selectedValue: string) => any;
|
onClick: (selectedValue: string | boolean) => void;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ const StyledFieldSet = styled.fieldset`
|
||||||
|
|
||||||
export const SessionRadioGroup = (props: Props) => {
|
export const SessionRadioGroup = (props: Props) => {
|
||||||
const { items, group, initialItem, style } = props;
|
const { items, group, initialItem, style } = props;
|
||||||
const [activeItem, setActiveItem] = useState('');
|
const [activeItem, setActiveItem] = useState<string | boolean>(initialItem);
|
||||||
|
|
||||||
useMount(() => {
|
useMount(() => {
|
||||||
setActiveItem(initialItem);
|
setActiveItem(initialItem);
|
||||||
|
@ -43,12 +43,12 @@ export const SessionRadioGroup = (props: Props) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SessionRadio
|
<SessionRadio
|
||||||
key={item.value}
|
key={item.value.toString()}
|
||||||
label={item.label}
|
label={item.label}
|
||||||
active={itemIsActive}
|
active={itemIsActive}
|
||||||
value={item.value}
|
value={item.value}
|
||||||
inputName={group}
|
inputName={group}
|
||||||
onClick={(value: string) => {
|
onClick={(value: string | boolean) => {
|
||||||
setActiveItem(value);
|
setActiveItem(value);
|
||||||
props.onClick(value);
|
props.onClick(value);
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -834,10 +834,10 @@ class CompositionBoxInner extends React.Component<Props, State> {
|
||||||
private async onKeyDown(event: any) {
|
private async onKeyDown(event: any) {
|
||||||
const isEnter = event.key === 'Enter';
|
const isEnter = event.key === 'Enter';
|
||||||
const isShiftEnter = event.shiftKey && isEnter;
|
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;
|
const isNotComposing = !event.nativeEvent.isComposing;
|
||||||
|
|
||||||
if (isEnterNewLineSetting && isEnter && isNotComposing) {
|
if (isShiftSendEnabled && isEnter && isNotComposing) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (isShiftEnter) {
|
if (isShiftEnter) {
|
||||||
await this.onSendMessage();
|
await this.onSendMessage();
|
||||||
|
|
|
@ -109,7 +109,7 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean |
|
||||||
initialItem={initialNotificationEnabled}
|
initialItem={initialNotificationEnabled}
|
||||||
group={SettingsKey.settingsNotification}
|
group={SettingsKey.settingsNotification}
|
||||||
items={items}
|
items={items}
|
||||||
onClick={async (selectedRadioValue: string) => {
|
onClick={async (selectedRadioValue: string | boolean) => {
|
||||||
await window.setSettingValue(SettingsKey.settingsNotification, selectedRadioValue);
|
await window.setSettingValue(SettingsKey.settingsNotification, selectedRadioValue);
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -8,7 +8,10 @@ import { toggleAudioAutoplay } from '../../../state/ducks/userConfig';
|
||||||
import { getAudioAutoplay } from '../../../state/selectors/userConfig';
|
import { getAudioAutoplay } from '../../../state/selectors/userConfig';
|
||||||
import { SessionRadioGroup } from '../../basic/SessionRadioGroup';
|
import { SessionRadioGroup } from '../../basic/SessionRadioGroup';
|
||||||
import { BlockedContactsList } from '../BlockedList';
|
import { BlockedContactsList } from '../BlockedList';
|
||||||
import { SessionSettingsItemWrapper, SessionToggleWithDescription } from '../SessionSettingListItem';
|
import {
|
||||||
|
SessionSettingsItemWrapper,
|
||||||
|
SessionToggleWithDescription,
|
||||||
|
} from '../SessionSettingListItem';
|
||||||
|
|
||||||
async function toggleCommunitiesPruning() {
|
async function toggleCommunitiesPruning() {
|
||||||
try {
|
try {
|
||||||
|
@ -83,16 +86,16 @@ const AudioMessageAutoPlaySetting = () => {
|
||||||
const EnterKeyFunctionSetting = () => {
|
const EnterKeyFunctionSetting = () => {
|
||||||
const forceUpdate = useUpdate();
|
const forceUpdate = useUpdate();
|
||||||
|
|
||||||
const initialSetting = window.getSettingValue(SettingsKey.settingsEnterKeyFunction) || true;
|
const initialSetting = window.getSettingValue(SettingsKey.hasShiftSendEnabled) || false;
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
label: window.i18n('enterSendNewMessageDescription'),
|
label: window.i18n('enterSendNewMessageDescription'),
|
||||||
value: 'enterSend',
|
value: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: window.i18n('enterNewLineDescription'),
|
label: window.i18n('enterNewLineDescription'),
|
||||||
value: 'enterNewLine',
|
value: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -104,11 +107,14 @@ const EnterKeyFunctionSetting = () => {
|
||||||
>
|
>
|
||||||
<SessionRadioGroup
|
<SessionRadioGroup
|
||||||
initialItem={initialSetting}
|
initialItem={initialSetting}
|
||||||
group={SettingsKey.settingsEnterKeyFunction} // make sure to define this key in your SettingsKey enum
|
group={SettingsKey.hasShiftSendEnabled} // make sure to define this key in your SettingsKey enum
|
||||||
items={items}
|
items={items}
|
||||||
onClick={async (selectedRadioValue: string) => {
|
onClick={(selectedRadioValue: string | boolean) => {
|
||||||
await window.setSettingValue(SettingsKey.settingsEnterKeyFunction, selectedRadioValue);
|
async function updateSetting() {
|
||||||
|
await window.setSettingValue(SettingsKey.hasShiftSendEnabled, selectedRadioValue);
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
|
}
|
||||||
|
updateSetting().catch(error => window.log.error('Error updating setting:', error));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SessionSettingsItemWrapper>
|
</SessionSettingsItemWrapper>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const settingsReadReceipt = 'read-receipt-setting';
|
const settingsReadReceipt = 'read-receipt-setting';
|
||||||
const settingsTypingIndicator = 'typing-indicators-setting';
|
const settingsTypingIndicator = 'typing-indicators-setting';
|
||||||
const settingsAutoUpdate = 'auto-update';
|
const settingsAutoUpdate = 'auto-update';
|
||||||
const settingsEnterKeyFunction = 'enter-key-function-setting';
|
const hasShiftSendEnabled = 'hasShiftSendEnabled';
|
||||||
const settingsMenuBar = 'hide-menu-bar';
|
const settingsMenuBar = 'hide-menu-bar';
|
||||||
const settingsSpellCheck = 'spell-check';
|
const settingsSpellCheck = 'spell-check';
|
||||||
const settingsLinkPreview = 'link-preview-setting';
|
const settingsLinkPreview = 'link-preview-setting';
|
||||||
|
@ -24,7 +24,7 @@ export const SettingsKey = {
|
||||||
settingsReadReceipt,
|
settingsReadReceipt,
|
||||||
settingsTypingIndicator,
|
settingsTypingIndicator,
|
||||||
settingsAutoUpdate,
|
settingsAutoUpdate,
|
||||||
settingsEnterKeyFunction,
|
hasShiftSendEnabled,
|
||||||
settingsMenuBar,
|
settingsMenuBar,
|
||||||
settingsSpellCheck,
|
settingsSpellCheck,
|
||||||
settingsLinkPreview,
|
settingsLinkPreview,
|
||||||
|
|
|
@ -8,6 +8,7 @@ const SettingsBoolsKeyTrackedInRedux = [
|
||||||
SettingsKey.someDeviceOutdatedSyncing,
|
SettingsKey.someDeviceOutdatedSyncing,
|
||||||
SettingsKey.settingsLinkPreview,
|
SettingsKey.settingsLinkPreview,
|
||||||
SettingsKey.hasBlindedMsgRequestsEnabled,
|
SettingsKey.hasBlindedMsgRequestsEnabled,
|
||||||
|
SettingsKey.hasShiftSendEnabled,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export type SettingsState = {
|
export type SettingsState = {
|
||||||
|
@ -20,6 +21,7 @@ export function getSettingsInitialState() {
|
||||||
someDeviceOutdatedSyncing: false,
|
someDeviceOutdatedSyncing: false,
|
||||||
'link-preview-setting': false, // this is the value of SettingsKey.settingsLinkPreview
|
'link-preview-setting': false, // this is the value of SettingsKey.settingsLinkPreview
|
||||||
hasBlindedMsgRequestsEnabled: false,
|
hasBlindedMsgRequestsEnabled: false,
|
||||||
|
hasShiftSendEnabled: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -47,6 +49,8 @@ const settingsSlice = createSlice({
|
||||||
SettingsKey.hasBlindedMsgRequestsEnabled,
|
SettingsKey.hasBlindedMsgRequestsEnabled,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
const hasShiftSendEnabled = Storage.get(SettingsKey.hasShiftSendEnabled);
|
||||||
|
|
||||||
state.settingsBools.someDeviceOutdatedSyncing = isBoolean(outdatedSync)
|
state.settingsBools.someDeviceOutdatedSyncing = isBoolean(outdatedSync)
|
||||||
? outdatedSync
|
? outdatedSync
|
||||||
: false;
|
: false;
|
||||||
|
@ -54,6 +58,9 @@ const settingsSlice = createSlice({
|
||||||
state.settingsBools.hasBlindedMsgRequestsEnabled = isBoolean(hasBlindedMsgRequestsEnabled)
|
state.settingsBools.hasBlindedMsgRequestsEnabled = isBoolean(hasBlindedMsgRequestsEnabled)
|
||||||
? hasBlindedMsgRequestsEnabled
|
? hasBlindedMsgRequestsEnabled
|
||||||
: false;
|
: false;
|
||||||
|
state.settingsBools.hasShiftSendEnabled = isBoolean(hasShiftSendEnabled)
|
||||||
|
? hasShiftSendEnabled
|
||||||
|
: false;
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
updateSettingsBoolValue(state, action: PayloadAction<{ id: string; value: boolean }>) {
|
updateSettingsBoolValue(state, action: PayloadAction<{ id: string; value: boolean }>) {
|
||||||
|
|
|
@ -11,6 +11,9 @@ const getHasDeviceOutdatedSyncing = (state: StateType) =>
|
||||||
const getHasBlindedMsgRequestsEnabled = (state: StateType) =>
|
const getHasBlindedMsgRequestsEnabled = (state: StateType) =>
|
||||||
state.settings.settingsBools[SettingsKey.hasBlindedMsgRequestsEnabled];
|
state.settings.settingsBools[SettingsKey.hasBlindedMsgRequestsEnabled];
|
||||||
|
|
||||||
|
const getHasShiftSendEnabled = (state: StateType) =>
|
||||||
|
state.settings.settingsBools[SettingsKey.hasShiftSendEnabled];
|
||||||
|
|
||||||
export const useHasLinkPreviewEnabled = () => {
|
export const useHasLinkPreviewEnabled = () => {
|
||||||
const value = useSelector(getLinkPreviewEnabled);
|
const value = useSelector(getLinkPreviewEnabled);
|
||||||
return Boolean(value);
|
return Boolean(value);
|
||||||
|
@ -25,3 +28,8 @@ export const useHasBlindedMsgRequestsEnabled = () => {
|
||||||
const value = useSelector(getHasBlindedMsgRequestsEnabled);
|
const value = useSelector(getHasBlindedMsgRequestsEnabled);
|
||||||
return Boolean(value);
|
return Boolean(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useHasEnterSendEnabled = () => {
|
||||||
|
const value = useSelector(getHasShiftSendEnabled);
|
||||||
|
return Boolean(value);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue