Snackbar: refactor to use opts object

environments/review-sw-skipwai-nw7uz5/deployments/366
Alex Gleason 2022-06-23 17:53:04 -05:00
rodzic 9fff48a49f
commit 82122ffe45
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 22 dodań i 11 usunięć

Wyświetl plik

@ -15,29 +15,31 @@ export type SnackbarAction = {
severity: SnackbarActionSeverity, severity: SnackbarActionSeverity,
}; };
export const show = ( type SnackbarOpts = {
severity: SnackbarActionSeverity,
message: SnackbarMessage,
actionLabel?: SnackbarMessage, actionLabel?: SnackbarMessage,
actionLink?: string, actionLink?: string,
action?: () => void, action?: () => void,
};
export const show = (
severity: SnackbarActionSeverity,
message: SnackbarMessage,
opts?: SnackbarOpts,
): SnackbarAction => ({ ): SnackbarAction => ({
type: ALERT_SHOW, type: ALERT_SHOW,
message, message,
actionLabel,
actionLink,
severity, severity,
action, ...opts,
}); });
export const info = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) => export const info = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) =>
show('info', message, actionLabel, actionLink); show('info', message, { actionLabel, actionLink });
export const success = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) => export const success = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) =>
show('success', message, actionLabel, actionLink); show('success', message, { actionLabel, actionLink });
export const error = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) => export const error = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) =>
show('error', message, actionLabel, actionLink); show('error', message, { actionLabel, actionLink });
export default { export default {
info, info,

Wyświetl plik

@ -4,6 +4,7 @@ import './precheck';
import * as OfflinePluginRuntime from '@lcdp/offline-plugin/runtime'; 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 { defineMessages } from 'react-intl';
import snackbar from 'soapbox/actions/snackbar'; import snackbar from 'soapbox/actions/snackbar';
import * as BuildConfig from 'soapbox/build_config'; import * as BuildConfig from 'soapbox/build_config';
@ -15,6 +16,11 @@ import * as monitoring from './monitoring';
import * as perf from './performance'; import * as perf from './performance';
import ready from './ready'; import ready from './ready';
const messages = defineMessages({
update: { id: 'sw.update', defaultMessage: 'Update' },
updateText: { id: 'sw.update_text', defaultMessage: 'An update is available.' },
});
function main() { function main() {
perf.start('main()'); perf.start('main()');
@ -36,8 +42,11 @@ 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() {
store.dispatch(snackbar.show('info', 'An update is available.', 'Update', undefined, () => { store.dispatch(snackbar.show('info', messages.updateText, {
actionLabel: messages.update,
action: () => {
OfflinePluginRuntime.applyUpdate(); OfflinePluginRuntime.applyUpdate();
},
})); }));
}, },
onUpdated: function() { onUpdated: function() {