Skip to content

Commit

Permalink
fix customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Jan 12, 2022
1 parent 56c7361 commit f808991
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@eeacms/volto-plotlycharts"
],
"dependencies": {
"@eeacms/volto-corsproxy": "2.1.1",
"@eeacms/volto-corsproxy": "*",
"@eeacms/volto-plotlycharts": "*",
"@n8tb1t/use-scroll-position": "^2.0.3",
"mgr-pdf-viewer-react": "^1.0.3",
Expand Down
50 changes: 48 additions & 2 deletions src/customizations/volto/components/theme/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import jwtDecode from 'jwt-decode';
import { compose } from 'redux';
import { asyncConnect } from '@plone/volto/helpers';
import { Segment, Grid } from 'semantic-ui-react';
Expand All @@ -17,6 +18,9 @@ import trim from 'lodash/trim';
import cx from 'classnames';
import config from '@plone/volto/registry';
import { PluggablesProvider } from '@plone/volto/components/manage/Pluggable';
import LockingToastsFactory from '@plone/volto/components/manage/LockingToastsFactory/LockingToastsFactory';
import WorkingCopyToastsFactory from '@plone/volto/components/manage/WorkingCopyToastsFactory/WorkingCopyToastsFactory';
import { visitBlocks } from '@plone/volto/helpers/Blocks/Blocks';
import Error from '@plone/volto/error';

import {
Expand Down Expand Up @@ -228,6 +232,11 @@ class App extends Component {
</Grid>
</div>
)}
<LockingToastsFactory
content={this.props.content}
user={this.props.userId}
/>
<WorkingCopyToastsFactory content={this.props.content} />
<ToastContainer
position={toast.POSITION.BOTTOM_CENTER}
hideProgressBar
Expand All @@ -248,7 +257,41 @@ class App extends Component {
);
}
}
export const fetchContent = async ({ store, location }) => {
const content = await store.dispatch(
getContent(getBaseUrl(location.pathname)),
);

const promises = [];
const { blocksConfig } = config.blocks;

const visitor = ([id, data]) => {
const blockType = data['@type'];
const { getAsyncData } = blocksConfig[blockType];
if (getAsyncData) {
const p = getAsyncData({
store,
dispatch: store.dispatch,
path: location.pathname,
location,
id,
data,
});
if (!p?.length) {
throw new Error(
'You should return a list of promises from getAsyncData',
);
}
promises.push(...p);
}
};

visitBlocks(content, visitor);

await Promise.allSettled(promises);

return content;
};
export const __test__ = connect(
(state, props) => ({
pathname: props.location.pathname,
Expand All @@ -269,8 +312,8 @@ export default compose(
},
{
key: 'content',
promise: ({ location, store: { dispatch } }) =>
__SERVER__ && dispatch(getContent(getBaseUrl(location.pathname))),
promise: ({ location, store }) =>
__SERVER__ && fetchContent({ store, location }),
},
{
key: 'navigation',
Expand All @@ -297,6 +340,9 @@ export default compose(
connect(
(state, props) => ({
pathname: state.router.location.pathname,
userId: state.userSession.token
? jwtDecode(state.userSession.token).sub
: '',
token: state.userSession.token,
content: state.content.data,
apiError: state.apierror.error,
Expand Down

0 comments on commit f808991

Please sign in to comment.