Guest User

Untitled

a guest
Jun 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. import * as React from 'react'
  2. import { Router, Route, IndexRoute, hashHistory, browserHistory, Link } from 'react-router'
  3. import {ITask, IStoreAction, ActionType} from '../model/TasksModel'
  4.  
  5. import store from '../store/Store'
  6.  
  7. interface TaskEditProp {
  8. task: ITask
  9.  
  10. }
  11.  
  12. class TaskEdit extends React.Component<TaskEditProp, {}>{
  13. constructor() {
  14. super();
  15. this.state = store.getState()
  16.  
  17. store.subscribe(() => {
  18. this.setState(store.getState())
  19. })
  20.  
  21. //todo: console.log(this.props.location);
  22.  
  23. }
  24.  
  25. onSave = (e) => {
  26. e.preventDefault();
  27. var refs: any = this.refs;
  28. var task: ITask = {
  29. index: this.props.task ? this.props.task.index : 0,
  30. text: refs.text.value,
  31. done: false
  32. }
  33.  
  34. var storeAction: IStoreAction = {
  35. type: ActionType.EDIT_TASK,
  36. task
  37. }
  38.  
  39. store.dispatch(storeAction)
  40. browserHistory.push('/')
  41. }
  42.  
  43. onCancel = (e) => {
  44. e.preventDefault();
  45. browserHistory.push('/')
  46. }
  47.  
  48. render() {
  49.  
  50. const { props: { children } } = this;
  51. return (
  52. <div className="">
  53. <h3>Edit Task</h3>
  54. <form onSubmit={this.onSave}>
  55. <fieldset className="form-group">
  56. <label for="task">Task</label>
  57. <input type="text" ref="text" className="form-control" >{this.props.location}</input>
  58. </fieldset>
  59. <div className="btn-group">
  60. <button className="btn btn-primary" >Save</button>
  61. <button className="btn btn-warning" onClick={this.onCancel} >Cancel</button>
  62. </div>
  63. </form>
  64.  
  65. </div>
  66. )
  67. }
  68. }
  69.  
  70. export default TaskEdit;
  71.  
  72. var Routes = (
  73. <Router history={browserHistory}>
  74. <Route path="/" component={Tasks}>
  75. <IndexRoute component={TaskList} />
  76. <Route path="/add" component={TaskAdd} />
  77. <Route path="/edit/:id" component={TaskEdit} />
  78. </Route>
  79. <Route path="/about" component={About}/>
  80. </Router>
  81. )
  82.  
  83. let { id } = this.props.params;
  84.  
  85. index: this.props.task ? this.props.task.index : 0,
  86.  
  87. index: this.props.params.id ? this.props.params.id : 0,
  88.  
  89. Import { withRouter, Switch, Route, NavLink, RouteProps } from 'react-router-dom';
  90.  
  91. interface TaskEditProp extends RouteProps {
  92. task: ITask
  93. }
Add Comment
Please, Sign In to add comment