Skip to content

Commit

Permalink
fix: fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
xche529 committed May 28, 2024
1 parent 05af562 commit 1bb4028
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 8 deletions.
3 changes: 2 additions & 1 deletion backend/src/db/daos/groupDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Group from "../models/group";
import Scene from "../models/scene";

const getGroup = async (groupId) => {
return await Group.findById(groupId);
const group = await Group.findById(groupId);
return group;
};

const getGroupByScenarioId = async (SId) => {
Expand Down
5 changes: 1 addition & 4 deletions backend/src/db/daos/noteDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ const createNote = async (groupId, title, role, text = "") => {
*/
const deleteNote = async (noteId, groupId) => {
const note = await Note.findById(noteId);
console.log("note:", note);
console.log("groupId:", groupId);
const updateQuery = {
$pull: { [`notes.${note.role}`]: noteId },
};

// delete note from group
let res = await Group.updateOne({ _id: groupId }, updateQuery);
console.log(res);
await Group.updateOne({ _id: groupId }, updateQuery);
// delete note from note collection
await note.delete();
};
Expand Down
38 changes: 35 additions & 3 deletions frontend/src/components/Note.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function Note({ role, id, group, user, refetchGroup }) {
const [open, setOpen] = useState(false);
const [save, setSave] = useState(false);
const [isRole, setRole] = useState(false);
const [showConfirm, setShowConfirm] = useState(false);
const [date, setDate] = useState();

const checkRole = () => {
Expand Down Expand Up @@ -82,9 +83,8 @@ export default function Note({ role, id, group, user, refetchGroup }) {
setOpen(false);
};

const handleDelete = async () => {
const res = window.confirm("Are you sure you want to delete this note?");
if (!res) return;
const deleteNote = async () => {
setShowConfirm(false);
try {
await usePost("/api/note/delete", { noteId: id, groupId: group._id });
refetchGroup();
Expand All @@ -95,6 +95,10 @@ export default function Note({ role, id, group, user, refetchGroup }) {
}
};

const handleDelete = () => {
setShowConfirm(true);
};

const handleKeyPress = (e) => {
if (e.key === "Escape") {
handleClose();
Expand Down Expand Up @@ -195,6 +199,34 @@ export default function Note({ role, id, group, user, refetchGroup }) {
</button>
)}
</div>
{showConfirm && (
<div
role="button"
onKeyDown={handleKeyPress}
tabIndex={0}
className={styles.overlay}
onClick={() => setShowConfirm(false)}
>
{" "}
<div className={styles.conform}>
<p>Are you sure you want to delete this note?</p>
<button
type="button"
onClick={deleteNote}
className={styles.conformButton}
>
Yes
</button>
<button
type="button"
onClick={() => setShowConfirm(false)}
className={styles.rejectButton}
>
No
</button>
</div>
</div>
)}
</div>
</div>
)}
Expand Down
67 changes: 67 additions & 0 deletions frontend/src/styling/Note.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,70 @@
margin: 2px 0;
padding: 0;
}

.conform {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
background-color: rgb(255, 255, 255);
border: 5px solid #515151;
padding: 20px;
border-radius: 13px;
visibility: "visible";
opacity: 1;
width: 50%;
height: 50%;
flex-direction: column;
z-index: 10;
}

.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9;
}

.conformButton {
position: fixed;
bottom: 150px;
left: 50%;
transform: translate(-50%, 0);
width: 25%;
height: 40px;
border-radius: 5px;
color: rgb(0, 0, 0);
transition-duration: 0.4s;
text-align: center;
border: none;
background-color: #97d5f0;
}

.conformButton:hover {
width: 50%;
}

.rejectButton {
position: fixed;
bottom: 50px;
left: 50%;
transform: translate(-50%, 0);
width: 25%;
height: 40px;
border-radius: 5px;
color: rgb(0, 0, 0);
transition-duration: 0.4s;
text-align: center;
border: none;
background-color: #97d5f0;
}

.rejectButton:hover {
width: 50%;
}

0 comments on commit 1bb4028

Please sign in to comment.