From 1ea31115b855ba089c1e32b64ffb138232c4651e Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 4 Apr 2018 21:28:47 -0400 Subject: [PATCH] Form values in state --- .env | 2 +- package.json | 8 +++---- src/Routes.js | 2 +- src/components/Bootstrap/Bootstrap.js | 4 ++-- src/components/Bootstrap/Grid.js | 2 +- src/components/Form/FormBlock.js | 2 +- src/views/Film/FilmAddView.js | 27 ++++++++++++++++------ yarn.lock | 33 ++++++++++++++++++++++----- 8 files changed, 57 insertions(+), 23 deletions(-) diff --git a/.env b/.env index 2dc03e4..7d1519f 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ BROWSER=none -NODE_PATH=src/ +NODE_PATH=./src/ diff --git a/package.json b/package.json index cbae66e..a1904b1 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "private": true, "dependencies": { "dist-exiftool": "^10.53.0", - "inferno": "^5.0.1", + "inferno": "^5.0.2", "inferno-bootstrap": "^5.0.0", - "inferno-router": "^5.0.1", + "inferno-router": "^5.0.2", "inferno-scripts": "6.3.0", "node-exiftool": "^2.3.0" }, @@ -33,8 +33,8 @@ "fix": "eslint --fix src/**/*.js", "lint": "eslint src/**/*.js", "pack": "build --dir", - "postinstall": "electron-builder install-app-deps", - "precommit": "yarn lint", + "postinstall": "set NODE_DIR=src/ electron-builder install-app-deps", + "precommit": "yarn lint", "react-start": "inferno-scripts start", "start": "nf start -p 3000", "test": "inferno-scripts test --env=jsdom" diff --git a/src/Routes.js b/src/Routes.js index 619a47d..026f40f 100644 --- a/src/Routes.js +++ b/src/Routes.js @@ -4,7 +4,7 @@ import * as V from './views'; export const Routes = (props) => ( - + diff --git a/src/components/Bootstrap/Bootstrap.js b/src/components/Bootstrap/Bootstrap.js index 3f47325..da8543a 100644 --- a/src/components/Bootstrap/Bootstrap.js +++ b/src/components/Bootstrap/Bootstrap.js @@ -28,8 +28,8 @@ import Tooltip from 'inferno-bootstrap/dist/Tooltip'; export const BSWrapper = (Component, tagName) => { return ({children, ...props}) => ( {children} - ) -} + ); +}; export const Alert = BSWrapper(BSAlert, 'bs-alert'); export const Jumbotron = BSWrapper(BSJumbotron, 'bs-jumbotron'); diff --git a/src/components/Bootstrap/Grid.js b/src/components/Bootstrap/Grid.js index b3c18d3..f889b6e 100644 --- a/src/components/Bootstrap/Grid.js +++ b/src/components/Bootstrap/Grid.js @@ -2,7 +2,7 @@ import BSCol from 'inferno-bootstrap/dist/Col'; import BSContainer from 'inferno-bootstrap/dist/Container'; import BSRow from 'inferno-bootstrap/dist/Row'; -import { BSWrapper } from './Bootstrap' +import { BSWrapper } from './Bootstrap'; export const Col = BSWrapper(BSCol, 'bs-col'); export const Container = BSWrapper(BSContainer, 'bs-container'); diff --git a/src/components/Form/FormBlock.js b/src/components/Form/FormBlock.js index 28762c6..583ef48 100644 --- a/src/components/Form/FormBlock.js +++ b/src/components/Form/FormBlock.js @@ -16,7 +16,7 @@ export const FormBlock = ({ : ; return ( - + {formElement} diff --git a/src/views/Film/FilmAddView.js b/src/views/Film/FilmAddView.js index 3a4ce62..69d9027 100644 --- a/src/views/Film/FilmAddView.js +++ b/src/views/Film/FilmAddView.js @@ -10,31 +10,39 @@ import { Col, Form, Row, -} from 'components/Bootstrap' +} from 'components/Bootstrap'; import { FormBlock } from 'components/Form'; export class FilmAddView extends Component { constructor (props) { - super (props); + super(props); this.state = { form: { valid: {}, values: {}, - } + }, }; } - handleFormChange (e) { - console.log(e); + handleFormChange (instance, e) { + instance.setState({ + form: { + ...instance.state.form, + values: { + ...instance.state.form.values, + [e.target.id]: e.target.value, + }, + }, + }); } render () { return ( -
+ Add a Film @@ -45,11 +53,13 @@ export class FilmAddView extends Component { label="Brand" name="brand" required + value={this.state.form.values['brand']} />