From cca15b06407cce2ba9d3fae1d0c77f22f723f603 Mon Sep 17 00:00:00 2001 From: Faustino Kialungila Date: Mon, 13 Apr 2020 18:53:33 +0200 Subject: [PATCH] Disable notifications (#1421) * Remove notifications * remove dead component --- src/components/Toast.css | 33 -------------- src/components/Toast.tsx | 97 ---------------------------------------- src/serviceWorker.tsx | 18 ++++---- 3 files changed, 10 insertions(+), 138 deletions(-) delete mode 100644 src/components/Toast.css delete mode 100644 src/components/Toast.tsx diff --git a/src/components/Toast.css b/src/components/Toast.css deleted file mode 100644 index b4a418e7..00000000 --- a/src/components/Toast.css +++ /dev/null @@ -1,33 +0,0 @@ -.Toast__container { - position: fixed; - bottom: calc(var(--space-factor) * 2); - right: calc(var(--space-factor) * 2); - left: calc(var(--space-factor) * 2); - display: flex; - justify-content: center; - z-index: 1000; -} - -.Toast { - position: relative; -} - -.Toast__content { - padding-right: calc(var(--space-factor) * 9); - max-width: calc(var(--space-factor) * 50); -} - -.Toast__close { - position: absolute; - width: calc(var(--space-factor) * 5); - height: calc(var(--space-factor) * 5); - top: calc(var(--space-factor) * -1); - right: 0; - display: flex; - align-items: center; - justify-content: center; -} - -.Toast__close svg { - height: calc(var(--space-factor) * 3); -} diff --git a/src/components/Toast.tsx b/src/components/Toast.tsx deleted file mode 100644 index 84821d13..00000000 --- a/src/components/Toast.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import React from "react"; -import { render } from "react-dom"; -import Stack from "./Stack"; -import { Island } from "./Island"; -import "./Toast.css"; -import { close } from "./icons"; - -const TOAST_TIMEOUT = 7000; - -function ToastRenderer(props: { - toasts: Map; - onCloseRequest: (id: number) => void; -}) { - return ( - - {[...props.toasts.entries()].map(([id, toast]) => ( - -
-
{toast}
- -
-
- ))} -
- ); -} - -let toastsRootNode: HTMLDivElement; -function getToastsRootNode() { - return toastsRootNode || (toastsRootNode = initToastsRootNode()); -} - -function initToastsRootNode() { - const div = window.document.createElement("div"); - document.body.appendChild(div); - div.className = "Toast__container"; - return div; -} - -function renderToasts( - toasts: Map, - onCloseRequest: (id: number) => void, -) { - render( - , - getToastsRootNode(), - ); -} - -let incrementalId = 0; -function getToastId() { - return incrementalId++; -} - -class ToastManager { - private toasts = new Map(); - private timers = new Map(); - - public push(message: React.ReactNode, shiftAfterMs: number) { - const id = getToastId(); - this.toasts.set(id, message); - if (isFinite(shiftAfterMs)) { - const handle = window.setTimeout(() => this.pop(id), shiftAfterMs); - this.timers.set(id, handle); - } - this.render(); - } - - private pop = (id: number) => { - const handle = this.timers.get(id); - if (handle) { - window.clearTimeout(handle); - this.timers.delete(id); - } - this.toasts.delete(id); - this.render(); - }; - - private render() { - renderToasts(this.toasts, this.pop); - } -} - -let toastManagerInstance: ToastManager; -function getToastManager(): ToastManager { - return toastManagerInstance ?? (toastManagerInstance = new ToastManager()); -} - -export function push(message: React.ReactNode, manualClose = false) { - const toastManager = getToastManager(); - toastManager.push(message, manualClose ? Infinity : TOAST_TIMEOUT); -} diff --git a/src/serviceWorker.tsx b/src/serviceWorker.tsx index 8e1a6231..c605c7b9 100644 --- a/src/serviceWorker.tsx +++ b/src/serviceWorker.tsx @@ -1,8 +1,6 @@ // This optional code is used to register a service worker. // register() is not called by default. -import { push } from "./components/Toast"; - // This lets the app load faster on subsequent visits in production, and gives // it offline capabilities. However, it also means that developers (and users) // will only see deployed updates on subsequent visits to a page, after all the @@ -76,10 +74,11 @@ function registerValidSW(swUrl: string, config?: Config) { // At this point, the updated precached content has been fetched, // but the previous service worker will still serve the older // content until all client tabs are closed. - push( - "New content is available and will be used when all " + - "tabs for this page are closed.", - ); + + // console.log( + // "New content is available and will be used when all " + + // "tabs for this page are closed.", + // ); // Execute callback if (config && config.onUpdate) { @@ -89,7 +88,8 @@ function registerValidSW(swUrl: string, config?: Config) { // At this point, everything has been precached. // It's the perfect time to display a // "Content is cached for offline use." message. - push("Content is cached for offline use."); + + // console.log("Content is cached for offline use."); // Execute callback if (config && config.onSuccess) { @@ -129,7 +129,9 @@ function checkValidServiceWorker(swUrl: string, config?: Config) { } }) .catch(() => { - push("No internet connection found. App is running in offline mode."); + // console.log( + // "No internet connection found. App is running in offline mode.", + // ); }); }