Edit stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

  1. import React, { Component } from 'react';
  2. import './App.css';
  3. class App extends Component {
  4. constructor(...stuff) {
  5. super(...stuff)
  6. this.state = {
  7. wc: 0,
  8. goal: "",
  9. }
  10. }
  11. render() {
  12. const pct = ((this.state.wc / (this.state.goal || 250)) * 100)
  13. return (
  14. <div className="App">
  15. <textarea ref={this.onRef.bind(this)} onChange={this.onChange.bind(this)}></textarea>
  16. <div className="App-status">
  17. <span>{this.state.wc}</span>
  18. <span>&nbsp;/&nbsp;</span>
  19. <span><input ref={this.onRef2.bind(this)} placeholder="250" onChange={this.onChange2.bind(this)} value={this.state.goal} /></span>
  20. <span>{ pct.toFixed(pct < 10 ? 1 : 0) }%</span>
  21. </div>
  22. </div>
  23. );
  24. }
  25. onRef(ta) {
  26. this.ta = ta
  27. }
  28. onRef2(tb) {
  29. this.tb = tb
  30. }
  31. onChange() {
  32. clearTimeout(this.timeout)
  33. this.timeout = setTimeout(() => {
  34. const wc = this.ta.value.split("\n").join(" ").split(" ").filter(t => t.length > 0).length
  35. this.setState({wc})
  36. }, 100)
  37. }
  38. onChange2() {
  39. let goal = parseInt(this.tb.value)
  40. if (goal > 0) {
  41. this.setState({goal})
  42. } else {
  43. this.setState({goal: ""})
  44. }
  45. }
  46. }
  47. export default App;