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

Delete Lesson Functionality #89

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
673b9f3
commiting to merge
AngelaLuo49021 Mar 24, 2020
9526100
pulled from master
AngelaLuo49021 Apr 9, 2020
8d7c20b
Merge branch 'master' of https://github.com/hack4impact-uiuc/glen-world
AngelaLuo49021 Apr 21, 2020
b4168fe
Merge branch 'master' of https://github.com/hack4impact-uiuc/glen-world
AngelaLuo49021 Apr 25, 2020
c82cbeb
added drop down for different deployments
AngelaLuo49021 Apr 27, 2020
eb6fad2
added select all button, no functionality yet
AngelaLuo49021 Apr 27, 2020
9006d79
WIP adding in student name checkboxes
AngelaLuo49021 Apr 28, 2020
9ef2a55
put the select button on the other side
AngelaLuo49021 Apr 28, 2020
93bb63a
WIP functionality of everything
AngelaLuo49021 Apr 29, 2020
bd62455
functionality of select all button is good now
AngelaLuo49021 Apr 29, 2020
06679de
Fixed the class names
AngelaLuo49021 Apr 29, 2020
77d605f
delete old component
AngelaLuo49021 Apr 29, 2020
e8ec859
fixed positioning of lesson info display in the custom lesson page
AngelaLuo49021 May 1, 2020
6f0869d
WIP calendar stuff
AngelaLuo49021 May 1, 2020
e72bf32
changes 4 kelley my daddy
AngelaLuo49021 May 1, 2020
1dee45c
Merge branch 'scrolling-student-list' of https://github.com/hack4impa…
AngelaLuo49021 May 1, 2020
19a1a33
changed the date thing so it doesn't show a day selected when its not
AngelaLuo49021 May 1, 2020
ce13418
WIP
AngelaLuo49021 May 1, 2020
fbf6bbc
made small CSS tweaks
AngelaLuo49021 May 5, 2020
ecda341
restyle lesson cards
AngelaLuo49021 May 5, 2020
27a06f3
WIP of fixing the lesson cards display
AngelaLuo49021 May 5, 2020
1e1a8a3
finally fixed the lesson cards stuff
AngelaLuo49021 May 5, 2020
b0cda0e
fixed some more suspicious CSS with phonics and stuff
AngelaLuo49021 May 6, 2020
3c0062a
fixed some stuff with the calendar and assigning the name
AngelaLuo49021 May 7, 2020
5d91020
more changes
AngelaLuo49021 May 7, 2020
d56ff8e
commit before i ruin everything lMAO
AngelaLuo49021 May 8, 2020
56fdef9
fixed janky stuff with the custom lessons page
AngelaLuo49021 May 8, 2020
61d0c10
vertically aligned names in create assignments
AngelaLuo49021 May 8, 2020
6f12d73
fixed some overlapping CSS issues
AngelaLuo49021 May 8, 2020
dccda21
more css class overlap fixes
AngelaLuo49021 May 8, 2020
ef866f3
making things tablet friendly ish
AngelaLuo49021 May 8, 2020
8620cea
more dynamic css changes
AngelaLuo49021 May 8, 2020
1e70ec8
even more css changesgit statusgit status
AngelaLuo49021 May 8, 2020
0ac2c98
some trade-offs with design for tablet friendliness
AngelaLuo49021 May 8, 2020
d7581bc
WIP of fixing phonics
AngelaLuo49021 May 8, 2020
051fd05
fixed phonic components
AngelaLuo49021 May 9, 2020
e5b3e9f
fixed all css related to create assignments
AngelaLuo49021 May 9, 2020
5a577e0
fixed button bar in custom lessons page
AngelaLuo49021 May 9, 2020
f7b2507
css name fixes
AngelaLuo49021 May 9, 2020
6cb4bed
yarn formatted
AngelaLuo49021 May 9, 2020
6ae462b
ipad mode is great for the lesson plans page now
AngelaLuo49021 May 11, 2020
4dfb608
fixed section selector stuff
AngelaLuo49021 May 12, 2020
a12eb9f
removed flex thing
AngelaLuo49021 May 12, 2020
93e7019
fixed flex thing again
AngelaLuo49021 May 12, 2020
2ea9999
small css changes 4 rebecca, btw idk how to center things :(
AngelaLuo49021 May 12, 2020
8151b73
another pointer change
AngelaLuo49021 May 12, 2020
dcc802f
kelley fixessss
AngelaLuo49021 May 12, 2020
42aa602
pointer for phonics
AngelaLuo49021 May 12, 2020
87ea524
conatiner fix??
AngelaLuo49021 May 15, 2020
ed96f65
yarn formatted
AngelaLuo49021 May 15, 2020
f67052c
frontend for deleting a lesson
AngelaLuo49021 May 15, 2020
acb6571
front-end stuffff
AngelaLuo49021 May 15, 2020
c810c2e
integrated backend endpoints
Lam7150 May 15, 2020
a26f53c
finished proper ui display
Lam7150 May 18, 2020
6f42da7
fixing merge conflicts
Lam7150 May 18, 2020
799fca3
removing handleDeleteLessonCOnfirmation
Lam7150 May 19, 2020
fac78b4
frontend fixes 4 daddy
AngelaLuo49021 May 19, 2020
65d1a4c
yarn formatted
AngelaLuo49021 May 19, 2020
fa679ce
destructuring objects
Lam7150 May 21, 2020
97c1dda
changed light
AngelaLuo49021 May 25, 2020
24698be
more changes for kelleyyy
AngelaLuo49021 May 25, 2020
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
1 change: 1 addition & 0 deletions public/images/icons/delete-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions src/components/DeleteConfirmation/DeleteConfirmation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";
import "./DeleteConfirmation.scss";

function DeleteConfirmation(props) {
const { lessonName, handleDelete, handleClose } = props;
return (
<div className="confirmation-background">
<div className="delete-note">Delete Lesson: {lessonName}?</div>
<div className="delete-lesson-button-container">
<div className="delete-confirmation-button" onClick={handleDelete}>
YES
</div>
<div
className="delete-confirmation-button"
onClick={() => handleClose(false)}
>
NO
</div>
</div>
</div>
);
}

export default DeleteConfirmation;
42 changes: 42 additions & 0 deletions src/components/DeleteConfirmation/DeleteConfirmation.scss
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
@import "../../pages/Index/index.scss";

.confirmation-background {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright bc this is frontend i'm assuming @AngelaLuo49021 wrote it correct me if i'm wrong
but to avoid clashing classnames while refactoring i decided to nest all the classes into this one because you can do that in sass, you can look at my branch (i think this is the link: #84 ) for examples

background-color: white;
border: 4px solid $assignments-font-color;
box-shadow: $assignments-box-shadow;
border-radius: 1vw;
width: 30vw;
min-height: 10vw;
margin: auto;
padding: 1vw;
position: fixed;
left: 40%;
top: 25%;

.delete-note {
font-size: 1.5rem;
color: black;
font-weight: bold;
}

.delete-lesson-button-container {
margin-top: 1vw;
display:flex;
flex-direction: row;
}

.delete-confirmation-button {
color: black;
background-color: $assignments-light-purple;
font-family: $assignments-roboto-font;
font-size: 1.5rem;
width: 6vw;
border-radius: 8px;
transition-duration: 0.3s;
font-weight: bold;
margin: auto;
cursor: pointer;
&:hover {
background-color: $assignments-light-green;
}
}
}
68 changes: 52 additions & 16 deletions src/components/LessonInfoDisplay/LessonInfoDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@ import React, { useState } from "react";
import { Col, Row } from "reactstrap";
import { compose } from "recompose";
import { withRouter, Redirect } from "react-router-dom";
import { withFirebase } from "utils/Firebase";
import { useRef } from "react";
import useOutsideClick from "../WordSelector/useOutsideClick";
import "./LessonInfoDisplay.scss";
import DeleteConfirmation from "../../components/DeleteConfirmation/DeleteConfirmation";

function LessonInfoDisplay(props) {
const {
firebase,
lesson,
template,
setDisplay,
handleDeletedLesson,
nameMap
} = props;
const [editLessonRedirect, setEditLessonRedirect] = useState(false);
const [showDelete, setShowDelete] = useState(false);
const ref = useRef();
useOutsideClick(ref, () => {
props.setDisplay(false);
if (!showDelete) {
setDisplay(false);
}
});

function toFormatDate(date) {
Expand All @@ -29,20 +42,27 @@ function LessonInfoDisplay(props) {
</div>
<div className="student-container">
{students.map(id => (
<div className="student-name">{props.nameMap[id]}</div>
<div className="student-name">{nameMap[id]}</div>
))}
</div>
</div>
</Col>
);
}

function handleDeleteLesson() {
firebase.deleteCustomLesson(lesson.id, lesson.dueDates);
handleDeletedLesson();
setShowDelete(false);
setDisplay(false);
}

if (editLessonRedirect) {
return (
<Redirect
to={{
pathname: "/createlesson",
state: { existingAssignment: props.lesson }
state: { existingAssignment: lesson }
}}
/>
);
Expand All @@ -55,42 +75,58 @@ function LessonInfoDisplay(props) {
<div className="info-display">
<div className="column">
<div className="word-group-display">
<div className="lesson-group-name">{props.template}</div>
<div className="lesson-group-name">{template}</div>
</div>
<div className="lesson-info-word-display">
<div className="grey-box">
<div className="word-group-name">
{props.lesson.wordGroup}
</div>
<div className="word-group-name">{lesson.wordGroup}</div>
</div>
<div className="words-list">
{props.lesson.words.map(word => (
{lesson.words.map(word => (
<div className="words">{word}</div>
))}
</div>
</div>
</div>

<Col className="wide-column">
<div
onClick={() => setEditLessonRedirect(true)}
className="button-container"
>
<img src="images/icons/edit-icon.svg" alt="edit" />
<div className="lesson-info-button-bar">
<div
onClick={() => setEditLessonRedirect(true)}
className="button-container"
>
<img src="images/icons/edit-icon.svg" alt="edit" />
</div>
<div
onClick={() => setShowDelete(true)}
className="button-container"
>
<img src="images/icons/delete-icon.svg" alt="delete" />
</div>
</div>
<div className="card-container">
<Row>
{Object.keys(props.lesson.dueDates).map(key => (
<div>{LessonCard(key, props.lesson.dueDates[key])}</div>
{Object.keys(lesson.dueDates).map(key => (
<div>{LessonCard(key, lesson.dueDates[key])}</div>
))}
</Row>
</div>
</Col>
</div>
</Row>
</div>
{showDelete && (
<DeleteConfirmation
lessonName={lesson.lessonName}
handleDelete={handleDeleteLesson}
handleClose={setShowDelete}
/>
)}
</div>
);
}

export default compose(withRouter)(LessonInfoDisplay);
export default compose(
withFirebase,
withRouter
)(LessonInfoDisplay);
13 changes: 9 additions & 4 deletions src/components/LessonInfoDisplay/LessonInfoDisplay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,16 @@
margin-top: 2%;
}

.button-container {
margin-right: .5vw;
margin-top: .3vw;
margin-left: 46vw;
.button-container{
cursor: pointer;
margin-right: 1vw;
margin-top: .5vw;
}

.lesson-info-button-bar {
display:flex;
flex-direction: row;
justify-content: flex-end;
}
.wide-column {
width: 60vw
Expand Down
2 changes: 1 addition & 1 deletion src/components/LessonNameDisplay/LessonNameDisplay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
background-color: white;
border: 4px solid $assignments-light-purple;
border-radius: 1em;
box-shadow: "5px 10px #888888";
box-shadow: $assignments-box-shadow;
margin: auto;
margin-top: 1vw;
overflow: hidden;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Confirmation/ConfirmationStyle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

.flex-container .cards-display-section {
display: flex;
background-color: $confirmation-light-light-grey-background-color;
background-color: $confirmation-extra-light-grey-background-color;
flex-wrap: wrap;
flex-grow: 12;
height: 100vh;
Expand Down
8 changes: 7 additions & 1 deletion src/pages/CustomLessonsDisplay/CustomLessonsDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function CustomLessonsDisplay(props) {
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;

Expand All @@ -32,7 +33,7 @@ function CustomLessonsDisplay(props) {
firebase.getAdminCustomLessons(ADMIN_ACCOUNT).then(lesson => {
setAllLessons(lesson);
});
}, [editLessonRedirect]); // Updates lessons when redirected to page from CreateAssignment
}, [editLessonRedirect, deletedLesson]); // Updates lessons when redirected to page from CreateAssignment or lesson deleted

async function deploymentNameMap(lesson) {
let deploymentAccountIds = getDeploymentAccountIdsFromLesson(lesson);
Expand All @@ -56,6 +57,10 @@ function CustomLessonsDisplay(props) {
setDisplayLessonInfo(display);
}

function handleDeletedLesson() {
setDeletedLesson(!deletedLesson);
}
Comment on lines +60 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this the fix for the lessons not updating problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! So this signals to the LessonsDisplay to recall the firebase endpoint and update the lessons displayed on the screen in useEffect()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you explain this? is the value of deletedlesson ignored and it's only used to trigger useEffect()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym the value of deletedLesson ignored?

Yeah your interpretation is right, I made this specifically just to trigger useEffect(), to signal to the parent component displaying the customLessons (customLessonsDisplay) to update the lessons. Since we're not redirecting back to the same page, I think this is the best way to do it but correct me if I'm wrong if you have a better implementation!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just meant that it doesnt matter if it's true or false because its changing updates the component
i think it should be fine, it's only a little janky


function handleClick(lesson) {
handleChangeDisplayLessonInfo(!displayLessonInfo);
setDisplayLesson(lesson);
Expand Down Expand Up @@ -152,6 +157,7 @@ function CustomLessonsDisplay(props) {
lesson={displayLesson}
template={displayLessonTemplate}
setDisplay={handleChangeDisplayLessonInfo}
handleDeletedLesson={handleDeletedLesson}
nameMap={nameMap}
/>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Index/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ $assignments-light-purple: #b1b0ff;
$assignments-light-green: #B7E3D9;
$assignments-roboto-font: "Roboto", sans-serif;
$confirmation-light-grey-background-color: #DADADA;
$confirmation-light-light-grey-background-color: #EEEEEE;
$confirmation-extra-light-grey-background-color: #EEEEEE;
$assignments-box-shadow: "5px 10px #888888";
20 changes: 20 additions & 0 deletions src/utils/Firebase/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ class Firebase {
})
.catch(error => console.error("Error getting admin account: ", error));

deleteCustomLesson = (lessonId, dueDates) => {
this.db
.collection(FIREBASE_DB.CUSTOM_LESSONS_COL)
.doc(lessonId)
.delete()
.catch(error => console.error("Error deleting doc: ", error));

let deploymentAccountIds = getDeploymentAccountIdsFromLesson({
dueDates: dueDates
});
deploymentAccountIds.forEach(deploymentAccountId => {
this.db
.collection(FIREBASE_DB.DEPLOYMENT_ACCOUNTS_COL)
.doc(deploymentAccountId)
.update({
[`${FIREBASE_DB.CUSTOM_LESSONS_FIELD}.${lessonId}`]: app.firestore.FieldValue.delete()
});
});
};

setCustomLesson = (
adminAccountId,
lessonTemplate,
Expand Down