@@ -11,16 +11,18 @@ import FileDownloadIcon from '@mui/icons-material/FileDownload';
11
11
import FileUploadIcon from '@mui/icons-material/FileUpload' ;
12
12
import { toggleMode , importSnapshots , startReconnect } from '../slices/mainSlice' ;
13
13
import { useDispatch , useSelector } from 'react-redux' ;
14
- import StatusDot from '../components/StatusDot' ;
14
+ import StatusDot from '../components/StatusDot' ;
15
15
import LoopIcon from '@mui/icons-material/Loop' ;
16
16
import CloseIcon from '@mui/icons-material/Close' ;
17
17
import WarningIcon from '@mui/icons-material/Warning' ;
18
18
import { MainState , RootState } from '../FrontendTypes' ;
19
19
20
- function exportHandler ( snapshots : [ ] ) : void { // function that takes in our tabs[currentTab] object to be exported as a JSON file. NOTE: TypeScript needs to be updated
20
+ function exportHandler ( snapshots : [ ] ) : void {
21
+ // function that takes in our tabs[currentTab] object to be exported as a JSON file. NOTE: TypeScript needs to be updated
21
22
const fileDownload : HTMLAnchorElement = document . createElement ( 'a' ) ; // invisible HTML element that will hold our tabs[currentTab] object
22
23
23
- fileDownload . href = URL . createObjectURL ( // href is the reference to the URL object created from the Blob
24
+ fileDownload . href = URL . createObjectURL (
25
+ // href is the reference to the URL object created from the Blob
24
26
new Blob ( [ JSON . stringify ( snapshots ) ] , { type : 'application/json' } ) , // Blob obj is raw data. The tabs[currentTab] object is stringified so the Blob can access the raw data
25
27
) ;
26
28
@@ -30,15 +32,18 @@ function exportHandler(snapshots: []): void { // function that takes in our tabs
30
32
URL . revokeObjectURL ( fileDownload . href ) ; // after file is downloaded, remove the href
31
33
}
32
34
33
- function importHandler ( dispatch : ( a : unknown ) => void ) : void { // function handles the importing of a tabs[currentTab] object when the upload button is selected
35
+ function importHandler ( dispatch : ( a : unknown ) => void ) : void {
36
+ // function handles the importing of a tabs[currentTab] object when the upload button is selected
34
37
const fileUpload = document . createElement ( 'input' ) ; // invisible HTML element that will hold our uploaded tabs[currentTab] object
35
38
fileUpload . setAttribute ( 'type' , 'file' ) ; // Attributes added to HTML element
36
39
37
- fileUpload . onchange = ( e : Event ) => { // onChange is when value of HTML element is changed
40
+ fileUpload . onchange = ( e : Event ) => {
41
+ // onChange is when value of HTML element is changed
38
42
const reader = new FileReader ( ) ; // FileReader is an object that reads contents of local files in async. It can use file or blob objects
39
43
const eventFiles = e . target as HTMLInputElement ; // uploaded tabs[currentTab] object is stored as the event.target
40
-
41
- if ( eventFiles ) { // if the fileUpload element has an eventFiles
44
+
45
+ if ( eventFiles ) {
46
+ // if the fileUpload element has an eventFiles
42
47
reader . readAsText ( eventFiles . files [ 0 ] ) ; // the reader parses the file into a string and stores it within the reader object
43
48
}
44
49
@@ -51,33 +56,38 @@ function importHandler(dispatch: (a: unknown) => void): void { // function handl
51
56
fileUpload . click ( ) ; // click is a method on all HTML elements that simulates a mouse click, triggering the element's click event
52
57
}
53
58
54
-
55
59
function ButtonsContainer ( ) : JSX . Element {
56
60
const dispatch = useDispatch ( ) ;
57
- const { currentTab, tabs, currentTabInApp, connectionStatus} : MainState = useSelector ( ( state : RootState ) => state . main ) ;
58
- const { mode : { paused } } = tabs [ currentTab ] ;
61
+ const { currentTab, tabs, currentTabInApp, connectionStatus } : MainState = useSelector (
62
+ ( state : RootState ) => state . main ,
63
+ ) ;
64
+ //@ts -ignore
65
+ const {
66
+ //@ts -ignore
67
+ mode : { paused } ,
68
+ } = tabs [ currentTab ] ;
59
69
60
70
//adding a local state using useState for the reconnect button functionality
61
71
const [ reconnectDialogOpen , setReconnectDialogOpen ] = useState ( false ) ;
62
72
63
73
//logic for handling dialog box opening and closing
64
74
const handleReconnectClick = ( ) => {
65
75
setReconnectDialogOpen ( true ) ;
66
- }
76
+ } ;
67
77
68
78
const handleReconnectConfirm = ( ) => {
69
79
handleReconnectCancel ( ) ;
70
80
dispatch ( startReconnect ( ) ) ;
71
- }
81
+ } ;
72
82
73
83
const handleReconnectCancel = ( ) => {
74
84
//closing the dialog
75
85
setReconnectDialogOpen ( false ) ;
76
- }
86
+ } ;
77
87
78
88
useEffect ( ( ) => {
79
89
if ( ! connectionStatus ) setReconnectDialogOpen ( true ) ;
80
- } , [ connectionStatus ] )
90
+ } , [ connectionStatus ] ) ;
81
91
82
92
return (
83
93
< div className = 'buttons-container' >
@@ -94,22 +104,18 @@ function ButtonsContainer(): JSX.Element {
94
104
variant = 'outlined'
95
105
className = 'export-button'
96
106
type = 'button'
107
+ //@ts -ignore
97
108
onClick = { ( ) => exportHandler ( tabs [ currentTab ] ) }
98
109
>
99
110
< FileDownloadIcon sx = { { pr : 1 } } />
100
111
Download
101
112
</ Button >
102
- < Button
103
- variant = 'outlined'
104
- className = 'import-button'
105
- onClick = { ( ) => importHandler ( dispatch ) } >
113
+ < Button variant = 'outlined' className = 'import-button' onClick = { ( ) => importHandler ( dispatch ) } >
106
114
< FileUploadIcon sx = { { pr : 1 } } />
107
115
Upload
108
116
</ Button >
109
117
{ /* The component below renders a button for the tutorial walkthrough of Reactime */ }
110
- < Tutorial
111
- dispatch = { dispatch }
112
- currentTabInApp = { currentTabInApp } />
118
+ < Tutorial dispatch = { dispatch } currentTabInApp = { currentTabInApp } />
113
119
{ /* adding a button for reconnection functionality 10/5/2023 */ }
114
120
< Button
115
121
variant = 'outlined'
@@ -122,40 +128,70 @@ function ButtonsContainer(): JSX.Element {
122
128
< StatusDot status = { connectionStatus ? 'active' : 'inactive' } />
123
129
</ span >
124
130
}
125
- >
131
+ >
126
132
< LoopIcon sx = { { pr : 1 } } />
127
133
Reconnect
128
134
</ Button >
129
- < Dialog className = "dialog-pop-up" open = { reconnectDialogOpen } onClose = { handleReconnectCancel } >
130
- < div className = 'close-icon-pop-up-div' >
131
- < CloseIcon type = "button" onClick = { ( ) => handleReconnectCancel ( ) } className = 'close-icon-pop-up' />
135
+ < Dialog className = 'dialog-pop-up' open = { reconnectDialogOpen } onClose = { handleReconnectCancel } >
136
+ < div className = 'close-icon-pop-up-div' >
137
+ < CloseIcon
138
+ type = 'button'
139
+ onClick = { ( ) => handleReconnectCancel ( ) }
140
+ className = 'close-icon-pop-up'
141
+ />
132
142
</ div >
133
- < div className = " warning-header-container" >
134
- < WarningIcon className = 'warning-icon-pop-up' />
143
+ < div className = ' warning-header-container' >
144
+ < WarningIcon className = 'warning-icon-pop-up' />
135
145
< DialogTitle className = 'dialog-pop-up-header' > WARNING</ DialogTitle >
136
146
</ div >
137
147
< DialogContent className = 'dialog-pop-up-contents' >
138
- < h3 > Status: { connectionStatus ? 'Connected' : 'Disconnected' } </ h3 >
139
- { connectionStatus
140
- ? < >
141
- Reconnecting while Reactime is still connected to the application may cause unforeseen issues. Are you sure you want to proceed with the reconnection?
142
- </ >
143
- : < >
144
- Reactime has unexpectedly disconnected from your application. To continue using Reactime, please reconnect.
145
- < br />
146
- < br />
147
- WARNING: Reconnecting can sometimes cause unforeseen issues, consider downloading the data before proceeding with the reconnection, if needed.
148
- </ > }
148
+ < h3 > Status: { connectionStatus ? 'Connected' : 'Disconnected' } </ h3 >
149
+ { connectionStatus ? (
150
+ < >
151
+ Reconnecting while Reactime is still connected to the application may cause unforeseen
152
+ issues. Are you sure you want to proceed with the reconnection?
153
+ </ >
154
+ ) : (
155
+ < >
156
+ Reactime has unexpectedly disconnected from your application. To continue using
157
+ Reactime, please reconnect.
158
+ < br />
159
+ < br />
160
+ WARNING: Reconnecting can sometimes cause unforeseen issues, consider downloading the
161
+ data before proceeding with the reconnection, if needed.
162
+ </ >
163
+ ) }
149
164
</ DialogContent >
150
165
151
166
< DialogActions className = 'dialog-pop-up-actions' >
152
- < Button onClick = { ( ) => handleReconnectCancel ( ) } className = "cancel-button-pop-up" type = "button" variant = "contained" style = { { backgroundColor : '#474c55' } } >
167
+ < Button
168
+ onClick = { ( ) => handleReconnectCancel ( ) }
169
+ className = 'cancel-button-pop-up'
170
+ type = 'button'
171
+ variant = 'contained'
172
+ style = { { backgroundColor : '#474c55' } }
173
+ >
153
174
Cancel
154
175
</ Button >
155
- { ! connectionStatus && < Button onClick = { ( ) => exportHandler ( tabs [ currentTab ] ) } type = "button" className = "download-button-pop-up" variant = "contained" color = "primary" >
156
- Download
157
- </ Button > }
158
- < Button onClick = { ( ) => handleReconnectConfirm ( ) } type = "button" className = "reconnect-button-pop-up" variant = "contained" style = { { backgroundColor : '#F00008' } } >
176
+ { ! connectionStatus && (
177
+ < Button
178
+ // @ts -ignore
179
+ onClick = { ( ) => exportHandler ( tabs [ currentTab ] ) }
180
+ type = 'button'
181
+ className = 'download-button-pop-up'
182
+ variant = 'contained'
183
+ color = 'primary'
184
+ >
185
+ Download
186
+ </ Button >
187
+ ) }
188
+ < Button
189
+ onClick = { ( ) => handleReconnectConfirm ( ) }
190
+ type = 'button'
191
+ className = 'reconnect-button-pop-up'
192
+ variant = 'contained'
193
+ style = { { backgroundColor : '#F00008' } }
194
+ >
159
195
Reconnect
160
196
</ Button >
161
197
</ DialogActions >
0 commit comments