1
- import React , { useState , useEffect , useRef } from 'react' ;
1
+ import React , { useState , useEffect , useRef } from 'react' ;
2
2
import { Box , Stack , Backdrop } from '@mui/material' ;
3
3
import MessageBox from './MessageBox' ;
4
4
import BoxHeader from './BoxHeader' ;
5
5
import InputField from './InputField' ;
6
6
import { testMessages } from '../utils/TestDatas' ;
7
7
import MessageParser from '../utils/MessageParser' ;
8
- import { ToastContainer , toast } from 'react-toastify' ;
9
- import { parseExcelTableToJson , getExcelTableNames } from '../utils/ExcelParser' ;
10
- import { toastOptins } from '../utils/ToastConfig' ;
8
+ import { ToastContainer } from 'react-toastify' ;
11
9
import type { ExcelTableData } from './ExcelTable' ;
10
+ import ExcelParserContainer from './ExcelParserContainer' ;
12
11
13
12
export default function App ( ) {
14
13
const [ waitingResponse , setWaitingResponse ] = useState ( false ) ;
15
14
const [ messages , setMessages ] = useState ( testMessages ) ;
16
15
const [ excelTableData , setExcelTableData ] = useState < ExcelTableData | null > ( null ) ;
17
- const [ readable , setReadable ] = useState ( true ) ;
18
-
19
- const messageEndRef = useRef < HTMLDivElement > ( null ) ;
20
- const backDropOpen = ! readable ;
21
-
22
- // Handle fisrt time loads and parse excel tables
23
- useEffect ( ( ) => {
24
- Office . onReady ( ( ) => {
25
- getExcelTableNames ( ) . then ( ( tableNames ) => {
26
- parseExcelTableToJson ( tableNames [ 0 ] ) . then ( ( excelTable ) => {
27
- setExcelTableData ( excelTable ) ;
28
- } ) . catch ( ( ) => {
29
- setReadable ( false ) ;
30
- } )
31
- } )
32
- } ) ;
33
- } , [ ] ) ;
34
16
35
17
// Handle user input
36
18
function handleSend ( message : string ) {
@@ -47,47 +29,15 @@ export default function App() {
47
29
} , 1000 ) ;
48
30
}
49
31
50
- // Handle auto scroll of message box
51
- useEffect ( ( ) => {
52
- if ( messageEndRef . current ) {
53
- // The "block" property should be set to "end", while default value is "start" causing unexpected behavior
54
- messageEndRef . current . scrollIntoView ( { behavior : 'smooth' , block : "end" } ) ;
55
- }
56
- } , [ messages ] ) ;
57
-
58
- // Handle notifying excel tables read result
59
- useEffect ( ( ) => {
60
- if ( ! readable ) {
61
- toast . error ( 'Can not read the table, reopen one that available' , {
62
- ...toastOptins ,
63
- position : 'top-center' ,
64
- autoClose : false ,
65
- closeButton : false ,
66
- hideProgressBar : true ,
67
- draggable : false ,
68
- theme : 'dark' ,
69
- closeOnClick : false ,
70
- } ) ;
71
- }
72
- else {
73
- toast . success ( 'Tables Finded' , toastOptins ) ;
74
- }
75
- } , [ readable ] )
76
-
77
32
return (
78
33
< Stack className = 'h-screen' >
79
34
< BoxHeader waitingResponse = { waitingResponse } />
80
35
< Box className = ' overflow-y-scroll flex-grow' >
81
36
< MessageBox messages = { messages } />
82
- < div ref = { messageEndRef } > </ div >
83
37
</ Box >
84
38
< InputField onSend = { handleSend } waitingResponse = { waitingResponse } />
85
39
< ToastContainer />
86
- < Backdrop
87
- sx = { ( theme ) => ( { color : '#fff' , zIndex : theme . zIndex . drawer + 1 } ) }
88
- open = { backDropOpen }
89
- >
90
- </ Backdrop >
40
+ < ExcelParserContainer setExcelTableData = { setExcelTableData } />
91
41
</ Stack >
92
42
) ;
93
43
}
0 commit comments