feat: make timer value load an existing one from the conversation or the default

fixed session radio button flickering
pull/2660/head
William Grant 3 years ago
parent c953c9f8f8
commit 8fb3f26376

@ -25,6 +25,7 @@ const StyledInput = styled.input<{
`; `;
// tslint:disable: use-simple-attributes // tslint:disable: use-simple-attributes
// NOTE (Will): We don't use a transition because it's too slow and creates flickering when changing buttons.
const StyledLabel = styled.label<{ const StyledLabel = styled.label<{
disabled: boolean; disabled: boolean;
filledSize: number; filledSize: number;
@ -39,7 +40,6 @@ const StyledLabel = styled.label<{
display: inline-block; display: inline-block;
border-radius: 100%; border-radius: 100%;
transition: var(--default-duration);
padding: ${props => props.filledSize}px; padding: ${props => props.filledSize}px;
border: none; border: none;
outline: 1px solid currentColor; /* CSS variables don't work here */ outline: 1px solid currentColor; /* CSS variables don't work here */

@ -49,10 +49,20 @@ const StyledNonAdminDescription = styled.div`
line-height: 15px; line-height: 15px;
`; `;
// TODO legacy messages support will be removed in a future release
function loadDefaultTimeValue(modeSelected: DisappearingMessageConversationType | undefined) {
return modeSelected !== 'off'
? modeSelected !== 'legacy'
? modeSelected === 'deleteAfterSend'
? DEFAULT_TIMER_OPTION.DELETE_AFTER_SEND
: DEFAULT_TIMER_OPTION.DELETE_AFTER_READ
: DEFAULT_TIMER_OPTION.LEGACY
: 0;
}
export type PropsForExpirationSettings = { export type PropsForExpirationSettings = {
expirationType: string | undefined; expirationType: string | undefined;
expireTimer: number | undefined; expireTimer: number | undefined;
isMe: boolean | undefined;
isGroup: boolean | undefined; isGroup: boolean | undefined;
weAreAdmin: boolean | undefined; weAreAdmin: boolean | undefined;
}; };
@ -84,16 +94,10 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
const { isGroup, weAreAdmin } = convoProps; const { isGroup, weAreAdmin } = convoProps;
const [modeSelected, setModeSelected] = useState(convoProps.expirationType); const [modeSelected, setModeSelected] = useState<DisappearingMessageConversationType | undefined>(
const [timeSelected, setTimeSelected] = useState( convoProps.expirationType
convoProps.expireTimer && convoProps.expireTimer > -1
? convoProps.expireTimer
: isGroup
? DEFAULT_TIMER_OPTION.DELETE_AFTER_SEND
: DEFAULT_TIMER_OPTION.DELETE_AFTER_READ
); );
const [timeSelected, setTimeSelected] = useState<number>(0);
// TODO verify that this if fine compared to updating in the useEffect
const timerOptions = useTimerOptionsByMode(modeSelected, hasOnlyOneMode); const timerOptions = useTimerOptionsByMode(modeSelected, hasOnlyOneMode);
const handleSetMode = async () => { const handleSetMode = async () => {
@ -108,7 +112,7 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
dispatch(resetRightOverlayMode()); dispatch(resetRightOverlayMode());
} }
} else { } else {
if (selectedConversationKey && modeSelected && timeSelected) { if (selectedConversationKey && modeSelected) {
await setDisappearingMessagesByConvoId(selectedConversationKey, modeSelected, timeSelected); await setDisappearingMessagesByConvoId(selectedConversationKey, modeSelected, timeSelected);
dispatch(closeRightPanel()); dispatch(closeRightPanel());
dispatch(resetRightOverlayMode()); dispatch(resetRightOverlayMode());
@ -116,14 +120,20 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
} }
}; };
const handleSetTime = (value: number) => {
setTimeSelected(value);
};
useEffect(() => { useEffect(() => {
if (modeSelected !== convoProps.expirationType) { // NOTE loads a time value from the conversation model or the default
setModeSelected(convoProps.expirationType); handleSetTime(
} modeSelected === convoProps.expirationType &&
if (convoProps.expireTimer && timeSelected !== convoProps.expireTimer) { convoProps.expireTimer &&
setTimeSelected(convoProps.expireTimer); convoProps.expireTimer > -1
} ? convoProps.expireTimer
}, [convoProps.expirationType, convoProps.expireTimer]); : loadDefaultTimeValue(modeSelected)
);
}, [convoProps.expirationType, convoProps.expireTimer, modeSelected]);
// TODO legacy messages support will be removed in a future // TODO legacy messages support will be removed in a future
useEffect(() => { useEffect(() => {
@ -165,7 +175,7 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
<TimeOptions <TimeOptions
options={timerOptions} options={timerOptions}
selected={timeSelected} selected={timeSelected}
setSelected={setTimeSelected} setSelected={handleSetTime}
hasOnlyOneMode={hasOnlyOneMode} hasOnlyOneMode={hasOnlyOneMode}
disabled={ disabled={
singleMode singleMode

@ -6,7 +6,7 @@ import { PanelRadioButton } from '../../../../buttons/PanelRadioButton';
type TimerOptionsProps = { type TimerOptionsProps = {
options: TimerOptionsArray | null; options: TimerOptionsArray | null;
selected?: number; selected: number;
setSelected: (value: number) => void; setSelected: (value: number) => void;
hasOnlyOneMode?: boolean; hasOnlyOneMode?: boolean;
disabled?: boolean; disabled?: boolean;

@ -1262,7 +1262,6 @@ export const getSelectedConversationExpirationSettings = createSelector(
(convo: ReduxConversationType | undefined): PropsForExpirationSettings => ({ (convo: ReduxConversationType | undefined): PropsForExpirationSettings => ({
expirationType: convo?.expirationType, expirationType: convo?.expirationType,
expireTimer: convo?.expireTimer, expireTimer: convo?.expireTimer,
isMe: convo?.isMe,
isGroup: convo?.isGroup, isGroup: convo?.isGroup,
weAreAdmin: convo?.weAreAdmin, weAreAdmin: convo?.weAreAdmin,
}) })

Loading…
Cancel
Save