|
1 | 1 | import * as React from 'react'; |
| 2 | +//importing useState from react to handle local state for button reconnect functionality |
| 3 | +import { useState } from 'react'; |
2 | 4 | // import { importSnapshots, toggleMode } from '../actions/actions'; |
3 | 5 | // import { useStoreContext } from '../store'; |
4 | 6 | import { Button } from '@mui/material'; |
| 7 | +//importing necesary material UI components for dialogue popup |
| 8 | +import { Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material'; |
5 | 9 | import Tutorial from '../components/Tutorial'; |
6 | 10 | import LockIcon from '@mui/icons-material/Lock'; |
7 | 11 | import LockOpenIcon from '@mui/icons-material/LockOpen'; |
8 | 12 | import FileDownloadIcon from '@mui/icons-material/FileDownload'; |
9 | 13 | import FileUploadIcon from '@mui/icons-material/FileUpload'; |
10 | | -import { toggleMode, importSnapshots } from '../RTKslices'; |
| 14 | +import { toggleMode, importSnapshots, startReconnect } from '../RTKslices'; |
11 | 15 | import { useDispatch, useSelector } from 'react-redux'; |
| 16 | +import StatusDot from '../components/StatusDot'; |
12 | 17 |
|
13 | 18 | 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 |
14 | 19 | const fileDownload: HTMLAnchorElement = document.createElement('a'); // invisible HTML element that will hold our tabs[currentTab] object |
@@ -44,15 +49,35 @@ function importHandler(dispatch: (a: unknown) => void): void { // function handl |
44 | 49 | fileUpload.click(); // click is a method on all HTML elements that simulates a mouse click, triggering the element's click event |
45 | 50 | } |
46 | 51 |
|
| 52 | + |
47 | 53 | function ButtonsContainer(): JSX.Element { |
48 | 54 | // const [{ tabs, currentTab, currentTabInApp }, dispatch] = useStoreContext(); |
49 | 55 | // const [state, dispatch] = useStoreContext(); |
50 | 56 | const dispatch = useDispatch(); |
51 | 57 | const currentTab = useSelector((state: any) => state.main.currentTab); |
52 | 58 | const tabs = useSelector((state: any)=>state.main.tabs); |
53 | 59 | const currentTabInApp = useSelector((state: any)=> state.main.currentTabInApp); |
| 60 | + const connectionStatus = useSelector((state: any)=> state.main.connectionStatus); |
54 | 61 | const { mode: { paused }} = tabs[currentTab]; |
55 | | - |
| 62 | + //adding a local state using useState for the reconnect button functionality |
| 63 | + const [reconnectDialogOpen, setReconnectDialogOpen] = useState(false); |
| 64 | + |
| 65 | + //logic for handling dialog box opening and closing |
| 66 | + const handleReconnectClick = () => { |
| 67 | + connectionStatus ? setReconnectDialogOpen(true) : dispatch(startReconnect()); |
| 68 | + } |
| 69 | + |
| 70 | + const handleReconnectConfirm = () => { |
| 71 | + //reconnection logic here |
| 72 | + dispatch(startReconnect()); |
| 73 | + setReconnectDialogOpen(false); |
| 74 | + } |
| 75 | + |
| 76 | + const handleReconnectCancel = () => { |
| 77 | + //closing the dialog |
| 78 | + setReconnectDialogOpen(false); |
| 79 | + } |
| 80 | + |
56 | 81 | return ( |
57 | 82 | <div className='buttons-container'> |
58 | 83 | <Button |
@@ -82,6 +107,35 @@ function ButtonsContainer(): JSX.Element { |
82 | 107 | //commented out so we can use useDispatch in Tutorial.tsx |
83 | 108 | dispatch={dispatch} |
84 | 109 | currentTabInApp={currentTabInApp} /> |
| 110 | + {/* adding a button for reconnection functionality 10/5/2023 */} |
| 111 | + <Button |
| 112 | + variant='outlined' |
| 113 | + className='reconnect-button' |
| 114 | + type='button' |
| 115 | + //update onClick functionality to include a popup that contains.... |
| 116 | + onClick={handleReconnectClick} |
| 117 | + endIcon={ |
| 118 | + <span style={{ position: 'relative', display: 'flex', alignItems: 'center' }}> |
| 119 | + <StatusDot status={connectionStatus ? 'active' : 'inactive'} /> |
| 120 | + </span> |
| 121 | + } |
| 122 | + > |
| 123 | + Reconnect |
| 124 | + </Button> |
| 125 | + <Dialog open={reconnectDialogOpen} onClose={handleReconnectCancel}> |
| 126 | + <DialogTitle>Reconnect Confirmation</DialogTitle> |
| 127 | + <DialogContent> |
| 128 | + {/* //insert info here on current connection status */} |
| 129 | + </DialogContent> |
| 130 | + <DialogActions> |
| 131 | + <Button onClick={handleReconnectCancel} color="primary"> |
| 132 | + Cancel |
| 133 | + </Button> |
| 134 | + <Button onClick={handleReconnectConfirm} color="primary"> |
| 135 | + Confirm Reconnect |
| 136 | + </Button> |
| 137 | + </DialogActions> |
| 138 | + </Dialog> |
85 | 139 | </div> |
86 | 140 | ); |
87 | 141 | } |
|
0 commit comments