diff options
| author | jules <jules@carbonpictures.com> | 2017-06-01 23:41:32 +0000 |
|---|---|---|
| committer | jules <jules@carbonpictures.com> | 2017-06-01 23:41:32 +0000 |
| commit | 291a7be04a43ef0062a31dbfafb481c6e7829b79 (patch) | |
| tree | 018241c1b8b83ab9f802ab3805b1d3fc9429dfa4 /lib/awprint/client | |
| parent | 8e7adf087ad73228b1d463411b1a6bfc329fb625 (diff) | |
| parent | 1dec5a464d13129194c41342afb3f73386132245 (diff) | |
Merge branch 'master' of ghghgh.us:armory-fmf-cms
Diffstat (limited to 'lib/awprint/client')
| -rw-r--r-- | lib/awprint/client/components/App.jsx | 100 | ||||
| -rw-r--r-- | lib/awprint/client/components/Modal.jsx | 14 | ||||
| -rw-r--r-- | lib/awprint/client/index.jsx | 13 |
3 files changed, 127 insertions, 0 deletions
diff --git a/lib/awprint/client/components/App.jsx b/lib/awprint/client/components/App.jsx new file mode 100644 index 0000000..4c4f9be --- /dev/null +++ b/lib/awprint/client/components/App.jsx @@ -0,0 +1,100 @@ +import React from 'react' + +import Modal from './Modal.jsx' + +const MAX_JOB_SIZE = 120 + +export default class App extends React.Component { + constructor(props) { + super() + this.state = { + jobs: [], + modalVisible: false, + } + this.load() + this.socket = io() + this.socket.on('job', (job) => this.prepend(job)) + } + + load() { + fetch('/_services/awprint/index') + .then( res => { + return res.json() + }).then( jobs => { + this.setState({ jobs }) + }).catch( e => { + console.error(e) + }) + } + + prepend(job) { + let jobs = this.state.jobs + if (this.state.jobs.length > MAX_JOB_SIZE) this.state.jobs.pop() + jobs.unshift(job) + console.log(job) + this.setState({ jobs }) + } + + print(job) { + job.printed = true + this.setState({ modalVisible: true }) + + // first request updates database + fetch('/_services/awprint/print', { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + _id: job._id, + }) + }) + .then( res => { + setTimeout( () => { + this.setState({ modalVisible: false }) + }, 1500) + }) + /* + // second request actually prints it? + fetch('/_services/awprint/print', { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + url: job.url, + }) + }) + .then( res => { + this.setState({ modalVisible: false }) + }) + */ + } + render() { + const jobs = this.state.jobs.map( (job,i) => { + const className = job.printed ? 'print printed' : 'print' + const datePartz = job.date.split('T') + const timePartz = datePartz[1].split(':') + const hour = Number(timePartz[0]) - 4 + const mins = timePartz[1] + const date = datePartz[0] + ' - ' + hour + ':' + mins + return ( + <div key={i} className={className} onClick={() => this.print(job)}> + <img src={job.url} /> + <div className='date'>{date}</div> + </div> + ) + }) + return ( + <div> + {jobs} + <Modal visible={this.state.modalVisible}> + <img src='public/spinner.svg' /> + <div>PRINTING YOUR PICTURE</div> + </Modal> + </div> + ) + } +}
\ No newline at end of file diff --git a/lib/awprint/client/components/Modal.jsx b/lib/awprint/client/components/Modal.jsx new file mode 100644 index 0000000..d3cac86 --- /dev/null +++ b/lib/awprint/client/components/Modal.jsx @@ -0,0 +1,14 @@ +import React, { Component } from 'react' + +export default class Modal extends Component { + render() { + let className = this.props.visible ? 'modal visible' : 'modal' + return ( + <div className={className}> + <div className='inner'> + {this.props.children} + </div> + </div> + ) + } +} diff --git a/lib/awprint/client/index.jsx b/lib/awprint/client/index.jsx new file mode 100644 index 0000000..136f3ff --- /dev/null +++ b/lib/awprint/client/index.jsx @@ -0,0 +1,13 @@ +import React from 'react' +import ReactDOM from 'react-dom' +import App from './components/App.jsx' + +const isIphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) +const isIpad = (navigator.userAgent.match(/iPad/i)) +const isAndroid = (navigator.userAgent.match(/Android/i)) +const isMobile = isIphone || isIpad || isAndroid +const isDesktop = ! isMobile + +document.body.classList.add(isDesktop ? 'desktop' : 'mobile') + +ReactDOM.render(<App />, document.getElementById('react-root')) |
