Skip to content

Commit 5efc4f3

Browse files
Christopher StamperChristopher Stamper
authored andcommitted
Finished increasing typescript coverage, fixed formatting
1 parent c6cc4ad commit 5efc4f3

File tree

5 files changed

+113
-63
lines changed

5 files changed

+113
-63
lines changed

src/app/components/Action.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const Action = (props: ActionProps): JSX.Element => {
9999
return (
100100
<div className='individual-action'>
101101
<div
102+
// @ts-ignore
102103
onKeyDown={(e): void => handleOnkeyDown(e, viewIndex)}
103104
className={selected || last ? 'action-component selected' : 'action-component'}
104105
onClick={() => {

src/app/components/MainSlider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function MainSlider(props: MainSliderProps): JSX.Element {
3636
useEffect(() => {
3737
if (currLocation) {
3838
// if we have a 'currLocation'
39+
//@ts-ignore
3940
setSliderIndex(currLocation.index); // set our slider thumb position to the 'currLocation.index'
4041
} else {
4142
setSliderIndex(0); // just set the thumb position to the beginning

src/app/containers/ButtonsContainer.tsx

Lines changed: 79 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ import FileDownloadIcon from '@mui/icons-material/FileDownload';
1111
import FileUploadIcon from '@mui/icons-material/FileUpload';
1212
import { toggleMode, importSnapshots, startReconnect } from '../slices/mainSlice';
1313
import { useDispatch, useSelector } from 'react-redux';
14-
import StatusDot from '../components/StatusDot';
14+
import StatusDot from '../components/StatusDot';
1515
import LoopIcon from '@mui/icons-material/Loop';
1616
import CloseIcon from '@mui/icons-material/Close';
1717
import WarningIcon from '@mui/icons-material/Warning';
1818
import { MainState, RootState } from '../FrontendTypes';
1919

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
2122
const fileDownload: HTMLAnchorElement = document.createElement('a'); // invisible HTML element that will hold our tabs[currentTab] object
2223

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
2426
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
2527
);
2628

@@ -30,15 +32,18 @@ function exportHandler(snapshots: []): void { // function that takes in our tabs
3032
URL.revokeObjectURL(fileDownload.href); // after file is downloaded, remove the href
3133
}
3234

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
3437
const fileUpload = document.createElement('input'); // invisible HTML element that will hold our uploaded tabs[currentTab] object
3538
fileUpload.setAttribute('type', 'file'); // Attributes added to HTML element
3639

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
3842
const reader = new FileReader(); // FileReader is an object that reads contents of local files in async. It can use file or blob objects
3943
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
4247
reader.readAsText(eventFiles.files[0]); // the reader parses the file into a string and stores it within the reader object
4348
}
4449

@@ -51,33 +56,38 @@ function importHandler(dispatch: (a: unknown) => void): void { // function handl
5156
fileUpload.click(); // click is a method on all HTML elements that simulates a mouse click, triggering the element's click event
5257
}
5358

54-
5559
function ButtonsContainer(): JSX.Element {
5660
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];
5969

6070
//adding a local state using useState for the reconnect button functionality
6171
const [reconnectDialogOpen, setReconnectDialogOpen] = useState(false);
6272

6373
//logic for handling dialog box opening and closing
6474
const handleReconnectClick = () => {
6575
setReconnectDialogOpen(true);
66-
}
76+
};
6777

6878
const handleReconnectConfirm = () => {
6979
handleReconnectCancel();
7080
dispatch(startReconnect());
71-
}
81+
};
7282

7383
const handleReconnectCancel = () => {
7484
//closing the dialog
7585
setReconnectDialogOpen(false);
76-
}
86+
};
7787

7888
useEffect(() => {
7989
if (!connectionStatus) setReconnectDialogOpen(true);
80-
}, [connectionStatus])
90+
}, [connectionStatus]);
8191

8292
return (
8393
<div className='buttons-container'>
@@ -94,22 +104,18 @@ function ButtonsContainer(): JSX.Element {
94104
variant='outlined'
95105
className='export-button'
96106
type='button'
107+
//@ts-ignore
97108
onClick={() => exportHandler(tabs[currentTab])}
98109
>
99110
<FileDownloadIcon sx={{ pr: 1 }} />
100111
Download
101112
</Button>
102-
<Button
103-
variant='outlined'
104-
className='import-button'
105-
onClick={() => importHandler(dispatch)}>
113+
<Button variant='outlined' className='import-button' onClick={() => importHandler(dispatch)}>
106114
<FileUploadIcon sx={{ pr: 1 }} />
107115
Upload
108116
</Button>
109117
{/* 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} />
113119
{/* adding a button for reconnection functionality 10/5/2023 */}
114120
<Button
115121
variant='outlined'
@@ -122,40 +128,70 @@ function ButtonsContainer(): JSX.Element {
122128
<StatusDot status={connectionStatus ? 'active' : 'inactive'} />
123129
</span>
124130
}
125-
>
131+
>
126132
<LoopIcon sx={{ pr: 1 }} />
127133
Reconnect
128134
</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+
/>
132142
</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' />
135145
<DialogTitle className='dialog-pop-up-header'>WARNING</DialogTitle>
136146
</div>
137147
<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+
)}
149164
</DialogContent>
150165

151166
<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+
>
153174
Cancel
154175
</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+
>
159195
Reconnect
160196
</Button>
161197
</DialogActions>

src/app/containers/MainContainer.tsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import { MainState, RootState } from '../FrontendTypes';
2626
function MainContainer(): JSX.Element {
2727
const dispatch = useDispatch();
2828

29-
const { currentTab , tabs, port }: MainState = useSelector((state: RootState) => state.main);
30-
29+
const { currentTab, tabs, port }: MainState = useSelector((state: RootState) => state.main);
30+
3131
const [actionView, setActionView] = useState(true); // We create a local state 'actionView' and set it to true
3232

3333
// this function handles Time Jump sidebar view
@@ -39,7 +39,8 @@ function MainContainer(): JSX.Element {
3939

4040
const recordBtn = document.getElementById('recordBtn');
4141

42-
if (recordBtn.style.display === 'none') { // switches whether to display the record toggle button by changing the display property between none and flex
42+
if (recordBtn.style.display === 'none') {
43+
// switches whether to display the record toggle button by changing the display property between none and flex
4344
recordBtn.style.display = 'flex';
4445
} else {
4546
recordBtn.style.display = 'none';
@@ -48,23 +49,23 @@ function MainContainer(): JSX.Element {
4849

4950
// Function handles when Reactime unexpectedly disconnects
5051
const handleDisconnect = (msg): void => {
51-
if (msg === 'portDisconnect')
52-
dispatch(disconnected());
53-
}
52+
if (msg === 'portDisconnect') dispatch(disconnected());
53+
};
5454

5555
// Function to listen for a message containing snapshots from the /extension/build/background.js service worker
56-
const messageListener = (message: {
57-
action: string;
58-
payload: Record<string, unknown>;
59-
sourceTab: number
56+
const messageListener = (message: {
57+
action: string;
58+
payload: Record<string, unknown>;
59+
sourceTab: number;
6060
}) => {
6161
const { action, payload, sourceTab } = message;
6262
let maxTab: number;
6363

64-
if (!sourceTab && action !== 'keepAlive') { // if the sourceTab doesn't exist or is 0 and it is not a 'keepAlive' action
64+
if (!sourceTab && action !== 'keepAlive') {
65+
// if the sourceTab doesn't exist or is 0 and it is not a 'keepAlive' action
6566
const tabsArray: Array<string> = Object.keys(payload); // we create a tabsArray of strings composed of keys from our payload object
6667
const numTabsArray: number[] = tabsArray.map((tab) => Number(tab)); // we then map out our tabsArray where we convert each string into a number
67-
68+
6869
maxTab = Math.max(...numTabsArray); // we then get the largest tab number value
6970
}
7071

@@ -97,28 +98,28 @@ function MainContainer(): JSX.Element {
9798
}
9899
default:
99100
}
100-
}
101+
};
101102

102103
useEffect(() => {
103104
if (port) return; // only open port once so if it exists, do not run useEffect again
104-
105+
105106
// Connect ot port and assign evaluated result (obj) to currentPort
106107
const currentPort = chrome.runtime.connect();
107-
108+
108109
// If messageListener exists on currentPort, remove it
109110
while (currentPort.onMessage.hasListener(messageListener))
110111
currentPort.onMessage.removeListener(messageListener);
111-
112+
112113
// Add messageListener to the currentPort
113114
currentPort.onMessage.addListener(messageListener);
114-
115+
115116
// If handleDisconnect exists on chrome.runtime, remove it
116117
while (chrome.runtime.onMessage.hasListener(handleDisconnect))
117118
chrome.runtime.onMessage.removeListener(handleDisconnect);
118-
119+
119120
// add handleDisconnect to chrome.runtime
120121
chrome.runtime.onMessage.addListener(handleDisconnect);
121-
122+
122123
// assign port to state so it could be used by other components
123124
dispatch(setPort(currentPort));
124125

@@ -128,13 +129,17 @@ function MainContainer(): JSX.Element {
128129
// Error Page launch IF(Content script not launched OR RDT not installed OR Target not React app)
129130
if (
130131
!tabs[currentTab] ||
132+
//@ts-ignore
131133
!tabs[currentTab].status.reactDevToolsInstalled ||
134+
//@ts-ignore
132135
!tabs[currentTab].status.targetPageisaReactApp
133136
) {
134137
return <ErrorContainer />;
135138
}
136139

137-
const { currLocation, viewIndex, sliderIndex, snapshots, hierarchy, webMetrics } = tabs[currentTab]; // we destructure the currentTab object
140+
const { currLocation, viewIndex, sliderIndex, snapshots, hierarchy, webMetrics } =
141+
tabs[currentTab]; // we destructure the currentTab object
142+
//@ts-ignore
138143
const snapshotView = viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex]; // if viewIndex is -1, then use the sliderIndex instead
139144

140145
// cleaning hierarchy and snapshotView from stateless data
@@ -182,18 +187,24 @@ function MainContainer(): JSX.Element {
182187
setActionView={setActionView}
183188
toggleActionContainer={toggleActionContainer}
184189
/>
190+
{/* @ts-ignore */}
185191
{snapshots.length ? (
186192
<div className='state-container-container'>
187193
<StateContainer
194+
// @ts-ignore
188195
webMetrics={webMetrics}
196+
// @ts-ignore
189197
viewIndex={viewIndex}
190198
snapshot={snapshotDisplay}
191199
hierarchy={hierarchyDisplay}
200+
// @ts-ignore
192201
snapshots={snapshots}
202+
// @ts-ignore
193203
currLocation={currLocation}
194204
/>
195205
</div>
196206
) : null}
207+
{/* @ts-ignore */}
197208
<TravelContainer snapshotsLength={snapshots.length} />
198209
<ButtonsContainer />
199210
</div>

src/app/containers/TravelContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function TravelContainer(props: TravelContainerProps): JSX.Element {
8080
// data-testid, prop for testing in RTL
8181
data-testid='play-button-test'
8282
//REMOVED DISPATCH FROM PLAY
83+
// @ts-ignore
8384
onClick={() => play(selectedSpeed.value, playing, dispatch, snapshotsLength, sliderIndex)}
8485
>
8586
{playing ? 'Pause' : 'Play'}

0 commit comments

Comments
 (0)