useExtensions fixed (extensions in context)

This commit is contained in:
Jan Prochazka 2020-11-21 20:20:47 +01:00
parent 5ec39054a3
commit 6ed3eaa896
3 changed files with 29 additions and 22 deletions

View File

@ -17,6 +17,7 @@ import { ModalLayerProvider } from './modals/showModal';
import UploadsProvider from './utility/UploadsProvider'; import UploadsProvider from './utility/UploadsProvider';
import ThemeHelmet from './themes/ThemeHelmet'; import ThemeHelmet from './themes/ThemeHelmet';
import PluginsProvider from './plugins/PluginsProvider'; import PluginsProvider from './plugins/PluginsProvider';
import { ExtensionsProvider } from './utility/useExtensions';
function App() { function App() {
return ( return (
@ -29,16 +30,18 @@ function App() {
<LeftPanelWidthProvider> <LeftPanelWidthProvider>
<ConnectionsPinger> <ConnectionsPinger>
<PluginsProvider> <PluginsProvider>
<ModalLayerProvider> <ExtensionsProvider>
<CurrentArchiveProvider> <ModalLayerProvider>
<CurrentThemeProvider> <CurrentArchiveProvider>
<UploadsProvider> <CurrentThemeProvider>
<ThemeHelmet /> <UploadsProvider>
<Screen /> <ThemeHelmet />
</UploadsProvider> <Screen />
</CurrentThemeProvider> </UploadsProvider>
</CurrentArchiveProvider> </CurrentThemeProvider>
</ModalLayerProvider> </CurrentArchiveProvider>
</ModalLayerProvider>
</ExtensionsProvider>
</PluginsProvider> </PluginsProvider>
</ConnectionsPinger> </ConnectionsPinger>
</LeftPanelWidthProvider> </LeftPanelWidthProvider>

View File

@ -354,10 +354,6 @@ export default function ImportExportConfigurator({ uploadedFile = undefined, onC
const [previewSource, setPreviewSource] = React.useState(null); const [previewSource, setPreviewSource] = React.useState(null);
const extensions = useExtensions(); const extensions = useExtensions();
console.log('ImportExportConfigurator', extensions);
const installed = useInstalledPlugins();
console.log('installed', installed);
const handleUpload = React.useCallback( const handleUpload = React.useCallback(
(file) => { (file) => {
console.log('UPLOAD', extensions); console.log('UPLOAD', extensions);

View File

@ -2,14 +2,22 @@ import React from 'react';
import { usePlugins } from '../plugins/PluginsProvider'; import { usePlugins } from '../plugins/PluginsProvider';
import { buildFileFormats } from './fileformats'; import { buildFileFormats } from './fileformats';
export default function useExtensions() { const ExtensionsContext = React.createContext(buildExtensions([]));
export function ExtensionsProvider({ children }) {
const plugins = usePlugins(); const plugins = usePlugins();
const extensions = React.useMemo( const extensions = React.useMemo(() => buildExtensions(plugins), [plugins]);
() => ({ return <ExtensionsContext.Provider value={extensions}>{children}</ExtensionsContext.Provider>;
plugins, }
fileFormats: buildFileFormats(plugins),
}), export function buildExtensions(plugins) {
[plugins] const extensions = {
); plugins,
fileFormats: buildFileFormats(plugins),
};
return extensions; return extensions;
} }
export default function useExtensions() {
return React.useContext(ExtensionsContext);
}