From 4ee5bc0f7868aa7ba156f1c1a101735e8d170ef0 Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Mon, 2 Mar 2020 19:14:51 -0800 Subject: [PATCH] hook input on LatlOutput to dispatch function --- src/components/LatlOutput.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/components/LatlOutput.js b/src/components/LatlOutput.js index a893de9..6f8a042 100644 --- a/src/components/LatlOutput.js +++ b/src/components/LatlOutput.js @@ -2,6 +2,34 @@ import React from 'react'; import './LatlOutput.scss'; const LatlOutput = ({results, options, dispatch}) => { + const handleClick = e => dispatchFunc => { + e.preventDefault() + return dispatchFunc(); + } + + const dispatchClear = () => { + const clearAction = { + type: 'CLEAR', + value: {} + } + dispatch(clearAction) + } + + const dispatchParse = () => { + const parseAction = { + type: 'PARSE_LATL', + value: {} + } + dispatch(parseAction) + } + + const dispatchRun = () => { + const runAction = { + type: 'RUN', + value: {} + } + dispatch(runAction) + } return (
@@ -10,7 +38,7 @@ const LatlOutput = ({results, options, dispatch}) => { {e.preventDefault()}} + onClick={e=>handleClick(e)(dispatchClear)} value="Clear" /> @@ -19,7 +47,7 @@ const LatlOutput = ({results, options, dispatch}) => { name="Parse" className="form form--add" type="submit" - onClick={e=>{e.preventDefault()}} + onClick={e=>handleClick(e)(dispatchParse)} value="Parse" /> @@ -28,7 +56,7 @@ const LatlOutput = ({results, options, dispatch}) => { name="Run" className="form form--add" type="submit" - onClick={e=>{e.preventDefault()}} + onClick={e=>handleClick(e)(dispatchRun)} value="Run" />