diff --git a/public/images/word-group/action.svg b/public/images/word-group/actions_pd.svg similarity index 100% rename from public/images/word-group/action.svg rename to public/images/word-group/actions_pd.svg diff --git a/public/images/word-group/animals-2.svg b/public/images/word-group/animals2_pd.svg similarity index 99% rename from public/images/word-group/animals-2.svg rename to public/images/word-group/animals2_pd.svg index a218f74..1125e2b 100644 --- a/public/images/word-group/animals-2.svg +++ b/public/images/word-group/animals2_pd.svg @@ -1,41 +1,41 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/word-group/animals-3.svg b/public/images/word-group/animals3_insects_pd.svg similarity index 100% rename from public/images/word-group/animals-3.svg rename to public/images/word-group/animals3_insects_pd.svg diff --git a/public/images/word-group/animals-1.svg b/public/images/word-group/animals_common_pd.svg similarity index 100% rename from public/images/word-group/animals-1.svg rename to public/images/word-group/animals_common_pd.svg diff --git a/public/images/word-group/body.svg b/public/images/word-group/body_parts1_pd.svg similarity index 100% rename from public/images/word-group/body.svg rename to public/images/word-group/body_parts1_pd.svg diff --git a/public/images/word-group/clothes.svg b/public/images/word-group/clothes_pd.svg similarity index 100% rename from public/images/word-group/clothes.svg rename to public/images/word-group/clothes_pd.svg diff --git a/public/images/word-group/colors.svg b/public/images/word-group/colors_pd.svg similarity index 100% rename from public/images/word-group/colors.svg rename to public/images/word-group/colors_pd.svg diff --git a/public/images/word-group/food-1.svg b/public/images/word-group/food1_fruits_veggies_pd.svg similarity index 100% rename from public/images/word-group/food-1.svg rename to public/images/word-group/food1_fruits_veggies_pd.svg diff --git a/public/images/word-group/food-2.svg b/public/images/word-group/food2_pd.svg similarity index 100% rename from public/images/word-group/food-2.svg rename to public/images/word-group/food2_pd.svg diff --git a/public/images/word-group/girl.svg b/public/images/word-group/girl.svg deleted file mode 100644 index 551e911..0000000 --- a/public/images/word-group/girl.svg +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/public/images/word-group/home.svg b/public/images/word-group/home_furniture_pd.svg similarity index 100% rename from public/images/word-group/home.svg rename to public/images/word-group/home_furniture_pd.svg diff --git a/public/images/word-group/media.svg b/public/images/word-group/media_pd.svg similarity index 100% rename from public/images/word-group/media.svg rename to public/images/word-group/media_pd.svg diff --git a/public/images/word-group/emotions.svg b/public/images/word-group/needs_feeling_pd.svg similarity index 100% rename from public/images/word-group/emotions.svg rename to public/images/word-group/needs_feeling_pd.svg diff --git a/public/images/word-group/person.svg b/public/images/word-group/persons_pd.svg similarity index 100% rename from public/images/word-group/person.svg rename to public/images/word-group/persons_pd.svg diff --git a/public/images/word-group/toys.svg b/public/images/word-group/toys_and_play_pd.svg similarity index 100% rename from public/images/word-group/toys.svg rename to public/images/word-group/toys_and_play_pd.svg diff --git a/public/images/word-group/travel.svg b/public/images/word-group/transportation_pd.svg similarity index 100% rename from public/images/word-group/travel.svg rename to public/images/word-group/transportation_pd.svg diff --git a/src/components/ConfirmationCard/ConfirmationCard.js b/src/components/ConfirmationCard/ConfirmationCard.js index 130bd4c..ce8c3fa 100644 --- a/src/components/ConfirmationCard/ConfirmationCard.js +++ b/src/components/ConfirmationCard/ConfirmationCard.js @@ -10,7 +10,7 @@ function ConfirmationCard(props) { let dateString = dateComponents[1] + " " + dateComponents[2]; setTitle(dateString); } else setTitle(props.title); - }); + }, [props.confirmation, props.title]); return (
diff --git a/src/components/DatePicker/DatePicker.js b/src/components/DatePicker/DatePicker.js index 454a310..946f7d7 100644 --- a/src/components/DatePicker/DatePicker.js +++ b/src/components/DatePicker/DatePicker.js @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useState } from "react"; import Calendar from "react-calendar/dist/entry.nostyle"; import "DatePicker/DatePicker.scss"; import { withFirebase } from "utils/Firebase"; diff --git a/src/components/ExampleComponent/ExampleComponent.js b/src/components/ExampleComponent/ExampleComponent.js deleted file mode 100644 index 4b6d43e..0000000 --- a/src/components/ExampleComponent/ExampleComponent.js +++ /dev/null @@ -1,31 +0,0 @@ -import React, { useState, useEffect } from "react"; -import { withFirebase } from "utils/Firebase"; -import CreateAssignment from "../../pages/CreateAssignment/CreateAssignment"; - -// Example constants -const LAM_ADMIN_ACCOUNT = "AxtySwFjYwR0uEsyP3Ds9nO22CY2"; -const LAM_STUDENT_ACCOUNT = "Oar8wZRQ0JArkRU1VfBj"; -const FATIMA_STUDENT_ACCOUNT = "S1ewuj5tOwC7z6EGTP3e"; - -/** - * Example of how to get customLessons given an adminID - */ -const ExampleComponent = ({ firebase }) => { - const [customLessons, setCustomLessons] = useState([]); - - useEffect(() => { - firebase.getAdminCustomLessons(LAM_ADMIN_ACCOUNT).then(customLesson => { - setCustomLessons(customLesson); - }); - }, [firebase]); - - return ( -
- {customLessons[0] && ( - - )} -
- ); -}; - -export default withFirebase(ExampleComponent); diff --git a/src/components/LessonCards/LessonCard.js b/src/components/LessonCards/LessonCard.js index 3d823e0..7a1e098 100644 --- a/src/components/LessonCards/LessonCard.js +++ b/src/components/LessonCards/LessonCard.js @@ -9,7 +9,8 @@ function LessonCard(props) { let dateComponents = props.lessonDate.split(" "); let dateString = dateComponents[1] + " " + dateComponents[2]; setCardDate(dateString); - }); + }, [props]); + return (
diff --git a/src/components/LessonCardsDisplay/LessonCardsDisplay.js b/src/components/LessonCardsDisplay/LessonCardsDisplay.js index 97a6c47..9da2d98 100644 --- a/src/components/LessonCardsDisplay/LessonCardsDisplay.js +++ b/src/components/LessonCardsDisplay/LessonCardsDisplay.js @@ -1,6 +1,5 @@ import React from "react"; import "./LessonCardsDisplay.scss"; -import { Col, Row, Container } from "reactstrap"; import LessonCard from "../LessonCards/LessonCard"; function LessonCardsDisplay(props) { diff --git a/src/components/PhonicSelector/PhonicSelector.js b/src/components/PhonicSelector/PhonicSelector.js index 9bec318..ad0d2e8 100644 --- a/src/components/PhonicSelector/PhonicSelector.js +++ b/src/components/PhonicSelector/PhonicSelector.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef } from "react"; +import React, { useState, useEffect } from "react"; import phonicGroups from "utils/phonics.json"; import PhonicIcon from "../PhonicIcon/PhonicIcon"; import PhonicWordSelector from "../PhonicWordSelector/PhonicWordSelector"; @@ -46,7 +46,7 @@ function PhonicSelector(props) { } return ( -
+
{Object.keys(phonicGroups).map((key, index) => (
diff --git a/src/components/PhonicSelector/PhonicSelector.scss b/src/components/PhonicSelector/PhonicSelector.scss index 0892439..fd02b11 100644 --- a/src/components/PhonicSelector/PhonicSelector.scss +++ b/src/components/PhonicSelector/PhonicSelector.scss @@ -1,15 +1,18 @@ +@import "../../pages/Index/index.scss"; -.phonic-background { - min-height: 50vh; - background-color: #f5f5f5; - overflow: auto; +.phonic-selector { + min-height: 50vh; + background-color: $assignments-app-background-color; + overflow: auto; + + .phonic-groups-display { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: center; + } + + .phonic-icon-margin { + margin: 2vw; } -.phonic-groups-display { - display: flex; - flex-direction: row; - flex-wrap: wrap; - justify-content: center; -} -.phonic-icon-margin { - margin: 2vw; } diff --git a/src/components/PhonicWordSelector/PhonicWordSelector.js b/src/components/PhonicWordSelector/PhonicWordSelector.js index b271785..4a355eb 100644 --- a/src/components/PhonicWordSelector/PhonicWordSelector.js +++ b/src/components/PhonicWordSelector/PhonicWordSelector.js @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React from "react"; import { Button } from "reactstrap"; import "../PhonicWordSelector/PhonicWordSelector.scss"; import "../PhonicIcon/PhonicIcon.scss"; diff --git a/src/components/SectionSelector/SectionSelector.js b/src/components/SectionSelector/SectionSelector.js index c151f4f..7d14af0 100644 --- a/src/components/SectionSelector/SectionSelector.js +++ b/src/components/SectionSelector/SectionSelector.js @@ -1,7 +1,7 @@ import React, { useState, useEffect } from "react"; import { withFirebase } from "utils/Firebase"; -import { Button, Box } from "@material-ui/core/"; -import { Row, Col, Container } from "react-bootstrap"; +import { Button } from "@material-ui/core/"; +import { Row, Col } from "react-bootstrap"; import useStyles from "SectionSelector/SectionSelectorStyle.js"; function SectionSelector(props) { const classes = useStyles(); diff --git a/src/components/StudentSelector/StudentSelector.js b/src/components/StudentSelector/StudentSelector.js index ffd9400..71fc29e 100644 --- a/src/components/StudentSelector/StudentSelector.js +++ b/src/components/StudentSelector/StudentSelector.js @@ -55,6 +55,7 @@ function StudentSelector(props) { function handleClickSelectAll(deployment) { let index = deployments.indexOf(currentDeployment); let newChecked = [...studentsChecked]; + // eslint-disable-next-line array-callback-return Object.keys(deployment.deploymentAccounts).map(deploymentAccountId => { if (!chooseAll[index]) { newChecked.push(deploymentAccountId); diff --git a/src/components/StudentSelector/StudentSelector.scss b/src/components/StudentSelector/StudentSelector.scss index 518a35b..3aba2ea 100644 --- a/src/components/StudentSelector/StudentSelector.scss +++ b/src/components/StudentSelector/StudentSelector.scss @@ -5,69 +5,82 @@ width: 33vw; background-color: white; border-radius: 1vw; -} -#deployment-ddown { - height: 3.5vw; - width:33vw; - border-top-left-radius: 1vw; - border-top-right-radius: 1vw; - background-color: $assignments-font-color; - color: white; - font-family: $assignments-roboto-font; - font-weight: bold; - font-size: 1.2rem; - transition-duration: 0.3s; - &:hover { - background-color: white; - color: $assignments-font-color; + #deployment-ddown { + height: 3.5vw; + width:33vw; + border-top-left-radius: 1vw; + border-top-right-radius: 1vw; + background-color: $assignments-font-color; + color: white; + font-family: $assignments-roboto-font; + font-weight: bold; + font-size: 1.2rem; + transition-duration: 0.3s; + &:hover { + background-color: white; + color: $assignments-font-color; + } } -} -.option-ddown { - height: 2.5vw; - width:33vw; - font-family: $assignments-roboto-font; - font-weight: bold; - font-size: 1.2rem; - &:hover { - background-color: #f5f5f5; + .option-ddown { + height: 2.5vw; + width:33vw; + font-family: $assignments-roboto-font; + font-weight: bold; + font-size: 1.2rem; + &:hover { + background-color: $assignments-app-background-color; + } } + .select-all-checkbox { + padding-right: 1vw; + padding-top: 1vw; + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: flex-end; + } + .select-all-label { + color: $assignments-font-color; + font-size: 1.2rem; + font-weight: bold; + margin-top: 3%; + } + #cbox { + margin-top: 10%; + } + .select-all-margins { + margin: auto; + margin-left: 5%; + margin-right: 5%; + } + .accounts-list { + height: 24vw; + padding-left: 1vw; + margin: auto; + overflow-y: auto; + overflow-x: hidden; + } + .student-name-label { + width: 20vw; + margin-left: 1em; + margin-top: 2%; + font-weight: bold; + font-size: 1.2rem; + color: $assignments-font-color; + text-align: start; + } + + input[type='checkbox'] { + -webkit-appearance:none; + width:2rem; + height:2rem; + background:white; + border-radius:5px; + border:2px solid #555; + margin-top: 0%; + } + input[type='checkbox']:checked { + background: $assignments-light-purple; + } } -.select-all-checkbox { - padding-right: 1vw; - padding-top: 1vw; - display: flex; - flex-direction: row; - flex-wrap: wrap; - justify-content: flex-end; -} -.select-all-label { - color: $assignments-font-color; - font-size: 1.2rem; - font-weight: bold; - margin-top: 3%; -} -#cbox { - margin-top: 10%; -} -.select-all-margins { - margin: auto; - margin-left: 5%; - margin-right: 5%; -} -.accounts-list { - height: 24vw; - padding-left: 1vw; - margin: auto; - overflow-y: auto; - overflow-x: hidden; -} -.student-name-label { - width: 20vw; - margin-left: 1em; - margin-top: 2%; - font-weight: bold; - font-size: 1.2rem; - color: $assignments-font-color; - text-align: start; -} \ No newline at end of file diff --git a/src/components/WordGroupSelector/WordGroupSelector.js b/src/components/WordGroupSelector/WordGroupSelector.js index eeadab8..b3f70af 100644 --- a/src/components/WordGroupSelector/WordGroupSelector.js +++ b/src/components/WordGroupSelector/WordGroupSelector.js @@ -1,166 +1,79 @@ -import React, { useState, useEffect, useRef } from "react"; +import React, { useState, useEffect, useCallback } from "react"; import { collectedWordGroupsService } from "util/GWUtil/resource"; import "./WordGroupSelector.scss"; -import { Button, Row, Col } from "react-bootstrap"; +import { TEMPLATE_WORD_GROUPS } from "../../utils/constants"; import WordGroupIcon from "../WordGroupIcon/WordGroupIcon"; import WordSelector from "../WordSelector/WordSelector"; function WordGroupSelector(props) { - const wordKeys = useRef(null); const [wordGroups, setWordGroups] = useState({}); const [clickedName, setClickedName] = useState(""); const [clickedGroup, setClickedGroup] = useState([]); - // selectMode dictates whether WordSelector component appears and a group's words can be selected - const [selectMode, setSelectMode] = useState(false); + const [wordSelectorToggle, setWordSelectorToggle] = useState(false); + + const handleClick = useCallback( + (group, groupName) => { + setClickedGroup(group); + setClickedName(groupName); + setWordSelectorToggle(!wordSelectorToggle); + }, + [wordSelectorToggle] + ); + useEffect(() => { if ( - Object.keys(wordGroups).length == 0 || - props.assignedWordGroup == "phonics" + Object.keys(wordGroups).length === 0 || + props.assignedWordGroup === "phonics" ) { collectedWordGroupsService.all().then(function(collectedWordGroups) { - wordKeys.current = Object.keys(collectedWordGroups); - /* - key is the word group name - 0th index is the list of words in this word group - 1st index is the image corresponding with the word group - 2nd index is the index of this word group among the list of all word groups (used to keep track of color changes) - */ - setWordGroups({ - People: [ - collectedWordGroups[wordKeys.current[0]], - "images/word-group/person.svg", - 0 - ], - Action: [ - collectedWordGroups[wordKeys.current[1]], - "images/word-group/action.svg", - 1 - ], - Toys: [ - collectedWordGroups[wordKeys.current[2]], - "images/word-group/toys.svg", - 2 - ], - Colors: [ - collectedWordGroups[wordKeys.current[3]], - "images/word-group/colors.svg", - 3 - ], - Animals: [ - collectedWordGroups[wordKeys.current[4]], - "images/word-group/animals-1.svg", - 4 - ], - Transport: [ - collectedWordGroups[wordKeys.current[5]], - "images/word-group/travel.svg", - 5 - ], - "Body Parts": [ - collectedWordGroups[wordKeys.current[6]], - "images/word-group/body.svg", - 6 - ], - Clothing: [ - collectedWordGroups[wordKeys.current[7]], - "images/word-group/clothes.svg", - 7 - ], - Food: [ - collectedWordGroups[wordKeys.current[8]], - "images/word-group/food-1.svg", - 8 - ], - "More Food": [ - collectedWordGroups[wordKeys.current[9]], - "images/word-group/food-2.svg", - 9 - ], - Furniture: [ - collectedWordGroups[wordKeys.current[10]], - "images/word-group/home.svg", - 10 - ], - Emotion: [ - collectedWordGroups[wordKeys.current[11]], - "images/word-group/emotions.svg", - 11 - ], - Media: [ - collectedWordGroups[wordKeys.current[12]], - "images/word-group/media.svg", - 12 - ], - "Animals 2": [ - collectedWordGroups[wordKeys.current[13]], - "images/word-group/animals-2.svg", - 13 - ], - "Animals 3": [ - collectedWordGroups[wordKeys.current[14]], - "images/word-group/animals-3.svg", - 14 - ] + let tempWordGroups = {}; + Object.keys(collectedWordGroups).forEach(wordGroupName => { + tempWordGroups[TEMPLATE_WORD_GROUPS[wordGroupName]] = { + words: collectedWordGroups[wordGroupName], + image: "images/word-group/" + wordGroupName + ".svg" + }; }); + setWordGroups(tempWordGroups); }); } else if (props.assignedWordGroup) { setClickedName(props.assignedWordGroup); - setClickedGroup(wordGroups[props.assignedWordGroup][0]); - setSelectMode(!selectMode); - handleChangeColor(wordGroups[props.assignedWordGroup][2]); + setClickedGroup(wordGroups[props.assignedWordGroup].words); + setWordSelectorToggle(true); } }, [wordGroups]); - const [cardColored, setCardColored] = useState( - Array(wordGroups.length) - .fill() - .map((_, i) => false) - ); - function handleClick(group, groupName) { - setClickedGroup(group); - setClickedName(groupName); - setSelectMode(!selectMode); - } - function handleChangeColor(index) { - //only one colored at a time bc you can only choose one word group - let cardColoredCopy = Array(wordGroups.length) - .fill() - .map((_, i) => false); - cardColoredCopy[index] = true; - setCardColored(cardColoredCopy); - } - - function handleChangeSelectMode(selectStatus) { - setSelectMode(selectStatus); - } return ( -
+
- {Object.keys(wordGroups).map((key, index) => ( -
-
handleClick(wordGroups[key][0], key, index)}> + {Object.keys(wordGroups).map((wordGroupName, index) => ( +
+
+ handleClick(wordGroups[wordGroupName].words, wordGroupName) + } + > handleClick(wordGroups[key][0], key, index)} + name={wordGroupName} + image={wordGroups[wordGroupName].image} + colored={wordGroupName === props.selectedWordGroup} + onClick={() => + handleClick(wordGroups[wordGroupName].words, wordGroupName) + } />
))}
- {selectMode && ( + {wordSelectorToggle && ( )}
diff --git a/src/components/WordGroupSelector/WordGroupSelector.scss b/src/components/WordGroupSelector/WordGroupSelector.scss index 30c4a3d..5a963e2 100644 --- a/src/components/WordGroupSelector/WordGroupSelector.scss +++ b/src/components/WordGroupSelector/WordGroupSelector.scss @@ -1,21 +1,20 @@ @import "../../pages/Index/index.scss"; -.background { +.word-group-selector { min-height: 52vw; - background-color: #f5f5f5; + background-color: $assignments-app-background-color; margin: auto; + + .word-groups-display { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: center; + } + + .word-groups-margins { + margin-left: 2rem; + margin-right: 2rem; + margin-bottom: 1rem; + } } - -.word-groups-display { - display: flex; - flex-direction: row; - flex-wrap: wrap; - justify-content: center; -} - -.word-groups-margins { - margin-left: 2rem; - margin-right: 2rem; - margin-bottom: 1rem; -} - diff --git a/src/components/WordSelector/WordSelector.js b/src/components/WordSelector/WordSelector.js index 57e888a..b6216e8 100644 --- a/src/components/WordSelector/WordSelector.js +++ b/src/components/WordSelector/WordSelector.js @@ -4,34 +4,36 @@ import { useRef } from "react"; import useOutsideClick from "./useOutsideClick"; import "./WordSelector.scss"; +const MIN_WORD_COUNT = 4; + function WordSelector(props) { const [wordCount, updateWordCount] = useState(0); - const [minWords] = useState(4); - const [checkedWords, updateWords] = useState([]); + const [checkedWords, setCheckedWords] = useState([]); const [wordGroup, updateWordGroup] = useState(); const [chooseAll, setChooseAll] = useState(false); const [disableSelect, setDisableSelect] = useState(false); const ref = useRef(); useOutsideClick(ref, () => { - props.setSelectMode(false); + props.setWordSelectorToggle(false); }); useEffect(() => { if (props.assignedWords) { - updateWords(props.assignedWords); + setCheckedWords(props.assignedWords); updateWordCount(props.assignedWords.length); updateWordGroup(props.assignedWordGroup); - setDisableSelect(props.assignedWordGroup != props.name); + setDisableSelect(props.assignedWordGroup !== props.name); } - }, []); + }, [props.assignedWords, props.assignedWordGroup, props.name]); + function disableNext() { - return wordCount < minWords || disableSelect; + return wordCount < MIN_WORD_COUNT || disableSelect; } function handleCheck(word) { if (props.name !== wordGroup) { - updateWords([word]); + setCheckedWords([word]); updateWordCount(1); updateWordGroup(props.name); setDisableSelect(false); @@ -41,7 +43,7 @@ function WordSelector(props) { checkedWords.splice(index, 1); updateWordCount(wordCount - 1); } else { - updateWords([...checkedWords, word]); + setCheckedWords([...checkedWords, word]); updateWordCount(wordCount + 1); } } @@ -49,9 +51,8 @@ function WordSelector(props) { function handleSelect() { props.selectWords(checkedWords); - props.setSelectMode(false); - props.selectGroup(props.name); - props.changeColor(props.index); + props.setWordSelectorToggle(false); + props.selectWordGroup(props.name); } function handleChooseAll() { @@ -60,20 +61,21 @@ function WordSelector(props) { setDisableSelect(false); } if (!chooseAll) { - updateWords([...props.group]); + setCheckedWords([...props.group]); updateWordCount(props.group.length); } else { - updateWords([]); + setCheckedWords([]); updateWordCount(0); } setChooseAll(!chooseAll); } + function wordSelection(word, index) { return (
-
); } export default compose( diff --git a/src/pages/CreateAssignment/CreateAssignment.scss b/src/pages/CreateAssignment/CreateAssignment.scss index 1c35c20..3f691ff 100644 --- a/src/pages/CreateAssignment/CreateAssignment.scss +++ b/src/pages/CreateAssignment/CreateAssignment.scss @@ -1,87 +1,78 @@ @import "../../pages/Index/index.scss"; -.create_assignment { +.create-assignment { overflow: auto; -} -.assignment_creation { - position: absolute; -} -.place_middle{ - position: "absolute"; - left: "50%"; - top: "50%"; - transform: "translate(-50%, -50%)"; - position: relative; -} -.assign { - color: $assignments-font-color; - background-color: $assignments-background-color; - font-family: $assignments-roboto-font; - font-weight: bold; - font-size: 1.5vw; - border-radius: 1em; - position: "absolute"; - width: 15vw; - height: 5vw; -} + .assign { + color: $assignments-font-color; + background-color: $assignments-background-color; + font-family: $assignments-roboto-font; + font-weight: bold; + font-size: 1.5vw; + border-radius: 1em; + width: 15vw; + height: 5vw; + margin-bottom: 1vw; + } + + .header { + color: $assignments-font-color; + font-family: $assignments-roboto-font; + font-weight: bold; + font-size: 5vw; + } -.header { - color: $assignments-font-color; - font-family: $assignments-roboto-font; - font-weight: bold; - font-size: 5vw; - cursor: pointer; -} + .lesson-name { + margin-bottom: 5%; + } + + .name-assignment { + margin: auto; + width: 60vw; + margin-top: 1vw; + } + + .student-date-container { + display: flex; + flex-direction: row; + flex-wrap: wrap; + width: 90vw; + min-height: 35vw; + border-radius: 20px; + margin: auto; + margin-top: 2vw; + margin-bottom: 2vw; + justify-content: center; + } + + .input { + color: $assignments-font-color; + background-color: $assignments-background-color; + border-color: $assignments-font-color; + border-radius: 1vw; + font-family: $assignments-roboto-font; + font-weight: bold; + font-size: 1.2rem; + width: 20vw; + } + + .input-header { + color: $assignments-background-color; + background-color: $assignments-font-color; + border-color: $assignments-font-color; + border-radius: 1vw; + font-family: $assignments-roboto-font; + font-weight: bold; + font-size: 1.2rem; + } -.name-assignment { - margin: auto; - width: 60vw; - margin-top: 1vw; -} -.input { - color: $assignments-font-color; - background-color: $assignments-background-color; - border-color: $assignments-font-color; - border-radius: 1vw; - font-family: $assignments-roboto-font; - font-weight: bold; - font-size: 1.2rem; - width: 20vw; -} -.input-header { - color: $assignments-background-color; - background-color: $assignments-font-color; - border-color: $assignments-font-color; - border-radius: 1vw; - font-family: $assignments-roboto-font; - font-weight: bold; - font-size: 1.2rem; -} -.spacing { - padding: 3em; -} -.lesson-name { - margin-bottom: 5%; -} -.student-date-container { - display: flex; - flex-direction: row; - flex-wrap: wrap; - width: 90vw; - min-height: 35vw; - border-radius: 20px; - margin: auto; - margin-top: 2vw; - margin-bottom: 2vw; - justify-content: center; + .header-route-back { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: left; + padding-left: 5vw; + cursor: pointer; + } } -.header-route-back { - display: flex; - flex-direction: row; - flex-wrap: wrap; - justify-content: left; - padding-left: 5vw; - cursor: pointer; -} \ No newline at end of file diff --git a/src/pages/CustomLessonsDisplay/CustomLessonsDisplay.js b/src/pages/CustomLessonsDisplay/CustomLessonsDisplay.js index f1c9cfb..23400de 100644 --- a/src/pages/CustomLessonsDisplay/CustomLessonsDisplay.js +++ b/src/pages/CustomLessonsDisplay/CustomLessonsDisplay.js @@ -9,7 +9,6 @@ import { } from "utils/constants.js"; import "./CustomLessonsDisplay.scss"; import { compose } from "recompose"; -import { Col, Row } from "reactstrap"; import { withRouter, Redirect } from "react-router-dom"; import LessonInfoDisplay from "../../components/LessonInfoDisplay/LessonInfoDisplay"; import LessonNameDisplay from "../../components/LessonNameDisplay/LessonNameDisplay"; @@ -23,7 +22,6 @@ function CustomLessonsDisplay(props) { const [displayLessonTemplate, setDisplayTemplate] = useState(null); const [displayLessonInfo, setDisplayLessonInfo] = useState(false); const [createLessonRedirect, setCreateLessonRedirect] = useState(false); - const [confirmationRedirect, setConfirmationRedirect] = useState(false); const [deletedLesson, setDeletedLesson] = useState(false); const [nameMap, setNameMap] = useState({}); const editLessonRedirect = props?.location.state?.redirect; @@ -33,7 +31,7 @@ function CustomLessonsDisplay(props) { firebase.getAdminCustomLessons(ADMIN_ACCOUNT).then(lesson => { setAllLessons(lesson); }); - }, [editLessonRedirect, deletedLesson]); // Updates lessons when redirected to page from CreateAssignment or lesson deleted + }, [editLessonRedirect, firebase, deletedLesson]); // Updates lessons when redirected to page from CreateAssignment async function deploymentNameMap(lesson) { let deploymentAccountIds = getDeploymentAccountIdsFromLesson(lesson); @@ -137,7 +135,7 @@ function CustomLessonsDisplay(props) { {allLessons .filter( lesson => - (!filterType || lesson.lessonTemplate == filterType) && + (!filterType || lesson.lessonTemplate === filterType) && (!filterGroup || lesson.wordGroup === TEMPLATE_WORD_GROUPS[filterGroup]) ) diff --git a/src/pages/CustomLessonsDisplay/CustomLessonsDisplay.scss b/src/pages/CustomLessonsDisplay/CustomLessonsDisplay.scss index 63f882d..0109d72 100644 --- a/src/pages/CustomLessonsDisplay/CustomLessonsDisplay.scss +++ b/src/pages/CustomLessonsDisplay/CustomLessonsDisplay.scss @@ -13,7 +13,7 @@ min-height: 30vw; flex-wrap: wrap; flex-direction: row; - justify-content: start; + flex-start:start; background-color: $assignments-app-background-color; } .button-bar { @@ -21,7 +21,7 @@ display: flex; flex-direction: row; flex-wrap: wrap; - justify-content: start; + flex-start:start; } #ddown, .button { height: 4.5vw; @@ -60,7 +60,7 @@ font-family: $assignments-roboto-font; font-size: 1em; &:hover { - background-color: #f5f5f5; + background-color: $assignments-app-background-color; } &:focus { background-color: $assignments-light-purple; @@ -74,7 +74,7 @@ .icon-display { display: flex; flex-direction: row; - flex-wrap: wrap; - justify-content: start; + flex-wrap: wrap; + flex-start:start; width: 100vw; } diff --git a/src/utils/Firebase/firebase.js b/src/utils/Firebase/firebase.js index 3aebdad..b247871 100644 --- a/src/utils/Firebase/firebase.js +++ b/src/utils/Firebase/firebase.js @@ -228,97 +228,92 @@ class Firebase { else customLessonRef = customLessonRef.doc(); // TODO: needs error validation to stop function if customLesson fails - customLessonRef - .get() - .then(customLessonDoc => { - // Get existing lesson's currently assigned students - let currentAssignedDeploymentIds = []; - if (lessonDocId) { - currentAssignedDeploymentIds = getDeploymentAccountIdsFromLesson( - customLessonDoc.data() - ); - } - // Get new lesson's assigned students - let deploymentAccountIds = new Set(); - for (let assignedDeploymentIds of Object.values(dueDates)) { - assignedDeploymentIds.forEach(deploymentId => - deploymentAccountIds.add(deploymentId) - ); - } - deploymentAccountIds = Array.from(deploymentAccountIds); - - // Create or update lesson - customLessonRef - .set({ - adminAccountId: adminAccountId, - lessonTemplate: lessonTemplate, - wordGroup: wordGroup, - words: words, - dueDates: dueDates, - lessonName: lessonName - }) - .catch(error => - console.error("Error creating custom lesson: ", error) - ); - - // Push custom lesson to deployment accounts - let batch = this.db.batch(); - - // Add/update deploymentAccount references to this custom lesson - let deploymentRefs = deploymentAccountIds.map(id => - this.db.doc(`${FIREBASE_DB.DEPLOYMENT_ACCOUNTS_COL}/${id}/`) + return customLessonRef.get().then(customLessonDoc => { + // Get existing lesson's currently assigned students + let currentAssignedDeploymentIds = []; + if (lessonDocId) { + currentAssignedDeploymentIds = getDeploymentAccountIdsFromLesson( + customLessonDoc.data() + ); + } + // Get new lesson's assigned students + let deploymentAccountIds = new Set(); + for (let assignedDeploymentIds of Object.values(dueDates)) { + assignedDeploymentIds.forEach(deploymentId => + deploymentAccountIds.add(deploymentId) ); + } + deploymentAccountIds = Array.from(deploymentAccountIds); + + // Create or update lesson + customLessonRef + .set({ + adminAccountId: adminAccountId, + lessonTemplate: lessonTemplate, + wordGroup: wordGroup, + words: words, + dueDates: dueDates, + lessonName: lessonName + }) + .catch(error => console.error("Error creating custom lesson: ", error)); + + // Push custom lesson to deployment accounts + let batch = this.db.batch(); + + // Add/update deploymentAccount references to this custom lesson + let deploymentRefs = deploymentAccountIds.map(id => + this.db.doc(`${FIREBASE_DB.DEPLOYMENT_ACCOUNTS_COL}/${id}/`) + ); + + return Promise.all(deploymentRefs.map(ref => ref.get())) + .then(deploymentAccountDocs => { + for (let i = 0; i < deploymentRefs.length; i++) { + let deploymentRef = deploymentRefs[i]; + let deploymentAccountDoc = deploymentAccountDocs[i]; + + // Gets existing completed assignments + let currentCompletedDueDates = deploymentAccountDoc.data() + .customLessons?.[customLessonRef.id]; + + // Initializes/updates assignments + let completedDueDates = {}; + Object.keys(dueDates).forEach(dueDate => { + if (dueDates[dueDate].includes(deploymentRef.id)) { + completedDueDates[dueDate] = Boolean( + currentCompletedDueDates?.[dueDate] + ); + } + }); - return Promise.all(deploymentRefs.map(ref => ref.get())) - .then(deploymentAccountDocs => { - for (let i = 0; i < deploymentRefs.length; i++) { - let deploymentRef = deploymentRefs[i]; - let deploymentAccountDoc = deploymentAccountDocs[i]; - - // Gets existing completed assignments - let currentCompletedDueDates = deploymentAccountDoc.data() - .customLessons?.[customLessonRef.id]; - - // Initializes/updates assignments - let completedDueDates = {}; - Object.keys(dueDates).forEach(dueDate => { - if (dueDates[dueDate].includes(deploymentRef.id)) { - completedDueDates[dueDate] = Boolean( - currentCompletedDueDates?.[dueDate] - ); - } - }); + batch.update(deploymentRef, { + [`${FIREBASE_DB.CUSTOM_LESSONS_FIELD}.${customLessonRef.id}`]: completedDueDates + }); + } + + // Remove custom lesson for non-assigned students + for (let deploymentAccountId of currentAssignedDeploymentIds) { + if (!deploymentAccountIds.includes(deploymentAccountId)) { + let deploymentRef = this.db.doc( + `${FIREBASE_DB.DEPLOYMENT_ACCOUNTS_COL}/${deploymentAccountId}/` + ); batch.update(deploymentRef, { - [`${FIREBASE_DB.CUSTOM_LESSONS_FIELD}.${customLessonRef.id}`]: completedDueDates + [`${FIREBASE_DB.CUSTOM_LESSONS_FIELD}.${customLessonRef.id}`]: app.firestore.FieldValue.delete() }); } - - // Remove custom lesson for non-assigned students - for (let deploymentAccountId of currentAssignedDeploymentIds) { - if (!deploymentAccountIds.includes(deploymentAccountId)) { - let deploymentRef = this.db.doc( - `${FIREBASE_DB.DEPLOYMENT_ACCOUNTS_COL}/${deploymentAccountId}/` - ); - - batch.update(deploymentRef, { - [`${FIREBASE_DB.CUSTOM_LESSONS_FIELD}.${customLessonRef.id}`]: app.firestore.FieldValue.delete() - }); - } - } - }) - .then(() => - batch - .commit() - .catch(error => - console.error( - "Pushing custom lessons to deployments failed: ", - error - ) + } + }) + .then(() => + batch + .commit() + .catch(error => + console.error( + "Pushing custom lessons to deployments failed: ", + error ) - ); - }) - .catch(error => console.error("Error getting custom lesson: ", error)); + ) + ); + }); }; }