Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Quick hack to demo single block selection in columns
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Sep 13, 2020
1 parent f05ed23 commit 1d878bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/demo/BlockSelection.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* This component is only needed because we need <RecoilRoot> to wrap our
* stuff. Otherwise we'd implement this functionality in ColumnsBlockEdit
*
*/
import React from 'react';
import { doesNodeContainClick } from 'semantic-ui-react/dist/commonjs/lib';
import { useRecoilState } from 'recoil';
Expand All @@ -9,6 +14,7 @@ const BlockSelection = (props) => {
const { children, columns, selected } = props;
const blockNode = React.useRef(null);
const innerNode = React.useRef(null);
const currentSelectedBlock = React.useRef(null);

const [formStates, setFormStates] = useRecoilState(formStateQuery(columns));

Expand Down Expand Up @@ -40,6 +46,17 @@ const BlockSelection = (props) => {
};
});

React.useEffect(() => {
formStates.find((state) => {
if (state.selected && state.selected !== currentSelectedBlock.current) {
currentSelectedBlock.current = state.selected;
setFormStates({ selected: currentSelectedBlock.current });
return true;
}
return false;
});
});

return (
<div ref={blockNode} className="outer-selection-wrapper">
{DEBUG ? (
Expand Down
5 changes: 0 additions & 5 deletions src/demo/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
.demo-column {
padding: 0.3em;
}

.outer-select-wrapper {
padding-top: 1em;
border: 1px solid black;
}
}

.drag-drop-list-widget {
Expand Down

0 comments on commit 1d878bb

Please sign in to comment.