Skip to content

Commit 4b00d90

Browse files
committed
Merge branch 'dev' of https://github.com/reactrewind/react-rewind into slide
2 parents 7bd715d + 7c60cb0 commit 4b00d90

File tree

13 files changed

+12027
-37
lines changed

13 files changed

+12027
-37
lines changed

package-lock.json

Lines changed: 4586 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/components/App.jsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class App extends Component {
6060
}
6161

6262
componentDidMount() {
63-
// *******************************************************
64-
// need to impletement setState for filteredData to same value as data
65-
// this.setState({ data, filteredData: data });
66-
// *******************************************************
67-
6863
// adds listener to the effects that are gonna be sent from
6964
// our edited useReducer from the 'react' library.
7065
chrome.runtime.onConnect.addListener((portFromExtension) => {
@@ -79,11 +74,14 @@ class App extends Component {
7974
this.setState((state) => ({
8075
data: [...state.data, newData],
8176
filteredData: [...state.data, newData],
77+
isPlayingIndex: state.data.length - 1,
8278
}));
8379
});
8480
});
8581
}
8682

83+
84+
8785
// functionality to change 'play' button to 'stop'
8886
setIsPlaying() {
8987
if (this.state.isPlayingIndex > this.state.data.length - 1) {
@@ -200,6 +198,20 @@ class App extends Component {
200198
type: 'TIMETRAVEL',
201199
direction: 'forward',
202200
});
201+
202+
// if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
203+
204+
const { data, isPlayingIndex } = this.state;
205+
const { id, action, state } = data[isPlayingIndex + 1];
206+
this.setState(prev => ({
207+
...prev,
208+
id,
209+
action,
210+
state,
211+
isPlayingIndex: isPlayingIndex + 1,
212+
}));
213+
214+
console.log('isPlayingIndex', this.state.isPlayingIndex);
203215
}
204216

205217
// function to travel to the PAST
@@ -209,6 +221,21 @@ class App extends Component {
209221
type: 'TIMETRAVEL',
210222
direction: 'backwards',
211223
});
224+
225+
const { data, isPlayingIndex } = this.state;
226+
227+
if (isPlayingIndex === 0) {
228+
console.log('is playingIdx in toThePast is 0');
229+
} else {
230+
const { id, action, state } = data[isPlayingIndex - 1];
231+
this.setState(prev => ({
232+
...prev,
233+
id,
234+
action,
235+
state,
236+
isPlayingIndex: isPlayingIndex - 1,
237+
}));
238+
}
212239
}
213240

214241
render() {
@@ -265,4 +292,4 @@ class App extends Component {
265292
}
266293
}
267294

268-
export default App;
295+
export default App;
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import ReactJson from 'react-json-view';
23

34
//styled components
45
import { DetailsWrapper } from '../../../styles/Details.jsx';
@@ -8,11 +9,12 @@ export default function Actions(props) {
89
const { action } = props;
910
return (
1011
<DetailsWrapper>
11-
action:
12-
{(action && action.type) || 'select an event'}
13-
<br></br>
14-
payload:
15-
{(action && action.payload) || 'select an event'}
12+
{<ReactJson
13+
theme={'threezerotwofour'}
14+
style={{ backgroundColor: 'transparent' }}
15+
displayDataTypes={false}
16+
src={action}
17+
/> || 'select an event'}
1618
</DetailsWrapper>
1719
);
1820
}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
import React from 'react';
22
import { DetailsWrapper } from '../../../styles/Details.jsx';
3+
import ReactJson from 'react-json-view';
4+
// functionality
5+
// gets difference from previous state to new state
6+
import stateDifference from '../../stateDifference.jsx';
7+
38

49
export default function Effects(props) {
10+
console.log('state differnce in effects display IMPORT', stateDifference);
11+
const differenceOfPrevAndNextState = stateDifference([1,2,3], [2,4, 9, 11, {'wow': 1}])
512
return (
6-
<DetailsWrapper>effects display page</DetailsWrapper>
13+
<DetailsWrapper>
14+
<ReactJson
15+
theme={'threezerotwofour'}
16+
style={{ backgroundColor: 'transparent', height: '-webkit-fill-available' }}
17+
displayDataTypes={false}
18+
src={differenceOfPrevAndNextState}
19+
/>
20+
</DetailsWrapper>
21+
722
);
823
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import React from 'react';
2+
import ReactJson from 'react-json-view';
23

34
export default function EffectCard(props) {
45
// renders the data to show
5-
const { stringData } = props;
6+
const { actionState } = props;
7+
68
return (
79
<div>
8-
{ stringData || 'select an event'}
10+
<ReactJson
11+
theme={'threezerotwofour'}
12+
style={{ backgroundColor: 'transparent', height: '-webkit-fill-available' }}
13+
displayDataTypes={false}
14+
src={actionState}
15+
/>
916
</div>
1017
);
1118
}

src/app/components/DetailCards/State/StateDisplay.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import { DetailsWrapper } from '../../../styles/Details.jsx';
77
export default function State(props) {
88
// stringifying data to pass down to StateCard to display
99
const { actionState } = props;
10-
const stringData = JSON.stringify(actionState, null, '\t');
11-
1210
return (
1311
<DetailsWrapper>
14-
{<StateCard stringData={stringData} />}
12+
{<StateCard actionState={actionState} />}
1513
</DetailsWrapper>
1614
);
1715
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
function stateDifference(old, curr) {
3+
4+
if(typeof(old) === "string" && typeof(curr) === "string") {
5+
if(old === curr) return false;
6+
return curr;
7+
}
8+
else if(typeof(old) === "number" && typeof(curr) === "number") {
9+
if( old === curr) return false;
10+
return curr;
11+
}
12+
else if(typeof(old) !== typeof(curr)) {
13+
return curr;
14+
}
15+
else if(Array.isArray(old) && Array.isArray(curr)) {
16+
let newArr = [];
17+
for ( let i = 0; i < curr.length; i++){
18+
if(!old.includes(curr[i])){
19+
let result = stateDifference(old[i], curr[i])
20+
if (result) {
21+
newArr.push(result)
22+
}
23+
}
24+
}
25+
return newArr.length > 0 ? newArr : false;
26+
}
27+
else if(typeof(old) === "object" && typeof(curr) === "object") {
28+
let newObj = {}
29+
for ( let prop in curr) {
30+
result = stateDifference(old[prop], curr[prop])
31+
if (result){
32+
newObj[prop] = result
33+
}
34+
}
35+
return Object.keys(newObj).length === 0 ? false : newObj
36+
}
37+
}
38+
39+
export default stateDifference;

src/app/container/Details.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function Details(props) {
2121
action, id, actionState,
2222
} = props;
2323

24+
2425
return (
2526
<Router>
2627
<>

0 commit comments

Comments
 (0)