Skip to content

Commit

Permalink
#28 Recognize Molecule: pictures in tif-format cannot be loaded (#111)
Browse files Browse the repository at this point in the history
- add check if image preview is supported
- add info message if file is empty or incorrect
  • Loading branch information
AndreiMazol authored Nov 23, 2020
1 parent a636f0c commit fcfc296
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/script/ui/dialog/mainmenu/recognize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
***************************************************************************/

import React from 'react'
import React, { useState, useCallback } from 'react'
import { connect } from 'react-redux'
import { range } from 'lodash/fp'

Expand All @@ -28,6 +28,10 @@ import StructRender from '../../component/structrender'
import OpenButton from '../../component/view/openbutton'
import Spin from '../../component/view/spin'

function isImage(file) {
return file?.type?.includes('image')
}

function Recognize(prop) {
const {
file,
Expand All @@ -44,11 +48,15 @@ function Recognize(prop) {
onChangeImago,
...props
} = partProps
const [canPreviewImage, setCanPreviewImage] = useState(true)
const result = () =>
structStr && !(structStr instanceof Promise)
? { structStr, fragment }
: null

const clearFile = useCallback(() => {
onImage(null)
return true
}, [onImage])
return (
<Dialog
title="Import From Image"
Expand Down Expand Up @@ -84,18 +92,25 @@ function Recognize(prop) {
/>
</label>
<div className="picture">
{file && (
{file && isImage(file) && canPreviewImage && (
<img
alt=""
id="pic"
src={url(file) || ''}
onError={() => {
onImage(null)
//TODO: add error handler call
//legacy message: Error, it isn't a picture
setCanPreviewImage(false)
}}
/>
)}
{file && isImage(file) && !canPreviewImage && (
<div>
Preview of '{file.type}' MIME type does not supported by current
browser
</div>
)}
{(!file || (!isImage(file) && clearFile())) && (
<div>Please choose image</div>
)}
</div>
<div className="output">
{structStr &&
Expand Down

0 comments on commit fcfc296

Please sign in to comment.