Skip to content

Commit

Permalink
fix: using same modal and snackbar manager for apps and boards (#132)
Browse files Browse the repository at this point in the history
* fix: using same modal and snackbar manager for apps and boards
* fix: removing unused manager providers
  • Loading branch information
nubsthead authored Sep 27, 2022
1 parent 355f975 commit 4715f80
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 48 deletions.
7 changes: 1 addition & 6 deletions src/boot/app/app-context-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@

import React, { FC } from 'react';
import { I18nextProvider } from 'react-i18next';
import { ModalManager, SnackbarManager } from '@zextras/carbonio-design-system';
import AppErrorCatcher from './app-error-catcher';
import { useI18n } from '../../store/i18n';

const AppContextProvider: FC<{ pkg: string }> = ({ pkg, children }) => {
const i18n = useI18n(pkg)();
return (
<I18nextProvider i18n={i18n}>
<ModalManager>
<SnackbarManager>
<AppErrorCatcher>{children}</AppErrorCatcher>
</SnackbarManager>
</ModalManager>
<AppErrorCatcher>{children}</AppErrorCatcher>
</I18nextProvider>
);
};
Expand Down
44 changes: 33 additions & 11 deletions src/boot/bootstrapper-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@

import React, { FC, useContext, useEffect } from 'react';
import { BrowserRouter, Route, Switch, useHistory, useParams } from 'react-router-dom';
import { SnackbarManagerContext, ModalManagerContext } from '@zextras/carbonio-design-system';
import {
SnackbarManagerContext,
ModalManagerContext,
ModalManager,
SnackbarManager
} from '@zextras/carbonio-design-system';
import { useTranslation } from 'react-i18next';
import AppLoaderMounter from './app/app-loader-mounter';
import { useBridge } from '../store/context-bridge';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import ShellView from '../shell/shell-view';
import { BASENAME, IS_STANDALONE } from '../constants';
import { useAppStore } from '../store/app';
import { NotificationPermissionChecker } from '../notification/NotificationPermissionChecker';
import { registerDefaultViews } from './app/default-views';

const ContextBridge: FC = () => {
const history = useHistory();
Expand All @@ -39,18 +47,32 @@ const StandaloneListener: FC = () => {
return null;
};

const DefaultViewsRegister: FC = () => {
const [t] = useTranslation();
useEffect(() => {
registerDefaultViews(t);
}, [t]);
return null;
};

const BootstrapperRouter: FC = () => (
<BrowserRouter basename={BASENAME}>
{IS_STANDALONE && (
<Switch>
<Route path={'/:route'}>
<StandaloneListener />
</Route>
</Switch>
)}
<ContextBridge />
<AppLoaderMounter />
<ShellView />
<SnackbarManager>
<ModalManager>
{IS_STANDALONE && (
<Switch>
<Route path={'/:route'}>
<StandaloneListener />
</Route>
</Switch>
)}
<DefaultViewsRegister />
<NotificationPermissionChecker />
<ContextBridge />
<AppLoaderMounter />
<ShellView />
</ModalManager>
</SnackbarManager>
</BrowserRouter>
);
export default BootstrapperRouter;
23 changes: 3 additions & 20 deletions src/boot/bootstrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,11 @@

import React, { FC, useEffect } from 'react';
import { SnackbarManager, ModalManager } from '@zextras/carbonio-design-system';
import { useTranslation } from 'react-i18next';
import { init } from './init';
import { ThemeProvider } from './theme-provider';
import BootstrapperRouter from './bootstrapper-router';
import BootstrapperContextProvider from './bootstrapper-provider';
import { unloadAllApps } from './app/load-apps';
import { registerDefaultViews } from './app/default-views';
import { NotificationPermissionChecker } from '../notification/NotificationPermissionChecker';

const DefaultViewsRegister: FC = () => {
const [t] = useTranslation();
useEffect(() => {
registerDefaultViews(t);
}, [t]);
return null;
};

const Bootstrapper: FC = () => {
useEffect(() => {
Expand All @@ -32,15 +21,9 @@ const Bootstrapper: FC = () => {
}, []);
return (
<ThemeProvider>
<SnackbarManager>
<ModalManager>
<BootstrapperContextProvider>
<DefaultViewsRegister />
<NotificationPermissionChecker />
<BootstrapperRouter />
</BootstrapperContextProvider>
</ModalManager>
</SnackbarManager>
<BootstrapperContextProvider>
<BootstrapperRouter />
</BootstrapperContextProvider>
</ThemeProvider>
);
};
Expand Down
15 changes: 4 additions & 11 deletions src/shell/shell-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { useEffect, useState, useContext, FC, useMemo } from 'react';
import { Row, Responsive, SnackbarManager, ModalManager } from '@zextras/carbonio-design-system';
import { Row, Responsive } from '@zextras/carbonio-design-system';
import styled from 'styled-components';
import { find } from 'lodash';
import { PreviewManager } from '@zextras/carbonio-ui-preview';
Expand Down Expand Up @@ -99,16 +99,9 @@ const ShellView: FC = () => {
const hideShellHeader = activeRoute?.standalone?.hideShellHeader as string | undefined;
return (
<ShellContextProvider>
<ModalManager>
<SnackbarManager>
<PreviewManager>
<MemoShell
allowUnauthenticated={allowUnauthenticated}
hideShellHeader={hideShellHeader}
/>
</PreviewManager>
</SnackbarManager>
</ModalManager>
<PreviewManager>
<MemoShell allowUnauthenticated={allowUnauthenticated} hideShellHeader={hideShellHeader} />
</PreviewManager>
</ShellContextProvider>
);
};
Expand Down

0 comments on commit 4715f80

Please sign in to comment.