From e9e8775ee03ce0e0230e4df344d5a15e927e33ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Sat, 1 Dec 2018 13:45:20 +0800 Subject: [PATCH] use notification repalce modal for sw updated --- src/global.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/global.js b/src/global.js index 8c215e92..fb4e46ca 100644 --- a/src/global.js +++ b/src/global.js @@ -1,4 +1,5 @@ -import { Modal, message } from 'antd'; +import React from 'react'; +import { notification, Button, message } from 'antd'; import { formatMessage } from 'umi/locale'; // Notify user if offline now @@ -8,11 +9,18 @@ window.addEventListener('sw.offline', () => { // Pop up a prompt on the page asking the user if they want to use the latest version window.addEventListener('sw.updated', e => { - Modal.confirm({ - title: formatMessage({ id: 'app.pwa.serviceworker.updated' }), - content: formatMessage({ id: 'app.pwa.serviceworker.updated.hint' }), - okText: formatMessage({ id: 'app.pwa.serviceworker.updated.ok' }), - onOk: async () => { + const key = `open${Date.now()}`; + const btn = ( + + ); + notification.open({ + message: formatMessage({ id: 'app.pwa.serviceworker.updated' }), + description: formatMessage({ id: 'app.pwa.serviceworker.updated.hint' }), + btn, + key, + onClose: async () => { // Check if there is sw whose state is waiting in ServiceWorkerRegistration // https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration const worker = e.detail && e.detail.waiting; -- GitLab