fix: update usage of string and bool in radio group

This commit is contained in:
Kee Jefferys 2023-10-18 13:38:36 +11:00
parent 6b78cc1d4b
commit b8ef827e62
5 changed files with 25 additions and 23 deletions

View File

@ -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) => {
<StyledInput
type="radio"
name={inputName || ''}
value={value.toString()}
value={value}
aria-checked={active}
checked={active}
onChange={clickHandler}

View File

@ -5,10 +5,10 @@ import styled, { CSSProperties } from 'styled-components';
import { SessionRadio } from './SessionRadio';
interface Props {
initialItem: string | boolean;
items: Array<{ value: string | boolean; label: string }>;
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<string | boolean>(initialItem);
const [activeItem, setActiveItem] = useState('');
useMount(() => {
setActiveItem(initialItem);
@ -43,12 +43,12 @@ export const SessionRadioGroup = (props: Props) => {
return (
<SessionRadio
key={item.value.toString()}
key={item.value}
label={item.label}
active={itemIsActive}
value={item.value}
inputName={group}
onClick={(value: string | boolean) => {
onClick={(value: string) => {
setActiveItem(value);
props.onClick(value);
}}

View File

@ -875,10 +875,12 @@ class CompositionBoxInner extends React.Component<Props, State> {
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,
});
}

View File

@ -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();
}}

View File

@ -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}
>
<SessionRadioGroup
initialItem={initialSetting}
initialItem={initialSetting ? 'enterForNewLine' : 'enterForSend'}
group={SettingsKey.hasShiftSendEnabled} // make sure to define this key in your SettingsKey enum
items={items}
/* eslint-disable @typescript-eslint/no-misused-promises */
onClick={async (selectedRadioValue: string | boolean) => {
await window.setSettingValue(SettingsKey.hasShiftSendEnabled, selectedRadioValue);
forceUpdate();
onClick={(selectedRadioValue: string) => {
void window.setSettingValue(
SettingsKey.hasShiftSendEnabled,
selectedRadioValue === selectedWithSettingTrue
);
}}
/* eslint-enable @typescript-eslint/no-misused-promises */
/>
</SessionSettingsItemWrapper>
);