Skip to content

Commit 5ea7847

Browse files
committed
removed reconnect dialog and replaced with hot toast notification
1 parent 998f53e commit 5ea7847

File tree

3 files changed

+32
-106
lines changed

3 files changed

+32
-106
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
"rc-tooltip": "^6.1.3",
196196
"react": "^18.2.0",
197197
"react-apexcharts": "^1.4.1",
198+
"react-hot-toast": "^2.4.1",
198199
"react-hover": "^3.0.1",
199200
"react-json-tree": "^0.18.0",
200201
"react-redux": "^9.0.4",

src/app/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { MemoryRouter as Router } from 'react-router-dom';
33
import MainContainer from './containers/MainContainer';
4+
import { Toaster } from 'react-hot-toast';
45

56
/*
67
'currentTab' is the current active tab within Google Chrome.
@@ -11,6 +12,7 @@ import MainContainer from './containers/MainContainer';
1112
function App(): JSX.Element {
1213
return (
1314
<Router>
15+
<Toaster />
1416
<MainContainer />
1517
</Router>
1618
);

src/app/containers/ButtonsContainer.tsx

Lines changed: 29 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,72 @@
11
import * as React from 'react';
2-
//importing useState from react to handle local state for button reconnect functionality
3-
import { useState, useEffect } from 'react';
42
import { Button } from '@mui/material';
5-
//importing necesary material UI components for dialogue popup
6-
import { Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material';
73
import Tutorial from '../components/Buttons/Tutorial';
84
import { toggleMode, importSnapshots, startReconnect } from '../slices/mainSlice';
95
import { useDispatch, useSelector } from 'react-redux';
106
import StatusDot from '../components/Buttons/StatusDot';
11-
import CloseIcon from '@mui/icons-material/Close';
12-
import WarningIcon from '@mui/icons-material/Warning';
137
import { MainState, RootState } from '../FrontendTypes';
148
import { Lock, Unlock, Download, Upload, RefreshCw } from 'lucide-react';
9+
import { toast } from 'react-hot-toast';
1510

1611
function exportHandler(snapshots: []): void {
17-
// function that takes in our tabs[currentTab] object to be exported as a JSON file. NOTE: TypeScript needs to be updated
18-
const fileDownload: HTMLAnchorElement = document.createElement('a'); // invisible HTML element that will hold our tabs[currentTab] object
19-
12+
const fileDownload: HTMLAnchorElement = document.createElement('a');
2013
fileDownload.href = URL.createObjectURL(
21-
// href is the reference to the URL object created from the Blob
22-
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
14+
new Blob([JSON.stringify(snapshots)], { type: 'application/json' }),
2315
);
24-
25-
fileDownload.setAttribute('download', 'snapshot.json'); // We set a download attribute with snapshots.json as the file name. This allows us to download the file when the element is 'clicked.' The file will be named snapshots.json once the file is downloaded locally
26-
fileDownload.click(); // click is a method on all HTML elements that simulates a mouse click, triggering the element's click event
27-
28-
URL.revokeObjectURL(fileDownload.href); // after file is downloaded, remove the href
16+
fileDownload.setAttribute('download', 'snapshot.json');
17+
fileDownload.click();
18+
URL.revokeObjectURL(fileDownload.href);
2919
}
3020

3121
function importHandler(dispatch: (a: unknown) => void): void {
32-
// function handles the importing of a tabs[currentTab] object when the upload button is selected
33-
const fileUpload = document.createElement('input'); // invisible HTML element that will hold our uploaded tabs[currentTab] object
34-
fileUpload.setAttribute('type', 'file'); // Attributes added to HTML element
22+
const fileUpload = document.createElement('input');
23+
fileUpload.setAttribute('type', 'file');
3524

3625
fileUpload.onchange = (e: Event) => {
37-
// onChange is when value of HTML element is changed
38-
const reader = new FileReader(); // FileReader is an object that reads contents of local files in async. It can use file or blob objects
39-
const eventFiles = e.target as HTMLInputElement; // uploaded tabs[currentTab] object is stored as the event.target
26+
const reader = new FileReader();
27+
const eventFiles = e.target as HTMLInputElement;
4028

4129
if (eventFiles) {
42-
// if the fileUpload element has an eventFiles
43-
reader.readAsText(eventFiles.files[0]); // the reader parses the file into a string and stores it within the reader object
30+
reader.readAsText(eventFiles.files[0]);
4431
}
4532

4633
reader.onload = () => {
47-
const test = reader.result.toString(); // once the local file has been loaded, result property on FileReader object returns the file's contents and then converts the file contents to a string
48-
return dispatch(importSnapshots(JSON.parse(test))); // dispatch sends the result of of converting our tabs[currentTab] object => string => JSON Object. This updates the current tab
34+
const test = reader.result.toString();
35+
return dispatch(importSnapshots(JSON.parse(test)));
4936
};
5037
};
5138

52-
fileUpload.click(); // click is a method on all HTML elements that simulates a mouse click, triggering the element's click event
39+
fileUpload.click();
5340
}
5441

5542
function ButtonsContainer(): JSX.Element {
5643
const dispatch = useDispatch();
5744
const { currentTab, tabs, currentTabInApp, connectionStatus }: MainState = useSelector(
5845
(state: RootState) => state.main,
5946
);
47+
6048
//@ts-ignore
6149
const {
6250
//@ts-ignore
6351
mode: { paused },
6452
} = tabs[currentTab];
6553

66-
//adding a local state using useState for the reconnect button functionality
67-
const [reconnectDialogOpen, setReconnectDialogOpen] = useState(false);
68-
69-
//logic for handling dialog box opening and closing
70-
const handleReconnectClick = () => {
71-
setReconnectDialogOpen(true);
72-
};
73-
74-
const handleReconnectConfirm = () => {
75-
handleReconnectCancel();
54+
const handleReconnect = () => {
7655
dispatch(startReconnect());
56+
toast.success('Successfully reconnected', {
57+
duration: 2000,
58+
position: 'top-right',
59+
style: {
60+
background: '#1f2937',
61+
color: '#fff',
62+
},
63+
iconTheme: {
64+
primary: '#14b8a6',
65+
secondary: '#fff',
66+
},
67+
});
7768
};
7869

79-
const handleReconnectCancel = () => {
80-
//closing the dialog
81-
setReconnectDialogOpen(false);
82-
};
83-
84-
useEffect(() => {
85-
if (!connectionStatus) setReconnectDialogOpen(true);
86-
}, [connectionStatus]);
87-
8870
return (
8971
<div className='buttons-container'>
9072
<div className='buttons-wrapper'>
@@ -113,14 +95,11 @@ function ButtonsContainer(): JSX.Element {
11395
<Upload className='button-icon' size={18} />
11496
Upload
11597
</Button>
116-
{/* The component below renders a button for the tutorial walkthrough of Reactime */}
11798
<Tutorial dispatch={dispatch} currentTabInApp={currentTabInApp} />
118-
{/* adding a button for reconnection functionality 10/5/2023 */}
11999
<Button
120100
className='reconnect-button'
121101
type='button'
122-
//update onClick functionality to include a popup that contains....
123-
onClick={handleReconnectClick}
102+
onClick={handleReconnect}
124103
endIcon={
125104
<span style={{ position: 'relative', display: 'flex', alignItems: 'center' }}>
126105
<StatusDot status={connectionStatus ? 'active' : 'inactive'} />
@@ -130,62 +109,6 @@ function ButtonsContainer(): JSX.Element {
130109
<RefreshCw className='button-icon' size={18} />
131110
Reconnect
132111
</Button>
133-
<Dialog
134-
className='dialog-pop-up'
135-
open={reconnectDialogOpen}
136-
onClose={handleReconnectCancel}
137-
>
138-
<div className='close-icon-pop-up-div'>
139-
<CloseIcon
140-
type='button'
141-
onClick={() => handleReconnectCancel()}
142-
className='close-icon-pop-up'
143-
/>
144-
</div>
145-
<div className='warning-header-container'>
146-
<WarningIcon className='warning-icon-pop-up' />
147-
<DialogTitle className='dialog-pop-up-header'>WARNING</DialogTitle>
148-
</div>
149-
<DialogContent className='dialog-pop-up-contents'>
150-
<h3>Status: {connectionStatus ? 'Connected' : 'Disconnected'}</h3>
151-
{connectionStatus ? (
152-
<>
153-
Reconnecting while Reactime is still connected to the application may cause
154-
unforeseen issues. Are you sure you want to proceed with the reconnection?
155-
</>
156-
) : (
157-
<>
158-
Reactime has unexpectedly disconnected from your application. To continue using
159-
Reactime, please reconnect.
160-
<br />
161-
<br />
162-
WARNING: Reconnecting can sometimes cause unforeseen issues, consider downloading
163-
the data before proceeding with the reconnection, if needed.
164-
</>
165-
)}
166-
</DialogContent>
167-
168-
<DialogActions className='dialog-pop-up-actions'>
169-
<Button
170-
onClick={() => handleReconnectCancel()}
171-
className='cancel-button-pop-up'
172-
type='button'
173-
variant='contained'
174-
style={{ backgroundColor: '#474c55' }}
175-
>
176-
Cancel
177-
</Button>
178-
<Button
179-
onClick={() => handleReconnectConfirm()}
180-
type='button'
181-
className='reconnect-button-pop-up'
182-
variant='contained'
183-
style={{ backgroundColor: '#F00008' }}
184-
>
185-
Reconnect
186-
</Button>
187-
</DialogActions>
188-
</Dialog>
189112
</div>
190113
</div>
191114
);

0 commit comments

Comments
 (0)