Skip to content

Commit

Permalink
refactor: database structure search modal
Browse files Browse the repository at this point in the history
  • Loading branch information
wadjih-bencheikh18 authored and targos committed Aug 8, 2023
1 parent 795ace9 commit 643cf27
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 51 deletions.
40 changes: 4 additions & 36 deletions src/component/panels/databasePanel/DatabasePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { DatabaseNMREntry, mapRanges } from 'nmr-processing';
import OCL from 'openchemlib/full';
import { useCallback, useState, useRef, memo, useEffect, useMemo } from 'react';
import { BsHexagon, BsHexagonFill } from 'react-icons/bs';
import { FaICursor } from 'react-icons/fa';
import { IoSearchOutline } from 'react-icons/io5';
import { useAccordionContext } from 'react-science/ui';
Expand All @@ -27,12 +26,10 @@ import {
import { useChartData } from '../../context/ChartContext';
import { useDispatch } from '../../context/DispatchContext';
import { usePreferences } from '../../context/PreferencesContext';
import Button from '../../elements/Button';
import Input from '../../elements/Input';
import Select from '../../elements/Select';
import ToggleButton from '../../elements/ToggleButton';
import { useAlert } from '../../elements/popup/Alert';
import { positions, transitions, useModal } from '../../elements/popup/Modal';
import { useFormatNumberByNucleus } from '../../hooks/useFormatNumberByNucleus';
import useToolsFunctions from '../../hooks/useToolsFunctions';
import { DISPLAYER_MODE } from '../../reducer/core/Constants';
Expand Down Expand Up @@ -84,7 +81,6 @@ function DatabasePanelInner({
}: DatabaseInnerProps) {
const dispatch = useDispatch();
const alert = useAlert();
const modal = useModal();
const { item } = useAccordionContext('Databases');

const { handleChangeOption } = useToolsFunctions();
Expand Down Expand Up @@ -329,19 +325,6 @@ function DatabasePanelInner({
const searchByStructureHandler = (idCodeValue: string) => {
setIdCode(idCodeValue);
};
const openSearchByStructure = () => {
modal.show(
<DatabaseStructureSearchModal
onChange={searchByStructureHandler}
idCode={idCode}
/>,
{
position: positions.MIDDLE,
transition: transitions.SCALE,
isBackgroundBlur: false,
},
);
};

return (
<div
Expand Down Expand Up @@ -407,25 +390,10 @@ function DatabasePanelInner({
onClear={clearHandler}
canClear
/>
<Button.Done
fill="clear"
onClick={openSearchByStructure}
style={{ marginLeft: '5px' }}
>
{!idCode ? (
<BsHexagon
style={{
fontSize: '14px',
}}
/>
) : (
<BsHexagonFill
style={{
fontSize: '14px',
}}
/>
)}
</Button.Done>
<DatabaseStructureSearchModal
onChange={searchByStructureHandler}
idCode={idCode}
/>
</DefaultPanelHeader>
)}
{isFlipped && (
Expand Down
73 changes: 58 additions & 15 deletions src/component/panels/databasePanel/DatabaseStructureSearchModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/** @jsxImportSource @emotion/react */
import { BsHexagon, BsHexagonFill } from 'react-icons/bs';
import { StructureEditor } from 'react-ocl/full';
import { Modal, useOnOff } from 'react-science/ui';

import CloseButton from '../../elements/CloseButton';
import Button from '../../elements/Button';
import { ModalStyles } from '../../modal/ModalStyle';

interface DatabaseStructureSearchModalProps {
Expand All @@ -15,21 +17,62 @@ export function DatabaseStructureSearchModal({
idCode,
onClose,
}: DatabaseStructureSearchModalProps) {
const [isOpenDialog, openDialog, closeDialog] = useOnOff(false);

return (
<div css={ModalStyles}>
<div className="header handle">
<span>Search by structure</span>
<CloseButton onClick={onClose} className="close-bt" />
</div>
<>
<Button.Done
fill="clear"
onClick={openDialog}
style={{ marginLeft: '5px' }}
>
{!idCode ? (
<BsHexagon
style={{
fontSize: '14px',
}}
/>
) : (
<BsHexagonFill
style={{
fontSize: '14px',
}}
/>
)}
</Button.Done>
<Modal
hasCloseButton
isOpen={isOpenDialog}
onRequestClose={() => {
onClose?.();
closeDialog();
}}
maxWidth={1000}
>
<div css={ModalStyles}>
<Modal.Header>
<div
className="header handle"
style={{
padding: '0',
margin: '0 30%',
width: '40%',
}}
>
<span>Search by structure</span>
</div>
</Modal.Header>

<div className="main-content">
<StructureEditor
initialIDCode={idCode}
svgMenu
fragment
onChange={(molFile, molecule, idCode) => onChange(idCode)}
/>
</div>
</div>
<div className="main-content">
<StructureEditor
initialIDCode={idCode}
svgMenu
fragment
onChange={(molFile, molecule, idCode) => onChange(idCode)}
/>
</div>
</div>
</Modal>
</>
);
}

0 comments on commit 643cf27

Please sign in to comment.