diff --git a/package.json b/package.json index 05c75a6..948927d 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "@types/node": "^12.0.0", "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", + "make-workout": "^0.0.0", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.3", diff --git a/src/App.tsx b/src/App.tsx index 5016ac8..1ce69b4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,12 +1,34 @@ -import React from 'react'; +import React, { useState, useCallback } from 'react'; import { WorkoutPlot } from './components/WorkoutPlot'; +import { parse, stats } from 'make-workout'; + +const defaultWorkout = `Name: Hello + +Rest: 10:00 75% +Interval: 20:00 100% +Rest: 10:00 75% +`; export function App() { + const [text, setText] = useState(defaultWorkout); + const [statsText, setStatsText] = useState(stats(parse(defaultWorkout))); + + const onChange = useCallback((event: React.ChangeEvent) => { + const value = event.target.value; + setText(value); + try { + setStatsText(stats(parse(value))); + } catch (e) { + setStatsText(e.message); + } + }, [setText, setStatsText]); + return (

Workout editor

-