import { Component } from 'react'; import Plainbudget from 'plainbudget'; import Textarea from '../components/textarea'; import Button from '../components/button'; export default class Index extends Component { static getInitialProps (ctx) { return { isMobile: ctx.isMobile }; } constructor (props) { super(props); this.compute = this.compute.bind(this); this.onTextareaKeyDown = this.onTextareaKeyDown.bind(this); this.onTextareaChange = this.onTextareaChange.bind(this); this.onComputeClick = this.onComputeClick.bind(this); } state = { value: '' } compute () { const { value } = this.state; const calculated = Plainbudget.computeSheet(value); return this.setState({ value: calculated }); } onTextareaKeyDown (event) { if ((event.metaKey || event.ctrlKey) && event.keyCode === 13) { this.compute(); } } onTextareaChange (value) { return this.setState({ value }); } onComputeClick (event) { event.preventDefault(); this.compute(); } render () { const { isMobile } = this.props; const { value } = this.state; return (