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 ThemeHelmet from './themes/ThemeHelmet';
import PluginsProvider from './plugins/PluginsProvider';
import { ExtensionsProvider } from './utility/useExtensions';
function App() {
return (
@ -29,6 +30,7 @@ function App() {
<LeftPanelWidthProvider>
<ConnectionsPinger>
<PluginsProvider>
<ExtensionsProvider>
<ModalLayerProvider>
<CurrentArchiveProvider>
<CurrentThemeProvider>
@ -39,6 +41,7 @@ function App() {
</CurrentThemeProvider>
</CurrentArchiveProvider>
</ModalLayerProvider>
</ExtensionsProvider>
</PluginsProvider>
</ConnectionsPinger>
</LeftPanelWidthProvider>

View File

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

View File

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