diff --git a/src/App.tsx b/src/App.tsx index 9a0d704..7e69ded 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useRef } from "react"; import { WorkBook } from "xlsx/types"; import { Row, Col, Select } from "antd"; @@ -19,19 +19,22 @@ function App() { const [leftsheetlist, setLeftSheetlist] = useState(null); const [hotTableComponentLeft] = useState(React.createRef()); const [leftsheetdata, setLeftSheetData] = useState( - JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 10))) + JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 8))) ); const [leftWorkbook, setLeftWorkbook] = useState(); const [rightsheetname, setRightSheetname] = useState("Sheet1"); const [rightsheetlist, setRightSheetlist] = useState(null); const [hotTableComponentRight] = useState(React.createRef()); const [rightsheetdata, setRightSheetData] = useState( - JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 10))) + JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 8))) ); const [rightWorkbook, setRightWorkbook] = useState(); const [diffBtnText] = useState(">> Diff <<"); const [hotTableComponentDiffResult] = useState(React.createRef()); + const leftFileSelectRef = useRef(null); + const rightFileSelectRef = useRef(null); + const fileHandler = ( event: React.ChangeEvent, field: string @@ -110,6 +113,7 @@ function App() { onSheetSelectChange={(e) => onSheetFieldChange(e, "left")} hotTableComponentLeft={hotTableComponentLeft} sheetdata={leftsheetdata} + fileRef={leftFileSelectRef} /> @@ -122,6 +126,21 @@ function App() { setLeftSheetData(ExcelHelper.SampleDataLeft); setRightSheetData(ExcelHelper.SampleDataRight); }} + onResetBtnClick={(e) => { + // window.location.reload(); + leftFileSelectRef.current.value = ""; + rightFileSelectRef.current.value = ""; + setLeftSheetlist(null); + setRightSheetlist(null); + setLeftSheetname("Sheet1"); + setRightSheetname("Sheet1"); + setLeftSheetData( + JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 8))) + ); + setRightSheetData( + JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 8))) + ); + }} /> @@ -132,6 +151,7 @@ function App() { onSheetSelectChange={(e) => onSheetFieldChange(e, "right")} hotTableComponentRight={hotTableComponentRight} sheetdata={rightsheetdata} + fileRef={rightFileSelectRef} /> diff --git a/src/components/Center.tsx b/src/components/Center.tsx index 99bbc6c..bd75d10 100644 --- a/src/components/Center.tsx +++ b/src/components/Center.tsx @@ -6,6 +6,7 @@ interface DiffBtn { btntext: string; onDiffBtnClick(e: React.MouseEvent): any; onSampleBtnClick(e: React.MouseEvent): any; + onResetBtnClick(e: React.MouseEvent): any; } const CenterHooks = (props: DiffBtn) => { @@ -29,6 +30,15 @@ const CenterHooks = (props: DiffBtn) => { > {props.btntext} + ); }; diff --git a/src/components/Import.tsx b/src/components/Import.tsx index fc81e64..c75f178 100644 --- a/src/components/Import.tsx +++ b/src/components/Import.tsx @@ -6,6 +6,7 @@ import "antd/dist/antd.css"; interface Import { sheetname: string; sheetlist: any; + fileRef: React.RefObject; onFileSelectChange(e: React.ChangeEvent): any; onSheetSelectChange(e: string): any; } @@ -23,6 +24,7 @@ const ImportHooks = (props: Import) => { accept={ExcelHelper.SheetJSFT()} aria-label="Select original file" onChange={(e) => props.onFileSelectChange(e)} + ref={props.fileRef} >