Add Error Modal

This commit is contained in:
Timothy Warren 2018-05-01 16:58:24 -04:00
parent da94a5ac68
commit a1eaf1fba6
2 changed files with 370 additions and 333 deletions

View File

@ -42,7 +42,7 @@ const cssFilename = 'static/css/[name].[contenthash:8].css';
// To have this structure working with relative paths, we have to use custom options. // To have this structure working with relative paths, we have to use custom options.
const extractTextPluginOptions = shouldUseRelativeAssetPaths const extractTextPluginOptions = shouldUseRelativeAssetPaths
? // Making sure that the publicPath goes back to to build folder. ? // Making sure that the publicPath goes back to to build folder.
{ publicPath: Array(cssFilename.split('/').length).join('../') } {publicPath: Array(cssFilename.split('/').length).join('../')}
: {}; : {};
// This is the production configuration. // This is the production configuration.
@ -79,7 +79,7 @@ module.exports = {
// https://github.com/infernojs/create-inferno-app/issues/253 // https://github.com/infernojs/create-inferno-app/issues/253
modules: ['node_modules', paths.appNodeModules].concat( modules: ['node_modules', paths.appNodeModules].concat(
// It is guaranteed to exist because we tweak it in `env.js` // It is guaranteed to exist because we tweak it in `env.js`
process.env.NODE_PATH.split(path.delimiter).filter(Boolean) process.env.NODE_PATH.split(path.delimiter).filter(Boolean),
), ),
// These are the reasonable defaults supported by the Node ecosystem. // These are the reasonable defaults supported by the Node ecosystem.
// We also include JSX as a common component filename extension to support // We also include JSX as a common component filename extension to support
@ -190,8 +190,8 @@ module.exports = {
}, },
], ],
}, },
extractTextPluginOptions extractTextPluginOptions,
) ),
), ),
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`. // Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
}, },
@ -286,7 +286,7 @@ module.exports = {
// about it being stale, and the cache-busting can be skipped. // about it being stale, and the cache-busting can be skipped.
dontCacheBustUrlsMatching: /\.\w{8}\./, dontCacheBustUrlsMatching: /\.\w{8}\./,
filename: 'service-worker.js', filename: 'service-worker.js',
logger(message) { logger (message) {
if (message.indexOf('Total precache size is') === 0) { if (message.indexOf('Total precache size is') === 0) {
// This message occurs for every build and is a bit too noisy. // This message occurs for every build and is a bit too noisy.
return; return;

View File

@ -1,14 +1,35 @@
import { Component } from 'inferno';
import { import {
Alert, Alert,
Button, Button,
Col, Col,
Container, Container,
Jumbotron, Jumbotron,
Modal,
ModalBody,
ModalFooter,
ModalHeader,
Row, Row,
} from '../components/Bootstrap'; } from '../components/Bootstrap';
import { JSONMessage } from '../helpers/web-socket'; import { JSONMessage } from '../helpers/web-socket';
function handleDrop (e) { export class HomeView extends Component {
constructor (props) {
super(props);
this.state = {
showModal: false,
};
this.toggleErrorModal = this.toggleErrorModal.bind(this);
}
handleDragOver (e) {
e.preventDefault();
e.stopPropagation();
}
handleDrop (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
@ -18,35 +39,36 @@ function handleDrop (e) {
} }
window.clientWS.send(JSONMessage('dropped-files', draggedFiles)); window.clientWS.send(JSONMessage('dropped-files', draggedFiles));
} }
function handleDragOver (e) { showErrorDialog () {
e.preventDefault();
e.stopPropagation();
}
function showOpenDialog () {
window.clientWS.send(JSONMessage('show-open-dialog', {}));
}
function showSaveDialog () {
window.clientWS.send(JSONMessage('show-save-dialog', {}));
}
function showErrorDialog () {
window.clientWS.send(JSONMessage( window.clientWS.send(JSONMessage(
'show-error-box', 'show-error-box',
'Looks like there was a problem. (╥﹏╥) \n (╯°□°)╯︵ ┻━┻' 'Looks like there was a problem. (╥﹏╥) \n (╯°□°)╯︵ ┻━┻'
)); ));
} }
export const HomeView = (props) => { showOpenDialog () {
window.clientWS.send(JSONMessage('show-open-dialog', {}));
}
showSaveDialog () {
window.clientWS.send(JSONMessage('show-save-dialog', {}));
}
toggleErrorModal () {
this.setState(prevState => ({
showModal: !prevState.showModal,
}));
}
render () {
return ( return (
<main> <main>
<Alert color="info"> <Alert color="info">
This is a work in progress This is a work in progress
</Alert> </Alert>
<Jumbotron onDrop={handleDrop} onDragover={handleDragOver}> <Jumbotron onDrop={this.handleDrop} onDragover={this.handleDragOver}>
<Container className="App"> <Container className="App">
<Row> <Row>
<header className="App-header"> <header className="App-header">
@ -59,18 +81,33 @@ export const HomeView = (props) => {
</p> </p>
</Row> </Row>
<Row> <Row>
<Col md={4}> <Col md={3}>
<Button onClick={showOpenDialog}>Show Open Dialog</Button> <Button onClick={this.showOpenDialog}>Show Open Dialog</Button>
</Col> </Col>
<Col md={4}> <Col md={3}>
<Button onClick={showSaveDialog}>Show Save Dialog</Button> <Button onClick={this.showSaveDialog}>Show Save Dialog</Button>
</Col> </Col>
<Col md={4}> <Col md={3}>
<Button onClick={showErrorDialog}>Show Error Dialog</Button> <Button onClick={this.showErrorDialog}>Show Error Dialog</Button>
</Col>
<Col md={3}>
<Button onClick={this.toggleErrorModal}>Show Error Modal</Button>
</Col> </Col>
</Row> </Row>
</Container> </Container>
</Jumbotron> </Jumbotron>
<Modal fade isOpen={this.state.showModal} toggle={this.toggleErrorModal}>
<ModalHeader toggle={this.toggleErrorModal}>
Error Title
</ModalHeader>
<ModalBody>
Body of error message
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.toggleErrorModal}>Close</Button>
</ModalFooter>
</Modal>
</main> </main>
); );
}; }
}