From b85b199d133a1f191c8d42daaa7c5ab284bb986a Mon Sep 17 00:00:00 2001
From: brandon <41245867+murphybrandon@users.noreply.github.com>
Date: Fri, 1 Mar 2019 20:13:22 -0500
Subject: [PATCH] added buttons to go back and forward in time
---
src/app/components/App.jsx | 71 +++++++++++++------
.../DetailCards/Actions/ActionsDisplay.jsx | 4 +-
.../components/EventCards/EventCreator.jsx | 1 -
.../components/EventCards/EventsDisplay.jsx | 5 --
src/app/components/EventCards/TimeTravel.jsx | 12 ++--
src/app/container/Details.jsx | 4 +-
src/app/container/Events.jsx | 11 ++-
src/app/styles/Events.jsx | 9 ++-
8 files changed, 77 insertions(+), 40 deletions(-)
diff --git a/src/app/components/App.jsx b/src/app/components/App.jsx
index 101afb6..46ba406 100644
--- a/src/app/components/App.jsx
+++ b/src/app/components/App.jsx
@@ -43,7 +43,8 @@ class App extends Component {
};
this.addActionToView = this.addActionToView.bind(this);
- // this.toTheFuture = this.toTheFuture.bind(this);
+ this.toTheFuture = this.toTheFuture.bind(this);
+ this.toThePast = this.toThePast.bind(this);
}
componentDidMount() {
@@ -71,36 +72,60 @@ class App extends Component {
}
// function to travel to the FUTURE
- // **** not being passed to any children yet
- // toTheFuture(e) {
- // if (this.state.action) {
- // for (let i = 0; i < data.length - 1; i += 1) {
- // // clicking next returns next piece of data
- // if (data[i].id === this.state.id) {
- // const { action, id, payload, state } = data[i + 1];
- // this.setState({action, id, payload, state});
- // }
- // // if we're at the last action stop there
- // // don't let user go any further
- // if (data[i].id === undefined) {
- // const { action, id, payload, state } = data[data.length -1 ];
- // this.setState({action, id, payload, state});
- // }
- // }
- // }
- // }
+ toTheFuture(e) {
+ if (this.state.action) {
+ for (let i = 0; i < data.length - 1; i += 1) {
+ // clicking next returns next piece of data
+ if (data[i].id === this.state.id) {
+ const { action, id, payload, state } = data[i + 1];
+ this.setState({action, id, payload, state});
+ }
+ // if we're at the last action stop there
+ // don't let user go any further
+ if (data[i].id === undefined) {
+ const { action, id, payload, state } = data[data.length -1 ];
+ this.setState({action, id, payload, state});
+ }
+ }
+ }
+ }
+
+ // function to travel to the PAST
+ toThePast(e) {
+ if (this.state.action) {
+ for (let i = data.length - 1; i >= 0; i -= 1) {
+ // clicking next returns next piece of data
+ if (data[i].id === this.state.id) {
+ const { action, id, payload, state } = data[i - 1];
+ this.setState({action, id, payload, state});
+ }
+ // if we're at the last action stop there
+ // don't let user go any further
+ if (this.state.action === undefined) {
+ const { action, id, payload, state } = data[0];
+ this.setState({action, id, payload, state});
+ }
+ }
+ }
+ }
render() {
const {
- action, id, payload, state, data
+ action, id, payload, state, data,
} = this.state;
return (
<>
- }
+ (
+
+ )}
right={
(
);
}
-}
+ }
export default App;
\ No newline at end of file
diff --git a/src/app/components/DetailCards/Actions/ActionsDisplay.jsx b/src/app/components/DetailCards/Actions/ActionsDisplay.jsx
index 37df108..e3a4f4d 100644
--- a/src/app/components/DetailCards/Actions/ActionsDisplay.jsx
+++ b/src/app/components/DetailCards/Actions/ActionsDisplay.jsx
@@ -6,10 +6,10 @@ export default function Actions(props) {
return (
<>
action:
- {action.type || 'select an event'}
+ {(action && action.type) || 'select an event'}
payload:
- {action.payload || 'select an event'}
+ {(action && action.payload) || 'select an event'}
>
);
}
diff --git a/src/app/components/EventCards/EventCreator.jsx b/src/app/components/EventCards/EventCreator.jsx
index b673d83..39da857 100644
--- a/src/app/components/EventCards/EventCreator.jsx
+++ b/src/app/components/EventCards/EventCreator.jsx
@@ -5,7 +5,6 @@ import { EventCard, EventTimeDiv } from '../../styles/Events.jsx';
export default function EventCreator(props) {
// renders individual action
const { action, id, addAction, actionTime } = props;
- console.log(EventCard);
return (
☰ {action}
diff --git a/src/app/components/EventCards/EventsDisplay.jsx b/src/app/components/EventCards/EventsDisplay.jsx
index 3338e84..0e7e180 100644
--- a/src/app/components/EventCards/EventsDisplay.jsx
+++ b/src/app/components/EventCards/EventsDisplay.jsx
@@ -2,14 +2,10 @@ import React, { useContext, useState } from 'react';
// components import
import EventCreator from './EventCreator.jsx';
-import TimeTravel from './TimeTravel.jsx';
// styled components import
import { EventsWrapper } from '../../styles/Events.jsx';
-// data context import
-import { DataContext } from '../../index.js'
-
export default function Events(props) {
return (
@@ -22,7 +18,6 @@ export default function Events(props) {
/>
))}
{/* time travel doesn't work yet */}
-
);
}
diff --git a/src/app/components/EventCards/TimeTravel.jsx b/src/app/components/EventCards/TimeTravel.jsx
index ea85ba0..ddc5b9e 100644
--- a/src/app/components/EventCards/TimeTravel.jsx
+++ b/src/app/components/EventCards/TimeTravel.jsx
@@ -1,10 +1,14 @@
import React from 'react';
+// styled component
+import { TimeTravelContainer, EventTimeDiv } from '../../styles/Events.jsx';
+
export default function TimeTavel(props) {
+ const { toTheFuture, toThePast } = props;
return (
-
- PREVIOUS
- NEXT
-
+
+ PREVIOUS
+ NEXT
+
);
}
diff --git a/src/app/container/Details.jsx b/src/app/container/Details.jsx
index 0e1bd64..28800bb 100644
--- a/src/app/container/Details.jsx
+++ b/src/app/container/Details.jsx
@@ -19,7 +19,7 @@ export default function Details(props) {
// destructuring required info that's being passed down from App.jsx
// passing these props onto children
const {
- action, id, payload, actionState,
+ action, id, actionState,
} = props;
return (
@@ -30,7 +30,7 @@ export default function Details(props) {
{/* routing components and rendering them with props */}
}
+ render={props => }
/>
-
+
+
>
);
}
diff --git a/src/app/styles/Events.jsx b/src/app/styles/Events.jsx
index cc7600b..db4ef63 100644
--- a/src/app/styles/Events.jsx
+++ b/src/app/styles/Events.jsx
@@ -5,7 +5,7 @@ export const EventsWrapper = styled.div`
/* margin: 17px 17px; */
/* padding-top: 2%; */
/* padding-bottom: 2%; */
- height: 79%;
+ max-height: 300px;
overflow: auto;
`;
@@ -40,3 +40,10 @@ export const EventTimeDiv = styled.div`
border-radius: 5px;
/* border: 1px solid black; */
`;
+
+export const TimeTravelContainer = styled.div`
+ border-top: 1px solid white;
+ padding-top: 5%;
+ display: flex;
+ justify-content: space-evenly;
+`;