Skip to content

Commit 94b7ef3

Browse files
committed
all containers and reducer converted to typescript
1 parent 313e322 commit 94b7ef3

File tree

6 files changed

+26
-34
lines changed

6 files changed

+26
-34
lines changed

src/app/components/Diff.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import ReactHtmlParser from 'react-html-parser';
44
import { useStoreContext } from '../store.tsx';
55

66
interface DiffProps {
7-
snapshot: {state:object | string};
8-
show?: boolean;
7+
snapshot: {state:object|string};
8+
show?: boolean|undefined;
99
}
1010

1111
function Diff(props: DiffProps) {
@@ -23,7 +23,7 @@ function Diff(props: DiffProps) {
2323
}
2424

2525
// gabi :: cleanning preview from stateless data
26-
const statelessCleanning = (obj:{name?:string; componentData?:object; state?: object | string;stateSnaphot?:object; children?:[]}) => {
26+
const statelessCleanning = (obj:{name?:string; componentData?:object; state?:object|string;stateSnaphot?:object; children?:[]}) => {
2727
const newObj = { ...obj };
2828
if (newObj.name === 'nameless') {
2929
delete newObj.name;

src/app/containers/ActionContainer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ function ActionContainer() {
1717
const { hierarchy, sliderIndex, viewIndex } = tabs[currentTab];
1818
console.log(tabs[currentTab])
1919
let actionsArr = [];
20-
const hierarchyArr = [];
20+
const hierarchyArr:[] = [];
2121

2222
// gabi and nate :: delete function to traverse state from snapshots, now we are tranversing state from hiararchy and alsog getting infromation on display name and component name
23-
const displayArray = obj => {
23+
const displayArray = (obj:{stateSnapshot:{children:[]}, name:number, branch:number, index:number, children?:[]}) => {
2424
if (obj.stateSnapshot.children.length > 0 && obj.stateSnapshot.children[0] && obj.stateSnapshot.children[0].state && obj.stateSnapshot.children[0].name) {
25-
const newObj = {
25+
const newObj:object = {
2626
index: obj.index,
2727
displayName: `${obj.name}.${obj.branch}`,
2828
state: obj.stateSnapshot.children[0].state,
@@ -63,7 +63,7 @@ function ActionContainer() {
6363
}
6464
}
6565

66-
actionsArr = hierarchyArr.map((snapshot, index) => {
66+
actionsArr = hierarchyArr.map((snapshot:{state:object|string, displayName:string, componentName:string, componentData:object|undefined}, index) => {
6767
const selected = index === viewIndex;
6868
const last = viewIndex === -1 && index === hierarchyArr.length - 1;
6969
return (

src/app/containers/ButtonsContainer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { importSnapshots, toggleMode } from '../actions/actions.ts';
44
import { useStoreContext } from '../store.tsx';
55

6-
function exportHandler(snapshots) {
6+
function exportHandler(snapshots:[]) {
77
// create invisible download anchor link
88
const fileDownload = document.createElement('a');
99

@@ -20,11 +20,11 @@ function exportHandler(snapshots) {
2020
URL.revokeObjectURL(fileDownload.href);
2121
}
2222

23-
function importHandler(dispatch) {
23+
function importHandler(dispatch:(a:()=>void)=>void) {
2424
const fileUpload = document.createElement('input');
2525
fileUpload.setAttribute('type', 'file');
2626

27-
fileUpload.onchange = event => {
27+
fileUpload.onchange = (event:{target:{files:[]}}) => {
2828
const reader = new FileReader();
2929
reader.onload = () => dispatch(importSnapshots(JSON.parse(reader.result)));
3030
reader.readAsText(event.target.files[0]);

src/app/containers/MainContainer.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import ActionContainer from './ActionContainer.tsx';
44
import StateContainer from './StateContainer.tsx';
55
import TravelContainer from './TravelContainer.tsx';
66
import ButtonsContainer from './ButtonsContainer.tsx';
7-
87
import {
98
addNewSnapshots, initialConnect, setPort, setTab, deleteTab,
109
} from '../actions/actions.ts';
@@ -22,7 +21,7 @@ function MainContainer() {
2221
const port = chrome.runtime.connect();
2322

2423
// listen for a message containing snapshots from the background script
25-
port.onMessage.addListener(message => {
24+
port.onMessage.addListener((message:{action:string, payload:object, sourceTab:number}) => {
2625
const { action, payload, sourceTab } = message;
2726
let maxTab;
2827
if (!sourceTab) {
@@ -85,17 +84,15 @@ function MainContainer() {
8584
// if viewIndex is -1, then use the sliderIndex instead
8685
const snapshotView = viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex];
8786
// gabi :: cleannign hierarchy and snapshotView from stateless data
88-
const statelessCleanning = obj => {
87+
const statelessCleanning = (obj:{name?:string; componentData?:object; state?:object|string;stateSnaphot?:object; children?:[]}) => {
8988
const newObj = { ...obj };
9089
if (newObj.name === 'nameless') {
9190
delete newObj.name;
9291
}
9392
if (newObj.componentData) {
9493
delete newObj.componentData;
9594
}
96-
if (newObj.parent || newObj.parent === null) {
97-
delete newObj.parent;
98-
}
95+
9996
if (newObj.state === 'stateless') {
10097
delete newObj.state;
10198
}
@@ -105,7 +102,7 @@ function MainContainer() {
105102
if (newObj.children) {
106103
newObj.children = [];
107104
if (obj.children.length > 0) {
108-
obj.children.forEach(element => {
105+
obj.children.forEach((element:{state:object|string, children?:[]}) => {
109106
if (element.state !== 'stateless' || element.children.length > 0) {
110107
const clean = statelessCleanning(element);
111108
newObj.children.push(clean);

src/app/containers/StateContainer.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useState } from 'react';
2-
import PropTypes from 'prop-types';
32
import {
43
MemoryRouter as Router,
54
Route,
@@ -9,13 +8,16 @@ import {
98
import StateRoute from '../components/StateRoute.tsx';
109
import DiffRoute from '../components/DiffRoute.tsx';
1110

11+
interface StateContainerProps {
12+
snapshot:{state?:object|string, children?:[]};
13+
hierarchy:object;
14+
snapshots:[];
15+
viewIndex:number;
16+
}
17+
1218
// eslint-disable-next-line react/prop-types
13-
const StateContainer = ({
14-
snapshot,
15-
hierarchy,
16-
snapshots,
17-
viewIndex,
18-
}) => {
19+
const StateContainer = (props:StateContainerProps) => {
20+
const { snapshot, hierarchy, snapshots, viewIndex } = props
1921
const [Text, setText] = useState('State');
2022
return (
2123
<Router>
@@ -61,11 +63,4 @@ const StateContainer = ({
6163
);
6264
};
6365

64-
StateContainer.propTypes = {
65-
snapshot: PropTypes.shape({
66-
state: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
67-
children: PropTypes.arrayOf(PropTypes.object),
68-
}).isRequired,
69-
};
70-
7166
export default StateContainer;

src/app/reducers/mainReducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import produce from 'immer';
33
import * as types from '../constants/actionTypes.ts';
44

55

6-
export default (state, action) => produce(state, draft => {
6+
export default (state:object, action:{type:string, payload:any}) => produce((state:object, draft:{port:any, currentTab:any, tabs:object }) => {
77
const { port, currentTab, tabs } = draft;
88
const {
99
hierarchy,
@@ -16,12 +16,12 @@ export default (state, action) => produce(state, draft => {
1616

1717

1818
// gabi and nate :: function that find the index in the hierarchy and extract the name of the equivalent index to add to the post message
19-
const findName = (index, hierarchy) => {
19+
const findName = (index:number, hierarchy:{index:number, name:number, children:[]}) => {
2020
if (hierarchy.index == index) {
2121
return hierarchy.name;
2222
}
2323

24-
const hierarchyChildArray = [];
24+
const hierarchyChildArray:[] = [];
2525
for (const hierarchyChild of hierarchy.children) {
2626
hierarchyChildArray.push(findName(index, hierarchyChild));
2727
}

0 commit comments

Comments
 (0)