Skip to content

Commit

Permalink
Add block container stub
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Dec 29, 2022
1 parent 3c9d482 commit 2ce5641
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/SearchBlock/BlockContainer/BlockContainer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

export default function BlockContainer(props) {
return null;
}
40 changes: 40 additions & 0 deletions src/SearchBlock/BlockContainer/NewBlockAddButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { Button } from 'semantic-ui-react';
import { BlockChooser, Icon } from '@plone/volto/components';
import useOutsideClick from '@eeacms/search/lib/hocs/useOutsideClick';
import addSVG from '@plone/volto/icons/add.svg';

const NewBlockAddButton = (props) => {
const { allowedBlocks, block, index, onChangeGridItem } = props;
const ref = React.useRef();
const [isOpenMenu, setOpenMenu] = React.useState(false);

useOutsideClick(ref, () => setOpenMenu(false));

return (
<>
{isOpenMenu ? (
<div ref={ref}>
<BlockChooser
onMutateBlock={(block, value) => onChangeGridItem(index, value)}
currentBlock={block}
showRestricted
allowedBlocks={allowedBlocks}
/>
</div>
) : (
<Button
basic
icon
onClick={() => setOpenMenu(true)}
className="add-block-button"
aria-label={`Add grid block in position ${index}`}
>
<Icon name={addSVG} className="circled" size="24px" />
</Button>
)}
</>
);
};

export default NewBlockAddButton;
1 change: 1 addition & 0 deletions src/SearchBlock/BlockContainer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export BlockContainer from './BlockContainer';
3 changes: 2 additions & 1 deletion src/SearchBlock/SearchBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function SearchBlockView(props) {

const registry = React.useMemo(() => {
// TODO: this has the effect that the appConfig is never stable if the
// schema changes.
// schema changes, even if it's unrelated.
const reg = applyBlockSettings(
config.settings.searchlib,
appName,
Expand Down Expand Up @@ -49,6 +49,7 @@ function SearchBlockView(props) {
<div>
{mode !== 'view' && 'EEA Semantic Search block'}
<Variation
slotFills={data.slotFills}
registry={registry}
appName={appName}
mode={mode}
Expand Down
22 changes: 21 additions & 1 deletion src/SearchBlock/templates/FullView.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { BodyClass } from '@plone/volto/helpers';
import { SearchApp } from '@eeacms/search';
import { BlockContainer } from './../BlockContainer';

const overlayStyle = {
position: 'absolute',
Expand All @@ -9,6 +10,22 @@ const overlayStyle = {
zIndex: '100',
};

const slots = [
'aboveSearchInput',
'belowSearchInput',
'aboveResults',
'belowResults',
];

const getBlocks = (slotFills = {}, mode = 'view') => {
return Object.assign(
{},
slots.map((name) => ({
[name]: <BlockContainer block={name} data={slotFills[name]} />,
})),
);
};

function FullView(props) {
const { appName, mode } = props;

Expand All @@ -20,7 +37,10 @@ function FullView(props) {
{mode !== 'view' && (
<div className="overlay" style={overlayStyle}></div>
)}
<SearchApp {...props} />
<SearchApp
{...props}
slotFills={getBlocks(props.data?.slotFills, mode)}
/>
{props.children}
</div>
</BodyClass>
Expand Down

0 comments on commit 2ce5641

Please sign in to comment.