From 56ebd9dafcf8b8417abd5948cd8f035ce8c565c2 Mon Sep 17 00:00:00 2001 From: nklhrstv Date: Sat, 1 Feb 2020 10:46:00 +0200 Subject: [PATCH] Toast refactored to not use modals context --- src/App/App.js | 6 +- src/common/Toast/ToastContext.js | 10 +++ .../Toast.js => Toast/ToastItem/ToastItem.js} | 17 +++-- src/common/Toast/ToastItem/index.js | 3 + .../Toast => Toast/ToastItem}/styles.less | 4 +- src/common/Toast/ToastProvider.js | 72 +++++++++++++++++++ src/common/Toast/index.js | 7 ++ src/common/Toast/useToast.js | 8 +++ src/common/Toasts/Toast/index.js | 3 - src/common/Toasts/Toasts.js | 57 --------------- .../ToastsContainerContext.js | 7 -- .../ToastsContainerProvider.js | 20 ------ .../Toasts/ToastsContainerContext/index.js | 7 -- .../useToastsContainer.js | 8 --- src/common/Toasts/index.js | 3 - src/common/index.js | 5 +- 16 files changed, 119 insertions(+), 118 deletions(-) create mode 100644 src/common/Toast/ToastContext.js rename src/common/{Toasts/Toast/Toast.js => Toast/ToastItem/ToastItem.js} (78%) create mode 100644 src/common/Toast/ToastItem/index.js rename src/common/{Toasts/Toast => Toast/ToastItem}/styles.less (97%) create mode 100644 src/common/Toast/ToastProvider.js create mode 100644 src/common/Toast/index.js create mode 100644 src/common/Toast/useToast.js delete mode 100644 src/common/Toasts/Toast/index.js delete mode 100644 src/common/Toasts/Toasts.js delete mode 100644 src/common/Toasts/ToastsContainerContext/ToastsContainerContext.js delete mode 100644 src/common/Toasts/ToastsContainerContext/ToastsContainerProvider.js delete mode 100644 src/common/Toasts/ToastsContainerContext/index.js delete mode 100644 src/common/Toasts/ToastsContainerContext/useToastsContainer.js delete mode 100644 src/common/Toasts/index.js diff --git a/src/App/App.js b/src/App/App.js index 82b12d898..c7d23c300 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -2,7 +2,7 @@ require('spatial-navigation-polyfill'); const React = require('react'); const { Router } = require('stremio-router'); const { Core, KeyboardNavigation, ServicesProvider, Shell } = require('stremio/services'); -const { Toasts } = require('stremio/common'); +const { ToastProvider } = require('stremio/common'); const routerViewsConfig = require('./routerViewsConfig'); const styles = require('./styles'); @@ -51,14 +51,14 @@ const App = () => { { shellInitialized && coreInitialized ? - + - + :
} diff --git a/src/common/Toast/ToastContext.js b/src/common/Toast/ToastContext.js new file mode 100644 index 000000000..7418affbd --- /dev/null +++ b/src/common/Toast/ToastContext.js @@ -0,0 +1,10 @@ +const React = require('react'); + +const ToastContext = React.createContext({ + show: () => { }, + clear: () => { } +}); + +ToastContext.displayName = 'ToastContext'; + +module.exports = ToastContext; diff --git a/src/common/Toasts/Toast/Toast.js b/src/common/Toast/ToastItem/ToastItem.js similarity index 78% rename from src/common/Toasts/Toast/Toast.js rename to src/common/Toast/ToastItem/ToastItem.js index 8b4470c02..04ddbebe6 100644 --- a/src/common/Toasts/Toast/Toast.js +++ b/src/common/Toast/ToastItem/ToastItem.js @@ -5,7 +5,7 @@ const Icon = require('stremio-icons/dom'); const Button = require('stremio/common/Button'); const styles = require('./styles'); -const Toast = ({ type, title, message, icon, dataset, onSelect, onClose }) => { +const ToastItem = ({ type, title, message, icon, dataset, onSelect, onClose }) => { const toastOnClick = React.useCallback((event) => { if (!event.nativeEvent.selectPrevented && typeof onSelect === 'function') { onSelect({ @@ -28,7 +28,7 @@ const Toast = ({ type, title, message, icon, dataset, onSelect, onClose }) => { } }, [dataset, onClose]); return ( -