diff --git a/src/components/atoms/Action.js b/src/components/atoms/Action.js index 28ddbfc..047b953 100644 --- a/src/components/atoms/Action.js +++ b/src/components/atoms/Action.js @@ -69,7 +69,7 @@ export default function SessionAction({action, authUser, dataUser}) { setName(e.target.value)} /> setNotes(e.target.value)} multiline /> - + {'target'} setQtyTarget(e.target.value)} /> setStressTarget(e.target.value)} /> diff --git a/src/components/forms/NewActionForm.js b/src/components/forms/NewActionForm.js index 9df7745..13e8d2a 100644 --- a/src/components/forms/NewActionForm.js +++ b/src/components/forms/NewActionForm.js @@ -41,7 +41,7 @@ export default function NewActionForm({ dataUser, action, sessionId, toggleAddAc stressType: stressType, timestamp: Date.now() } - console.log(data) + console.log("data added:", data) actionsRef .add(data).then(docRef => { actionsRef.doc(docRef.id).update({ @@ -80,7 +80,7 @@ export default function NewActionForm({ dataUser, action, sessionId, toggleAddAc {/* Coach Only */} {'New Set'} - setOrderIndex(e.target.value)} /> + 0 ? orderIndex : 0} onChange={(e) => setOrderIndex(parseInt(e.target.value))} /> diff --git a/src/containers/SessionDetails.js b/src/containers/SessionDetails.js index edf3357..58cdf95 100644 --- a/src/containers/SessionDetails.js +++ b/src/containers/SessionDetails.js @@ -6,7 +6,7 @@ import { sessionDetailStyles } from '../styles/sessionStyles'; import firebase from '../firebase/config'; -export default function SessionDetails({authUser, dataUser, session, exitSession, cancelSession}) { +export default function SessionDetails({authUser, dataUser, session, exitSession, cancelSession, changeTab}) { const classes = sessionDetailStyles(); // Initialize - GET Session Actions @@ -14,25 +14,6 @@ export default function SessionDetails({authUser, dataUser, session, exitSession const actionsRef = firebase.firestore().collection('actions') const sessionsRef = firebase.firestore().collection('sessions'); - const [actions, setActions] = useState([]) - useEffect(() => { - actionsRef - .where("sessionId", "==", session.id) - .orderBy("orderIndex") - .onSnapshot( - querySnapshot => { - const sessionActions = [] - querySnapshot.forEach(doc => { - sessionActions.push(doc.data()) - }) - setActions(sessionActions) - }, - error => { - console.log(error) - } - ) - }, [session]) - // Session Functions const [sessionInProgress, setSessionInProgress] = useState(session.status) const startSession = () => { @@ -40,7 +21,7 @@ export default function SessionDetails({authUser, dataUser, session, exitSession // console.log("startSession clicked") } - const publishSession = () => { + const publishSession = (e) => { // update Session status to 'upcoming' sessionsRef.doc(session.id).update({ status: 'upcoming', @@ -52,7 +33,7 @@ export default function SessionDetails({authUser, dataUser, session, exitSession // update participant's sessions array usersRef.doc(session.participantUserId).update({ sessions: firebase.firestore.FieldValue.arrayUnion(session.id), - }) + }).then(() => changeTab(e, 0)) } const completeSession = () => { setSessionInProgress(false) @@ -65,8 +46,27 @@ export default function SessionDetails({authUser, dataUser, session, exitSession const toggleAddAction = () => { setAddingAction(!addingAction) } + const [actions, setActions] = useState([]) + useEffect(() => { + actionsRef + .where("sessionId", "==", session.id) + .orderBy("orderIndex") + .onSnapshot( + querySnapshot => { + const sessionActions = [] + querySnapshot.forEach(doc => { + sessionActions.push(doc.data()) + }) + setActions(sessionActions) + }, + error => { + console.log(error) + } + ) + }, [addingAction]) - console.log('SessionDetails, session: ', actions[actions.length-1]) + console.log("actions", actions) + // console.log('SessionDetails, session: ', actions[actions.length-1]) return ( {/* Session Info */} @@ -76,11 +76,10 @@ export default function SessionDetails({authUser, dataUser, session, exitSession {'Coach: ' + session.coachUsername} {'Participant: ' + session.participantUsername} {session.notes} - - + {session.status === "draft" && } diff --git a/src/styles/sessionStyles.js b/src/styles/sessionStyles.js index b27a3c8..c432bec 100644 --- a/src/styles/sessionStyles.js +++ b/src/styles/sessionStyles.js @@ -176,13 +176,20 @@ const sessionActionStyles = makeStyles(() => ({ actionTitle: { textAlign: 'center', }, - actionData: { + targetData: { display: 'flex', flexDirection: 'column', justifyContent: 'space-between', // alignItems: 'center', width: '20%', }, + actionData: { + display: 'flex', + flexDirection: 'column', + justifyContent: 'space-between', + // alignItems: 'center', + width: '30%', + }, actionButtons: { display: 'flex', flexDirection: 'column',