Skip to content

Commit e0180f5

Browse files
committed
Fully implemented TS on container files
1 parent 1691672 commit e0180f5

File tree

8 files changed

+60
-50
lines changed

8 files changed

+60
-50
lines changed

src/app/components/Action.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const Action = (props: ActionProps): JSX.Element => {
6161
* @function cleanTime: Displays render times for state changes
6262
* @returns render display time in seconds in milliseconds
6363
*/
64-
const cleanTime = () => {
64+
const cleanTime = ():string => {
6565
if (!componentData || !componentData.actualDuration) {
6666
return 'NO TIME';
6767
}
@@ -87,7 +87,7 @@ const Action = (props: ActionProps): JSX.Element => {
8787
}
8888
return `+${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`;
8989
};
90-
const displayTime = cleanTime();
90+
const displayTime: string = cleanTime();
9191

9292
const optionsCursorTrueWithMargin = {
9393
followCursor: true,

src/app/components/FrontendTypes.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,37 @@ export interface BarGraphComparisonAction {
9595
series?: number;
9696
setAction: (e: boolean | string) => void;
9797
}
98+
99+
interface StateContainerProps {
100+
snapshot: Record<
101+
number,
102+
{
103+
name?: string;
104+
componentData?: Record<string, unknown>;
105+
state?: Record<string, unknown>;
106+
stateSnaphot?: Record<string, unknown>;
107+
children?: unknown[];
108+
}
109+
>;
110+
toggleActionContainer?: any;
111+
webMetrics?: object;
112+
hierarchy: Record<string, unknown>;
113+
snapshots?: [];
114+
viewIndex?: number;
115+
currLocation?: object;
116+
}
117+
118+
export interface TravelContainerProps {
119+
snapshotsLength: number;
120+
}
121+
122+
export interface Obj {
123+
stateSnapshot: {
124+
route: any;
125+
children: any[];
126+
};
127+
name: number;
128+
branch: number;
129+
index: number;
130+
children?: [];
131+
}

src/app/components/StateRoute/ComponentMap/LinkControls.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Props = {
3535
// use BFS to put all the nodes under snapShots(which is the tree node) into an array
3636
const nodeList = [];
3737

38-
const collectNodes = (node) => {
38+
const collectNodes = (node): void => {
3939
nodeList.splice(0, nodeList.length);
4040
/* We used the .splice method here to ensure that nodeList
4141
did not accumulate with page refreshes */

src/app/containers/ActionContainer.tsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import SwitchAppDropdown from '../components/SwitchApp';
88
import { emptySnapshots, changeView, changeSlider } from '../actions/actions';
99
import { useStoreContext } from '../store';
1010
import RouteDescription from '../components/RouteDescription';
11+
import { Obj } from '../components/FrontendTypes';
1112

1213
const resetSlider = () => {
1314
const slider = document.querySelector('.rc-slider-handle');
@@ -22,20 +23,11 @@ function ActionContainer(props): JSX.Element {
2223
const { toggleActionContainer, actionView, setActionView } = props;
2324
const [recordingActions, setRecordingActions] = useState(true);
2425

25-
let actionsArr = [];
26-
const hierarchyArr: any[] = [];
26+
let actionsArr: JSX.Element[] = [];
27+
const hierarchyArr: (number | {})[] = [];
2728

2829
// function to traverse state from hierarchy and also getting information on display name and component name
29-
const displayArray = (obj: {
30-
stateSnapshot: {
31-
route: any;
32-
children: any[];
33-
};
34-
name: number;
35-
branch: number;
36-
index: number;
37-
children?: [];
38-
}) => {
30+
const displayArray = (obj: Obj): void => {
3931
if (
4032
obj.stateSnapshot.children.length > 0 &&
4133
obj.stateSnapshot.children[0] &&
@@ -56,7 +48,7 @@ function ActionContainer(props): JSX.Element {
5648
hierarchyArr.push(newObj);
5749
}
5850
if (obj.children) {
59-
obj.children.forEach((element) => {
51+
obj.children.forEach((element): void => {
6052
displayArray(element);
6153
});
6254
}
@@ -67,7 +59,7 @@ function ActionContainer(props): JSX.Element {
6759
if (hierarchy) displayArray(hierarchy);
6860

6961
// handles keyboard presses, function passes an event and index of each action-component
70-
function handleOnKeyDown(e: KeyboardEvent, i: number) {
62+
function handleOnKeyDown(e: KeyboardEvent, i: number): void {
7163
let currIndex = i;
7264
// up arrow key pressed
7365
if (e.key === 'ArrowUp') {
@@ -89,7 +81,9 @@ function ActionContainer(props): JSX.Element {
8981
}
9082
}
9183
// Sort by index.
92-
hierarchyArr.sort((a, b) => a.index - b.index);
84+
85+
hierarchyArr.sort((a:Obj, b:Obj):number => a.index - b.index);
86+
9387
actionsArr = hierarchyArr.map(
9488
(snapshot: {
9589
routePath: any;
@@ -128,7 +122,7 @@ function ActionContainer(props): JSX.Element {
128122
}, [setActionView]);
129123

130124
// Function sends message to background.js which sends message to the content script
131-
const toggleRecord = () => {
125+
const toggleRecord = (): void => {
132126
port.postMessage({
133127
action: 'toggleRecord',
134128
tabId: currentTab,
@@ -142,7 +136,7 @@ function ActionContainer(props): JSX.Element {
142136
[route: string]: [];
143137
};
144138

145-
const routes = {};
139+
const routes: {} = {};
146140
for (let i = 0; i < actionsArr.length; i += 1) {
147141
if (!routes.hasOwnProperty(actionsArr[i].props.routePath)) {
148142
routes[actionsArr[i].props.routePath] = [actionsArr[i]];

src/app/containers/ButtonsContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { useStoreContext } from '../store';
1313

1414
import Tutorial from '../components/Tutorial';
1515

16-
function exportHandler(snapshots: []) {
16+
function exportHandler(snapshots: []): void {
1717
// create invisible download anchor link
18-
const fileDownload = document.createElement('a');
18+
const fileDownload:HTMLAnchorElement = document.createElement('a');
1919

2020
// set file in anchor link
2121
fileDownload.href = URL.createObjectURL(

src/app/containers/ErrorContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Loader from '../components/Loader';
55
import ErrorMsg from '../components/ErrorMsg';
66
import { useStoreContext } from '../store';
77

8-
function ErrorContainer(): any {
8+
function ErrorContainer(): JSX.Element {
99
const [store, dispatch] = useStoreContext();
1010
const { tabs, currentTitle, currentTab } = store;
1111
// hooks for error checks

src/app/containers/StateContainer.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,7 @@ import React, { useState } from 'react';
66
import { MemoryRouter as Router, Route, NavLink, Switch } from 'react-router-dom';
77
import StateRoute from '../components/StateRoute/StateRoute';
88
import DiffRoute from '../components/DiffRoute';
9-
10-
interface StateContainerProps {
11-
snapshot: Record<
12-
number,
13-
{
14-
name?: string;
15-
componentData?: Record<string, unknown>;
16-
state?: Record<string, unknown>;
17-
stateSnaphot?: Record<string, unknown>;
18-
children?: unknown[];
19-
}
20-
>;
21-
toggleActionContainer?: any;
22-
webMetrics?: object;
23-
hierarchy: Record<string, unknown>;
24-
snapshots?: [];
25-
viewIndex?: number;
26-
currLocation?: object;
27-
}
9+
import { StateContainerProps } from '../components/FrontendTypes';
2810

2911
// eslint-disable-next-line react/prop-types
3012
const StateContainer = (props: StateContainerProps): JSX.Element => {

src/app/containers/TravelContainer.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ import {
1111
resetSlider,
1212
} from '../actions/actions';
1313
import { useStoreContext } from '../store';
14+
import { TravelContainerProps } from '../components/FrontendTypes';
1415

15-
const speeds = [
16+
const speeds: {
17+
value: number;
18+
label: string;
19+
}[] = [
1620
{ value: 2000, label: '0.5x' },
1721
{ value: 1000, label: '1.0x' },
1822
{ value: 500, label: '2.0x' },
19-
];
23+
];
2024

2125
// start slider movement
2226
function play(
@@ -25,7 +29,7 @@ function play(
2529
dispatch: (a: any) => void,
2630
snapshotsLength: number,
2731
sliderIndex: number,
28-
) {
32+
): void {
2933
if (playing) {
3034
dispatch(pause());
3135
} else {
@@ -35,7 +39,7 @@ function play(
3539
dispatch(resetSlider());
3640
currentIndex = 0;
3741
}
38-
const intervalId = setInterval(() => {
42+
const intervalId: NodeJS.Timeout = setInterval(() => {
3943
if (currentIndex < snapshotsLength - 1) {
4044
dispatch(playForward());
4145
currentIndex += 1;
@@ -47,10 +51,6 @@ function play(
4751
}
4852
}
4953

50-
interface TravelContainerProps {
51-
snapshotsLength: number;
52-
}
53-
5454
function TravelContainer(props: TravelContainerProps): JSX.Element {
5555
const { snapshotsLength } = props;
5656
const [selectedSpeed, setSpeed] = useState(speeds[1]);

0 commit comments

Comments
 (0)