Fix for fallback update dialog

This commit is contained in:
Josh Perez 2020-02-20 16:09:50 -08:00 committed by Scott Nonnenberg
parent f379c72aba
commit 018dc34e47
5 changed files with 70 additions and 34 deletions

View file

@ -17,6 +17,9 @@ const defaultProps = {
dismissDialog: action('dismiss-dialog'),
hasNetworkDialog: false,
i18n,
didSnooze: false,
showEventsCount: 0,
snoozeUpdate: action('snooze-update'),
startUpdate: action('start-update'),
};
@ -27,6 +30,13 @@ const permutations = [
dialogType: 1,
},
},
{
title: 'Update (didSnooze=true)',
props: {
dialogType: 1,
didSnooze: true,
},
},
{
title: 'Cannot Update',
props: {
@ -54,11 +64,13 @@ storiesOf('Components/UpdateDialog', module)
1
);
const hasNetworkDialog = boolean('hasNetworkDialog', false);
const didSnooze = boolean('didSnooze', false);
return (
<UpdateDialog
{...defaultProps}
dialogType={dialogType}
didSnooze={didSnooze}
hasNetworkDialog={hasNetworkDialog}
/>
);

View file

@ -1,5 +1,4 @@
import React from 'react';
import moment from 'moment';
import { Dialogs } from '../types/Dialogs';
import { Intl } from './Intl';
@ -8,46 +7,25 @@ import { LocalizerType } from '../types/Util';
export interface PropsType {
ackRender: () => void;
dialogType: Dialogs;
didSnooze: boolean;
dismissDialog: () => void;
hasNetworkDialog: boolean;
i18n: LocalizerType;
showEventsCount: number;
snoozeUpdate: () => void;
startUpdate: () => void;
}
type MaybeMoment = moment.Moment | null;
type ReactSnoozeHook = React.Dispatch<React.SetStateAction<MaybeMoment>>;
const SNOOZE_TIMER = 60 * 1000 * 30;
function handleSnooze(setSnoozeForLater: ReactSnoozeHook) {
setSnoozeForLater(moment().add(SNOOZE_TIMER));
setTimeout(() => {
setSnoozeForLater(moment());
}, SNOOZE_TIMER);
}
function canSnooze(snoozeUntil: MaybeMoment) {
return snoozeUntil === null;
}
function isSnoozed(snoozeUntil: MaybeMoment) {
if (snoozeUntil === null) {
return false;
}
return moment().isBefore(snoozeUntil);
}
export const UpdateDialog = ({
ackRender,
dialogType,
didSnooze,
dismissDialog,
hasNetworkDialog,
i18n,
snoozeUpdate,
startUpdate,
}: PropsType): JSX.Element | null => {
const [snoozeUntil, setSnoozeForLater] = React.useState<MaybeMoment>(null);
React.useEffect(() => {
ackRender();
});
@ -56,7 +34,7 @@ export const UpdateDialog = ({
return null;
}
if (dialogType === Dialogs.None || isSnoozed(snoozeUntil)) {
if (dialogType === Dialogs.None) {
return null;
}
@ -116,12 +94,10 @@ export const UpdateDialog = ({
<span>{i18n('autoUpdateNewVersionMessage')}</span>
</div>
<div className="module-left-pane-dialog__actions">
{canSnooze(snoozeUntil) && (
{!didSnooze && (
<button
className="module-left-pane-dialog__button--no-border"
onClick={() => {
handleSnooze(setSnoozeForLater);
}}
onClick={snoozeUpdate}
>
{i18n('autoUpdateLaterButtonLabel')}
</button>