Skip to content

Commit c7a7166

Browse files
committed
Merge branch 'victor-dev' of https://github.com/victorvrv/react-rewind into victor-dev
2 parents 5a9d7d9 + 9ceb645 commit c7a7166

File tree

13 files changed

+12037
-35
lines changed

13 files changed

+12037
-35
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: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class App extends Component {
9494
});
9595
}
9696

97+
98+
9799
// functionality to change 'play' button to 'stop'
98100
setIsPlaying() {
99101
if (this.state.isPlayingIndex > this.state.data.length - 1) {
@@ -186,15 +188,23 @@ class App extends Component {
186188

187189
// time travel bar change
188190
handleBarChange(e) {
189-
const { data } = this.state;
191+
const { data, isPlayingIndex } = this.state;
190192
const { id, action, state } = data[e.target.value];
191-
193+
// forward or past
194+
const currentIsPlayingIndex = e.target.value;
195+
const forward = currentIsPlayingIndex > isPlayingIndex;
192196
this.setState({
193197
id,
194198
action,
195199
state,
196-
isPlayingIndex: parseInt(e.target.value),
200+
isPlayingIndex: parseInt(currentIsPlayingIndex),
197201
});
202+
// Displays to screen
203+
if (forward) {
204+
this.toTheFuture();
205+
} else {
206+
this.toThePast();
207+
}
198208
}
199209

200210
// function to travel to the FUTURE
@@ -204,6 +214,20 @@ class App extends Component {
204214
type: 'TIMETRAVEL',
205215
direction: 'forward',
206216
});
217+
218+
// if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
219+
220+
const { data, isPlayingIndex } = this.state;
221+
const { id, action, state } = data[isPlayingIndex + 1];
222+
this.setState(prev => ({
223+
...prev,
224+
id,
225+
action,
226+
state,
227+
isPlayingIndex: isPlayingIndex + 1,
228+
}));
229+
230+
console.log('isPlayingIndex', this.state.isPlayingIndex);
207231
}
208232

209233
// function to travel to the PAST
@@ -213,6 +237,21 @@ class App extends Component {
213237
type: 'TIMETRAVEL',
214238
direction: 'backwards',
215239
});
240+
241+
const { data, isPlayingIndex } = this.state;
242+
243+
if (isPlayingIndex === 0) {
244+
console.log('is playingIdx in toThePast is 0');
245+
} else {
246+
const { id, action, state } = data[isPlayingIndex - 1];
247+
this.setState(prev => ({
248+
...prev,
249+
id,
250+
action,
251+
state,
252+
isPlayingIndex: isPlayingIndex - 1,
253+
}));
254+
}
216255
}
217256

218257
resetApp() {
@@ -286,4 +325,4 @@ class App extends Component {
286325
}
287326
}
288327

289-
export default App;
328+
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)