ServiceWorker: click toast to install update (dirty)
This commit is contained in:
parent
638fc35f77
commit
3e205a9610
5 changed files with 24 additions and 10 deletions
|
@ -2,24 +2,32 @@ import { ALERT_SHOW } from './alerts';
|
||||||
|
|
||||||
import type { MessageDescriptor } from 'react-intl';
|
import type { MessageDescriptor } from 'react-intl';
|
||||||
|
|
||||||
export type SnackbarActionSeverity = 'info' | 'success' | 'error'
|
export type SnackbarActionSeverity = 'info' | 'success' | 'error';
|
||||||
|
|
||||||
type SnackbarMessage = string | MessageDescriptor
|
type SnackbarMessage = string | MessageDescriptor;
|
||||||
|
|
||||||
export type SnackbarAction = {
|
export type SnackbarAction = {
|
||||||
type: typeof ALERT_SHOW
|
type: typeof ALERT_SHOW,
|
||||||
message: SnackbarMessage
|
message: SnackbarMessage,
|
||||||
actionLabel?: SnackbarMessage
|
actionLabel?: SnackbarMessage,
|
||||||
actionLink?: string
|
actionLink?: string,
|
||||||
severity: SnackbarActionSeverity
|
action?: () => void,
|
||||||
}
|
severity: SnackbarActionSeverity,
|
||||||
|
};
|
||||||
|
|
||||||
export const show = (severity: SnackbarActionSeverity, message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string): SnackbarAction => ({
|
export const show = (
|
||||||
|
severity: SnackbarActionSeverity,
|
||||||
|
message: SnackbarMessage,
|
||||||
|
actionLabel?: SnackbarMessage,
|
||||||
|
actionLink?: string,
|
||||||
|
action?: () => void,
|
||||||
|
): SnackbarAction => ({
|
||||||
type: ALERT_SHOW,
|
type: ALERT_SHOW,
|
||||||
message,
|
message,
|
||||||
actionLabel,
|
actionLabel,
|
||||||
actionLink,
|
actionLink,
|
||||||
severity,
|
severity,
|
||||||
|
action,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const info = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) =>
|
export const info = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) =>
|
||||||
|
|
Binary file not shown.
|
@ -5,7 +5,9 @@ import * as OfflinePluginRuntime from '@lcdp/offline-plugin/runtime';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
|
import snackbar from 'soapbox/actions/snackbar';
|
||||||
import * as BuildConfig from 'soapbox/build_config';
|
import * as BuildConfig from 'soapbox/build_config';
|
||||||
|
import { store } from 'soapbox/store';
|
||||||
import { printConsoleWarning } from 'soapbox/utils/console';
|
import { printConsoleWarning } from 'soapbox/utils/console';
|
||||||
|
|
||||||
import { default as Soapbox } from './containers/soapbox';
|
import { default as Soapbox } from './containers/soapbox';
|
||||||
|
@ -34,7 +36,9 @@ function main() {
|
||||||
// https://github.com/NekR/offline-plugin/pull/201#issuecomment-285133572
|
// https://github.com/NekR/offline-plugin/pull/201#issuecomment-285133572
|
||||||
OfflinePluginRuntime.install({
|
OfflinePluginRuntime.install({
|
||||||
onUpdateReady: function() {
|
onUpdateReady: function() {
|
||||||
OfflinePluginRuntime.applyUpdate();
|
store.dispatch(snackbar.show('info', 'An update is available.', 'Update', undefined, () => {
|
||||||
|
OfflinePluginRuntime.applyUpdate();
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
onUpdated: function() {
|
onUpdated: function() {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
|
|
@ -13,6 +13,7 @@ const AlertRecord = ImmutableRecord({
|
||||||
severity: 'info',
|
severity: 'info',
|
||||||
actionLabel: '',
|
actionLabel: '',
|
||||||
actionLink: '',
|
actionLink: '',
|
||||||
|
action: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
import type { AnyAction } from 'redux';
|
import type { AnyAction } from 'redux';
|
||||||
|
|
|
@ -186,6 +186,7 @@ const buildAlert = (item: any) => {
|
||||||
title: item.title,
|
title: item.title,
|
||||||
actionLabel: item.actionLabel,
|
actionLabel: item.actionLabel,
|
||||||
actionLink: item.actionLink,
|
actionLink: item.actionLink,
|
||||||
|
action: item.action,
|
||||||
key: item.key,
|
key: item.key,
|
||||||
className: `notification-bar-${item.severity}`,
|
className: `notification-bar-${item.severity}`,
|
||||||
activeClassName: 'snackbar--active',
|
activeClassName: 'snackbar--active',
|
||||||
|
|
Loading…
Reference in a new issue