Skip to content

Commit

Permalink
#2966 – Error message after opening saved .PNG file
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitvex committed Jul 26, 2023
1 parent 8b9c8d8 commit 332c3e6
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,23 @@
* limitations under the License.
***************************************************************************/

import { RenderStruct } from 'ketcher-core';
import { MolSerializer, RenderStruct, Struct } from 'ketcher-core';
import { useEffect, useRef } from 'react';
import { Container } from './styles';
import { IStructRenderProps } from './types';

const normalizeStruct = (molV2000StringOrStruct: string | Struct) => {
if (molV2000StringOrStruct instanceof Struct) {
return molV2000StringOrStruct;
}

try {
return new MolSerializer().deserialize(molV2000StringOrStruct);
} catch (e) {
throw Error('Could not parse Struct');
}
};

const StructRender = ({ struct, options, className }: IStructRenderProps) => {
const renderRef = useRef<HTMLDivElement>(null);

Expand All @@ -27,7 +39,8 @@ const StructRender = ({ struct, options, className }: IStructRenderProps) => {

if (container) {
container.innerHTML = '';
RenderStruct.render(container, struct, options);
const normalizedStruct = normalizeStruct(struct);
RenderStruct.render(container, normalizedStruct, options);
}
}, [struct, options]);

Expand Down

0 comments on commit 332c3e6

Please sign in to comment.