Skip to content

Commit

Permalink
#407 Properly turn on/off inspiration fragments when using the next/p…
Browse files Browse the repository at this point in the history
…revious arrows (bug of #384)
  • Loading branch information
Adriána Kohanová committed Oct 20, 2020
1 parent f68cd67 commit 174a35e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions js/components/datasets/datasetMoleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ export const DatasetMoleculeList = memo(

const disableUserInteraction = useDisableUserInteraction();

useEffect(() => {
if (selectedMoleculeRef) {
selectedMoleculeRef.scrollIntoView({
behavior: 'smooth',
block: 'nearest',
inline: 'nearest'
});
}
}, [selectedMoleculeRef]);

// TODO Reset Infinity scroll

if (isActiveFilter) {
Expand Down
12 changes: 12 additions & 0 deletions js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei

const { getNglView } = useContext(NglContext);
const stage = getNglView(VIEWS.MAJOR_VIEW) && getNglView(VIEWS.MAJOR_VIEW).stage;
const [selectedMoleculeViewRef, setSelectedMoleculeViewRef] = useState(null);

const filterRef = useRef();

Expand Down Expand Up @@ -352,6 +353,16 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
}
}, [isActiveFilter, setFilterItemsHeight]);

useEffect(() => {
if (selectedMoleculeViewRef) {
selectedMoleculeViewRef.scrollIntoView({
behavior: 'smooth',
block: 'nearest',
inline: 'nearest'
});
}
}, [selectedMoleculeViewRef]);

const handleFilterChange = filter => {
const filterSet = Object.assign({}, filter);
for (let attr of MOL_ATTRIBUTES) {
Expand Down Expand Up @@ -741,6 +752,7 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
previousItemData={index > 0 && array[index - 1]}
nextItemData={index < array?.length && array[index + 1]}
removeOfAllSelectedTypes={removeOfAllSelectedTypes}
setRef={setSelectedMoleculeViewRef}
/>
))}
</InfiniteScroll>
Expand Down
12 changes: 10 additions & 2 deletions js/components/preview/molecule/moleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ const MoleculeView = memo(
index,
previousItemData,
nextItemData,
removeOfAllSelectedTypes
removeOfAllSelectedTypes,
setRef
}) => {
// const [countOfVectors, setCountOfVectors] = useState('-');
// const [cmpds, setCmpds] = useState('-');
const selectedAll = useRef(false);
const ref = useRef(null);
const currentID = (data && data.id) || undefined;
const classes = useStyles();
const key = 'mol_image';
Expand Down Expand Up @@ -529,11 +531,17 @@ const MoleculeView = memo(
};

const handleClickOnDownArrow = () => {
if (setRef && ref.current) {
setRef(ref.current.nextSibling);
}
removeOfAllSelectedTypes();
moveSelectedMolSettings(nextItemData);
};

const handleClickOnUpArrow = () => {
if (setRef && ref.current) {
setRef(ref.current.previousSibling);
}
removeOfAllSelectedTypes();
moveSelectedMolSettings(previousItemData);
};
Expand All @@ -542,7 +550,7 @@ const MoleculeView = memo(

return (
<>
<Grid container justify="space-between" direction="row" className={classes.container} wrap="nowrap">
<Grid container justify="space-between" direction="row" className={classes.container} wrap="nowrap" ref={ref}>
{/* Site number */}
<Grid item container justify="space-between" direction="column" className={classes.site}>
<Grid item>
Expand Down

0 comments on commit 174a35e

Please sign in to comment.