Skip to content

Commit a94612f

Browse files
committed
typescript events
1 parent e78c84d commit a94612f

File tree

7 files changed

+27
-24
lines changed

7 files changed

+27
-24
lines changed

src/app/components/Action.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,23 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { changeView, changeSlider } from '../actions/actions.ts';
44

5+
interface ActionProps {
6+
selected: boolean;
7+
last: boolean;
8+
index: number;
9+
sliderIndex: number;
10+
dispatch: () => void;
11+
displayName: string;
12+
componentName: string;
13+
componentData: {actualDuration: number};
14+
state: object;
15+
viewIndex: number;
16+
handleOnkeyDown: (e: KeyboardEvent, i: number) => void;
17+
}
18+
519
/* // gabi and nate :: index and delta props were removed from Action.jsx */
620
// viewIndex and handleonkeyDown added to props
7-
const Action = props => {
21+
const Action: React.SFC = (props: ActionProps) => {
822
const {
923
selected, last, index, sliderIndex, dispatch, displayName, componentName, componentData, state, viewIndex, handleOnkeyDown,
1024
} = props;
@@ -41,7 +55,7 @@ const Action = props => {
4155
return (
4256
<div
4357
// Edwin: invoking keyboard functionality; functionality is in ActionContainer;
44-
onKeyDown={e => handleOnkeyDown(e, viewIndex)}
58+
onKeyDown={(e: KeyboardEvent) => handleOnkeyDown(e, viewIndex)}
4559
className={selected || last ? 'action-component selected' : 'action-component'}
4660
onClick={() => {
4761
dispatch(changeView(index));
@@ -61,7 +75,7 @@ const Action = props => {
6175
</button>
6276
<button
6377
className="jump-button"
64-
onClick={e => {
78+
onClick={(e: MouseEvent) => {
6579
e.stopPropagation();
6680
dispatch(changeSlider(index));
6781
dispatch(changeView(index));
@@ -74,17 +88,5 @@ const Action = props => {
7488
</div>
7589
);
7690
};
77-
// gabi and nate :: added displayName, componentName and State props to propTypes
78-
Action.propTypes = {
79-
sliderIndex: PropTypes.number.isRequired,
80-
selected: PropTypes.bool.isRequired,
81-
index: PropTypes.number.isRequired,
82-
dispatch: PropTypes.func.isRequired,
83-
displayName: PropTypes.string.isRequired,
84-
componentName: PropTypes.string.isRequired,
85-
state: PropTypes.object.isRequired,
86-
handleOnkeyDown: PropTypes.func.isRequired,
87-
viewIndex: PropTypes.number.isRequired,
88-
};
8991

9092
export default Action;

src/app/components/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useReducer } from 'react';
22
import MainContainer from '../containers/MainContainer.tsx';
33
import { StoreContext } from '../store.tsx';
4-
import mainReducer from '../reducers/mainReducer.tsx';
4+
import mainReducer from '../reducers/mainReducer.ts';
55

66
const initialState = {
77
port: null,
File renamed without changes.

src/app/containers/ActionContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function ActionContainer() {
4141
if (hierarchy) displayArray(hierarchy);
4242

4343
// Edwin: handles keyboard presses, function passes an event and index of each action-component
44-
function handleOnKeyDown(e, i) {
44+
function handleOnKeyDown(e:KeyboardEvent, i:number) {
4545
let currIndex = i;
4646
// up array key pressed
4747
if (e.keyCode === 38) {
@@ -89,7 +89,7 @@ function ActionContainer() {
8989
<div className="action-component exclude">
9090
<button
9191
className="empty-button"
92-
onClick={() => {
92+
onClick={(e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
9393
dispatch(emptySnapshots());
9494
// set slider back to zero
9595
resetSlider();

src/app/containers/ButtonsContainer.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ function ButtonsContainer() {
4242

4343
return (
4444
<div className="buttons-container">
45-
<button className="pause-button" type="button" onClick={() => dispatch(toggleMode('paused'))}>
45+
<button className="pause-button" type="button" onClick={(e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => dispatch(toggleMode('paused'))}>
4646
{paused ? 'Resume' : 'Pause'}
4747
</button>
48-
<button className="lock-button" type="button" onClick={() => dispatch(toggleMode('locked'))}>
48+
<button className="lock-button" type="button" onClick={(e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => dispatch(toggleMode('locked'))}>
4949
{locked ? 'Unlock' : 'Lock'}
5050
</button>
5151
<button
5252
className="persist-button"
5353
type="button"
54-
onClick={() => dispatch(toggleMode('persist'))}
54+
onClick={(e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => dispatch(toggleMode('persist'))}
5555
>
5656
{persist ? 'Unpersist' : 'Persist'}
5757
</button>
58-
<button className="export-button" type="button" onClick={() => exportHandler(snapshots)}>
58+
<button className="export-button" type="button" onClick={(e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => exportHandler(snapshots)}>
5959
Export
6060
</button>
61-
<button className="import-button" type="button" onClick={() => importHandler(dispatch)}>
61+
<button className="import-button" type="button" onClick={(e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => importHandler(dispatch)}>
6262
Import
6363
</button>
6464
</div>

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const ChromeExtensionReloader = require('webpack-chrome-extension-reloader'); //
44
const config = {
55
// use a "multi-main entry" to inject multiple dependent files together and graph their dependencies into one "chunk"
66
entry: {
7-
app: './src/app/index.js',
7+
// app: './src/app/index.js',
8+
app: './src/app/index.tsx',
89
background: './src/extension/background.js',
910
content: './src/extension/contentScript.js',
1011
backend: './dev-reactime/index.js',

0 commit comments

Comments
 (0)