Skip to content

Commit

Permalink
Refractor Main and Modal.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dha-stix committed Oct 3, 2022
1 parent 627729f commit c17289a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function Main({ socket }) {
const [todoList, setTodoList] = useState([]);

const [showModal, setShowModal] = useState(false);
const [comments, setComments] = useState([]);
const [selectedItemID, setSelectedItemID] = useState("");

const toggleModal = (itemId) => {
Expand Down Expand Up @@ -37,7 +36,6 @@ function Main({ socket }) {
}
fetchTodos();
socket.on("todos", (data) => setTodoList(data));
socket.on("commentsReceived", (todo) => setComments(todo.comments));
}, [socket]);

const deleteTodo = (id) => socket.emit("deleteTodo", id);
Expand Down Expand Up @@ -79,8 +77,6 @@ function Main({ socket }) {
<Modal
showModal={showModal}
setShowModal={setShowModal}
comments={comments}
setComments={setComments}
selectedItemID={selectedItemID}
socket={socket}
/>
Expand Down
14 changes: 6 additions & 8 deletions todolist-with-react-and-socketIO/client/src/components/Modal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import React, { useRef, useState } from "react";
import React, { useEffect, useRef, useState } from "react";

const Modal = ({
showModal,
setShowModal,
comments,
selectedItemID,
socket,
}) => {
const Modal = ({ showModal, setShowModal, selectedItemID, socket }) => {
const modalRef = useRef();
const [comment, setComment] = useState("");
const [comments, setComments] = useState([]);

const closeModal = (e) => {
if (modalRef.current === e.target) {
Expand All @@ -24,6 +19,9 @@ const Modal = ({
});
setComment("");
};
useEffect(() => {
socket.on("commentsReceived", (todo) => setComments(todo.comments));
}, [socket]);

return (
<div className='modal' onClick={closeModal} ref={modalRef}>
Expand Down

0 comments on commit c17289a

Please sign in to comment.