Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now the Events page is setup to use redux. #18

Open
wants to merge 1 commit into
base: hoverboard-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions scripts/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,8 @@ const sessionsActions = {
}
};

const eventsActions = {
const eventActions = {
fetchEvents: () => {
// const result = firebase.database()
// .ref(`/events`)
// .on('value', snapshot => {
// console.log(snapshot.val());
// store.dispatch({type: FETCH_EVENTS, list: snapshot.val()});
// })

const result = new Promise(resolve => {
firebase.database()
.ref('/events')
Expand All @@ -263,13 +256,14 @@ const eventsActions = {
});

result
.then(list => {
//console.log(list);
.then(events => {
events.sort((eventOne, eventTwo) => new Date(eventTwo.startDate).getDate() - new Date(eventOne.startDate).getDate());
store.dispatch({
type: FETCH_EVENTS,
list
events
});
});
return result;
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const sessionsReducer = (state = initialState.sessions, action) => {
const eventsReducer = (state = initialState.events, action) => {
switch (action.type) {
case FETCH_EVENTS:
return action.data;
return state = action.events;
default:
return state;
}
Expand Down
29 changes: 7 additions & 22 deletions src/pages/events-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</template>

<script>
class EventsPage extends Polymer.Element {
class EventsPage extends UtilsFunctions(ReduxMixin(Polymer.Element)) {
static get is() {
return 'events-page'
}
Expand All @@ -74,7 +74,8 @@
static get properties() {
return {
events: {
type: Object
type: Array,
statePath: 'events'
},
schedule: {
type: Object,
Expand All @@ -87,26 +88,10 @@
}
}

constructor() {
super();
this.fetchEvents();
}

fetchEvents() {
const result = new Promise(resolve => {
firebase.database()
.ref('/events')
.on('value', snapshot => {
resolve(snapshot.val());
})
});

result
.then(list => {
list.sort((eventOne, eventTwo) => new Date(eventTwo.startDate).getDate() - new Date(eventOne.startDate).getDate());
this.events = list;
});
}
connectedCallback() {
super.connectedCallback();
if (!this.events.length) eventActions.fetchEvents();
}
}

window.customElements.define(EventsPage.is, EventsPage);
Expand Down