mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
implement component that show toast for every error in core
This commit is contained in:
parent
416328a19d
commit
c82a4563df
2 changed files with 32 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ const React = require('react');
|
|||
const { Router } = require('stremio-router');
|
||||
const { Core, KeyboardNavigation, ServicesProvider, Shell } = require('stremio/services');
|
||||
const { ToastProvider } = require('stremio/common');
|
||||
const CoreEventsToaster = require('./CoreEventsToaster');
|
||||
const routerViewsConfig = require('./routerViewsConfig');
|
||||
const styles = require('./styles');
|
||||
|
||||
|
|
@ -23,13 +24,13 @@ const App = () => {
|
|||
};
|
||||
const onCoreStateChanged = () => {
|
||||
if (services.core.active) {
|
||||
window.core = services.core;
|
||||
services.core.dispatch({
|
||||
action: 'Load',
|
||||
args: {
|
||||
model: 'Ctx'
|
||||
}
|
||||
});
|
||||
window.core = services.core;
|
||||
}
|
||||
setCoreInitialized(services.core.active || services.core.error instanceof Error);
|
||||
};
|
||||
|
|
@ -52,6 +53,7 @@ const App = () => {
|
|||
{
|
||||
shellInitialized && coreInitialized ?
|
||||
<ToastProvider className={styles['toasts-container']}>
|
||||
<CoreEventsToaster />
|
||||
<Router
|
||||
className={styles['router']}
|
||||
homePath={'/'}
|
||||
|
|
|
|||
29
src/App/CoreEventsToaster.js
Normal file
29
src/App/CoreEventsToaster.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const React = require('react');
|
||||
const { useServices } = require('stremio/services');
|
||||
const { useToast } = require('stremio/common');
|
||||
|
||||
const CoreEventsToaster = () => {
|
||||
const { core } = useServices();
|
||||
const toast = useToast();
|
||||
React.useEffect(() => {
|
||||
const onEvent = ({ event, args }) => {
|
||||
// UserAuthenticated are handled only in the /intro route
|
||||
if (event === 'Error' && args.source.event !== 'UserAuthenticated') {
|
||||
toast.show({
|
||||
type: 'error',
|
||||
title: args.source.event,
|
||||
message: args.error.message,
|
||||
icon: 'ic_warning',
|
||||
timeout: 10000
|
||||
});
|
||||
}
|
||||
};
|
||||
core.on('Event', onEvent);
|
||||
return () => {
|
||||
core.off('Event', onEvent);
|
||||
};
|
||||
}, []);
|
||||
return null;
|
||||
};
|
||||
|
||||
module.exports = CoreEventsToaster;
|
||||
Loading…
Reference in a new issue