From 84e15b866786854073feefce2392b47a3d84d724 Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Thu, 26 Jul 2018 23:37:41 -0400 Subject: Created styling and backend for users to sign up for competitions. --- src/actions/firebase.js | 62 ++++++++++++++- src/components/button-shared-styles.js | 12 +++ src/components/competition-element.js | 38 +++++++++- src/components/mao-competitions.js | 134 ++++++++++++++++++++++++--------- src/components/test-element.js | 84 +++++++++++++++++++++ src/reducers/firebase.js | 12 ++- 6 files changed, 299 insertions(+), 43 deletions(-) create mode 100644 src/components/test-element.js (limited to 'src') diff --git a/src/actions/firebase.js b/src/actions/firebase.js index 85ebe20..fe3ddb0 100644 --- a/src/actions/firebase.js +++ b/src/actions/firebase.js @@ -21,6 +21,7 @@ export const signIn = (_email, _password) => (dispatch) => { */ dispatch(authSuccess(user)); dispatch(getHours()) + dispatch(pullRegisteredCompetitions()); }) .catch((error) => { dispatch(authFail(error.code)); @@ -64,8 +65,8 @@ export const authSignOut = () => { //End Firebase Auth //Start Firebase Firestore -export const GET_HOURS = 'GET_HOURS'; -export const UPDATE_HOURS = 'UPDATE_HOURS' +export const GET_HOURS = 'GET_HOURS'; +export const UPDATE_HOURS = 'UPDATE_HOURS'; export const getHours = () => (dispatch, getState) => { const currentState = getState().firebase; @@ -87,4 +88,61 @@ export const updateHours = (hours) => { } } +export const REGISTER_COMP = 'REGISTER_COMP'; +export const PULL_REGISTERED_COMPETITIONS = 'PULL_REGISTERED_COMPETITIONS'; +export const UPDATE_REGISTERED_COMPETITIONS = 'UPDATE_REGISTERED_COMPETITIONS'; + +export const registerComp = (compName) => (dispatch, getState) => { + var docRef = firestore.collection('competitions').doc(compName); + var uid = getState().firebase.uid; + + docRef.get().then((doc) => { + if(doc.exists) { + var uidArr = doc.data().uids; + + uidArr.push(uid); + + docRef.set({ + uids: uidArr + }); + + dispatch(pullRegisteredCompetitions()); + } else { + docRef.set({ + uids : [uid] + }).then(() => { + dispatch(pullRegisteredCompetitions()); + }); + } + }); +} + +export const pullRegisteredCompetitions = () => (dispatch, getState) =>{ + var registeredComps = []; + + var docRef = firestore.collection('competitions'); + docRef.get().then((query) => { + query.forEach((doc) => { + if(doc.data().uids.includes(getState().firebase.uid)) { + registeredComps.push(doc.id); + } + }) + }); + + dispatch(updateRegisteredCompetitions(registeredComps)); +} + + + + +export const updateRegisteredCompetitions = (registeredComps) => { + return { + type: UPDATE_REGISTERED_COMPETITIONS, + payload: registeredComps + } +} + + + + //End Firebase Firestore diff --git a/src/components/button-shared-styles.js b/src/components/button-shared-styles.js index 2f167e4..5f426a4 100644 --- a/src/components/button-shared-styles.js +++ b/src/components/button-shared-styles.js @@ -22,5 +22,17 @@ export const ButtonSharedStyles = html` button:hover svg { fill: var(--app-primary-color); } + + paper-button { + text-align: center; + } + + paper-button.info { + background-color: #c9eaff; + } + + paper-button.success { + background-color: #b7e1cd; + } `; diff --git a/src/components/competition-element.js b/src/components/competition-element.js index 072f654..17381c9 100644 --- a/src/components/competition-element.js +++ b/src/components/competition-element.js @@ -10,12 +10,17 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN import { LitElement, html } from '@polymer/lit-element'; +// Import button styles +import { ButtonSharedStyles } from './button-shared-styles.js'; + // Import paper elements import '@polymer/paper-card/paper-card.js'; class CompetitionElement extends LitElement { _render(props) { return html` + ${ButtonSharedStyles} + + +
+

${props.information}

+
+
+ + + +
+
+ `; + } + + static get properties() { return { + name: String, + information: String, + image: String, + initialized: Boolean, + isRegistered: Boolean + }}; + + constructor() { + super(); + + this.name = "Competition"; + this.information = "Competition Information"; + this.image = "Image Path"; + this.initialized = false; + this.isRegistered = false; + } + + registerComp() { + this.dispatchEvent(new CustomEvent('register-comp')); + this.isRegistered = true; + } + + +} + +window.customElements.define('test-element', TestElement); diff --git a/src/reducers/firebase.js b/src/reducers/firebase.js index 6f02c69..4b0ed9a 100644 --- a/src/reducers/firebase.js +++ b/src/reducers/firebase.js @@ -12,11 +12,12 @@ import { AUTH_FAIL, AUTH_SUCCESS, AUTH_SIGN_OUT, - UPDATE_HOURS + UPDATE_HOURS, + UPDATE_REGISTERED_COMPETITIONS } from '../actions/firebase.js'; -const firebase = (state = {initialized: false, authMessage: "", hours: -1, uid: null}, action) => { +const firebase = (state = {initialized: false, authMessage: "", hours: -1, uid: null, registeredComps: []}, action) => { switch (action.type) { case AUTH_SUCCESS: return { @@ -49,6 +50,13 @@ const firebase = (state = {initialized: false, authMessage: "", hours: -1, uid: } break; + case UPDATE_REGISTERED_COMPETITIONS: + return { + ...state, + registeredComps : action.payload + } + break; + default: return state; } -- cgit v1.2.3-70-g09d2