Skip to content

Commit

Permalink
Merge pull request #66 from Kitware/adblock_wasm
Browse files Browse the repository at this point in the history
Tell user if file load errored
  • Loading branch information
floryst authored Apr 25, 2018
2 parents 5d5851c + ce5c081 commit ff54970
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 35 deletions.
12 changes: 12 additions & 0 deletions Sources/MainView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import 'normalize.css/normalize.css';
import React from 'react';
import PropTypes from 'prop-types';

import { ToastContainer, Slide } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

import UI from './ui';
import Layouts from './layouts';
import LayoutConfig from './config/glanceLayoutConfig';
Expand Down Expand Up @@ -185,6 +188,15 @@ export default class MainView extends React.Component {
>
<AboutPage />
</TitleModal>
<ToastContainer
position="top-right"
autoClose={8000}
transition={Slide}
hideProgressBar
closeOnClick
pauseOnHover
draggable={false}
/>
</div>
);
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/controls/FileLoader/RawReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ export default class RawReader extends React.Component {
<Button
className={style.button}
onClick={this.onLoad}
disabled={userDim !== this.state.size}
disabled={userDim !== this.state.size || this.state.loading}
style={{ marginLeft: '5px' }}
loading={this.state.loading}
>
Read
</Button>
Expand Down
9 changes: 7 additions & 2 deletions Sources/controls/FileLoader/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';

import { toast } from 'react-toastify';

import UI from '../../ui';
import ReaderFactory from '../../io/ReaderFactory';
import RawReader from './RawReader';
import style from './FileLoader.mcss';

const { Button, FaIcon } = UI;
const { Button, FaIcon, Messages } = UI;

export default class FileLoader extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -34,7 +36,10 @@ export default class FileLoader extends React.Component {
this.setState({ file: null });
this.props.updateTab('pipeline');
})
.catch(() => {
.catch((error) => {
if (error) {
toast.error(Messages.LoadFailure);
}
// No reader found
if (files.length === 1) {
this.setState({ file: files[0] });
Expand Down
8 changes: 5 additions & 3 deletions Sources/io/ReaderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ function readRawData({ fileName, data }) {
reader[fileNameMethod](fileName);
}
const ds = reader[parseMethod](data);
Promise.resolve(ds).then((dataset) =>
resolve({ dataset, reader, sourceType, name: fileName })
);
Promise.resolve(ds)
.then((dataset) =>
resolve({ dataset, reader, sourceType, name: fileName })
)
.catch(reject);
} else {
reject();
}
Expand Down
8 changes: 8 additions & 0 deletions Sources/ui/Messages/Messages.mcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.errorLine {
margin: 0;
padding: 2px;
}

.errorLink {
color: yellow;
}
47 changes: 47 additions & 0 deletions Sources/ui/Messages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import PropTypes from 'prop-types';

import style from './Messages.mcss';

function Link(props) {
return (
<a rel="noopener noreferrer" target="_blank" {...props}>
{props.children}
</a>
);
}

Link.propTypes = {
children: PropTypes.node,
};

Link.defaultProps = {
children: null,
};

export const LoadFailure = (
<div>
<p className={style.errorLine}>Failed to load image.</p>
<p className={style.errorLine}>
<Link
className={style.errorLink}
href="https://github.com/Kitware/pv-web-viewer/issues/62"
>
Perhaps AdBlock is enabled?
</Link>
</p>
<p className={style.errorLine}>
Or your image is not yet supported.&nbsp;
<Link
className={style.errorLink}
href="https://github.com/Kitware/pv-web-viewer/issues"
>
Tell us!
</Link>
</p>
</div>
);

export default {
LoadFailure,
};
2 changes: 2 additions & 0 deletions Sources/ui/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Button from './Button';
import Messages from './Messages';
import FaIcon from './FaIcon';
import Menu from './Menu';
import Progress from './Progress';
import TitleModal from './TitleModal';

export default {
Button,
Messages,
FaIcon,
Menu,
Progress,
Expand Down
63 changes: 35 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"mout": "1.0.0",
"normalize.css": "^8.0.0",
"paraviewweb": "3.0.13",
"react-toastify": "^4.0.0-rc.5",
"shelljs": "0.7.8",
"vtk.js": "6.4.19"
},
Expand Down

0 comments on commit ff54970

Please sign in to comment.