Snackbar: refactor to use opts object

virtuoso-debug
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,
};
export const show = (
severity: SnackbarActionSeverity,
message: SnackbarMessage,
type SnackbarOpts = {
actionLabel?: SnackbarMessage,
actionLink?: string,
action?: () => void,
};
export const show = (
severity: SnackbarActionSeverity,
message: SnackbarMessage,
opts?: SnackbarOpts,
): SnackbarAction => ({
type: ALERT_SHOW,
message,
actionLabel,
actionLink,
severity,
action,
...opts,
});
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) =>
show('success', message, actionLabel, actionLink);
show('success', message, { actionLabel, actionLink });
export const error = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) =>
show('error', message, actionLabel, actionLink);
show('error', message, { actionLabel, actionLink });
export default {
info,

Wyświetl plik

@ -4,6 +4,7 @@ import './precheck';
import * as OfflinePluginRuntime from '@lcdp/offline-plugin/runtime';
import React from 'react';
import ReactDOM from 'react-dom';
import { defineMessages } from 'react-intl';
import snackbar from 'soapbox/actions/snackbar';
import * as BuildConfig from 'soapbox/build_config';
@ -15,6 +16,11 @@ import * as monitoring from './monitoring';
import * as perf from './performance';
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() {
perf.start('main()');
@ -36,8 +42,11 @@ function main() {
// https://github.com/NekR/offline-plugin/pull/201#issuecomment-285133572
OfflinePluginRuntime.install({
onUpdateReady: function() {
store.dispatch(snackbar.show('info', 'An update is available.', 'Update', undefined, () => {
OfflinePluginRuntime.applyUpdate();
store.dispatch(snackbar.show('info', messages.updateText, {
actionLabel: messages.update,
action: () => {
OfflinePluginRuntime.applyUpdate();
},
}));
},
onUpdated: function() {