From 2263f412817d6d2d36372e7617feb0d97fa57af8 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 4 Jul 2017 02:11:44 +0200 Subject: break out browser and tasks --- client/components/Tasks/TaskForm.jsx | 50 ++++++++++++++++++++++ client/components/Tasks/TaskFormView.jsx | 72 ++++++++++++++++++++++++++++++++ client/components/Tasks/Tasks.jsx | 38 +++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 client/components/Tasks/TaskForm.jsx create mode 100644 client/components/Tasks/TaskFormView.jsx create mode 100644 client/components/Tasks/Tasks.jsx (limited to 'client/components/Tasks') diff --git a/client/components/Tasks/TaskForm.jsx b/client/components/Tasks/TaskForm.jsx new file mode 100644 index 0000000..89771ad --- /dev/null +++ b/client/components/Tasks/TaskForm.jsx @@ -0,0 +1,50 @@ +import { h, Component } from 'preact' +import { Link } from 'react-router-dom' + +import client from '../../client.js' + +export default class TaskForm extends Component { + constructor(props) { + super() + this.state = { + name: '', + } + this.updateState = this.updateState.bind(this) + this.handleSubmit = this.handleSubmit.bind(this) + } + + updateState(event){ + const name = event.target.name + let value = event.target.value + console.log(name, value) + this.setState({ + [name]: value, + error: null, + }) + } + + updateAlpha(event){ + const name = event.target.name + let value = event.target.value + console.log(name, value) + this.setState({ + alphaValue: value, + alpha: '1e' + value, + error: null, + }) + } + + handleSubmit(event) { + event.preventDefault() + let rec = Object.assign({}, this.state) + delete rec.error + this.props.onClose() + client.folder.create( rec ).then( (data) => { + this.props.addFolder( data ) + }) + } + + render() { + return ( ) + } +} diff --git a/client/components/Tasks/TaskFormView.jsx b/client/components/Tasks/TaskFormView.jsx new file mode 100644 index 0000000..078f7c7 --- /dev/null +++ b/client/components/Tasks/TaskFormView.jsx @@ -0,0 +1,72 @@ +import { h, Component } from 'preact' +import { Link } from 'react-router-dom' + +import client from '../../client.js' + +export default class TaskForm extends Component { + constructor(props) { + super() + this.state = { + name: '', + } + this.updateState = this.updateState.bind(this) + this.handleSubmit = this.handleSubmit.bind(this) + } + updateState(event){ + const name = event.target.name + let value = event.target.value + console.log(name, value) + this.setState({ + [name]: value, + error: null, + }) + } + updateAlpha(event){ + const name = event.target.name + let value = event.target.value + console.log(name, value) + this.setState({ + alphaValue: value, + alpha: '1e' + value, + error: null, + }) + } + handleSubmit(event) { + event.preventDefault() + let rec = Object.assign({}, this.state) + delete rec.error + this.props.onClose() + client.folder.create( rec ).then( (data) => { + this.props.addFolder( data ) + }) + } + render() { + return ( +
+
+
+ + {this.state.content} +
+ + +
+
+
+ {this.state.style} +
+ + +
+
+ this.updateAlpha(e)} + /> + {this.state.alphaString} + + +
+
+ ) + } +} diff --git a/client/components/Tasks/Tasks.jsx b/client/components/Tasks/Tasks.jsx new file mode 100644 index 0000000..b72cd79 --- /dev/null +++ b/client/components/Tasks/Tasks.jsx @@ -0,0 +1,38 @@ +import { h, Component } from 'preact' +import { Link } from 'react-router-dom' + +import TaskForm from './TaskForm.jsx' + +import client from '../../client.js' + +export default class Tasks extends Component { + constructor(props) { + super() + this.state = { + adding: false, + } + client.task.index().then( tasks => this.setState({ tasks }) ) + } + render() { + const tasks = (this.props.tasks || []).map( (task, i) => { + return ( +
this.toggle(task)}> + {task.name} +
+ ) + }) + return ( +
+
+
+ tasks +
+ +
+ {tasks} +
+
+
+ ) + } +} -- cgit v1.2.3-70-g09d2