Skip to content

Commit

Permalink
Merge pull request #7 from MinseoKangQ/feat/projects
Browse files Browse the repository at this point in the history
✨ 삭제 기능 추가
  • Loading branch information
MinseoKangQ authored Mar 13, 2024
2 parents c9d0304 + e7d237e commit 409841d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Body/Projects.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
}

.add-project-btn {
margin: 10px;
margin-top: 30px;
padding: 8px 16px;
background-color: #007bff;
Expand Down Expand Up @@ -90,4 +91,31 @@ table tr:nth-child(odd) {

table tr:nth-child(even) {
background-color: white;
}

.delete-project-btn {
margin: 10px;
margin-top: 30px;
padding: 8px 16px;
background-color: red;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.2s ease;
}

.delete-project-btn:hover {
background-color: darkred;
}

.projects-container .projects-table td input[type="checkbox"] {
margin-left: auto;
margin-right: auto;
display: block;
}

/* Alternatively, if you want to specifically target only the "Delete" column for any future adjustments */
.projects-container .projects-table td:last-child {
text-align: center;
}
33 changes: 32 additions & 1 deletion src/Body/Projects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Projects = ({
setProjectsTitle,
}) => {
const [newColumn, setNewColumn] = useState('');
const [selectedForDeletion, setSelectedForDeletion] = useState(new Set());

const handleAddColumn = () => {
if (newColumn && !columns.includes(newColumn)) {
Expand Down Expand Up @@ -38,6 +39,22 @@ const Projects = ({
setProjects([...projects, newProject]);
};

const handleSelectForDeletion = (index) => {
const newSet = new Set(selectedForDeletion);
if (newSet.has(index)) {
newSet.delete(index);
} else {
newSet.add(index);
}
setSelectedForDeletion(newSet);
};

const deleteSelectedProjects = () => {
const remainingProjects = projects.filter((_, index) => !selectedForDeletion.has(index));
setProjects(remainingProjects);
setSelectedForDeletion(new Set()); // Reset selection
};

return (
<div className="projects-container">
<input
Expand All @@ -59,12 +76,13 @@ const Projects = ({
Add Column
</button>
</div>
<table>
<table className="projects-table">
<thead>
<tr>
{columns.map((column, index) => (
<th key={index}>{column}</th>
))}
<th>Delete</th>
</tr>
</thead>
<tbody>
Expand All @@ -81,6 +99,13 @@ const Projects = ({
/>
</td>
))}
<td>
<input
type="checkbox"
checked={selectedForDeletion.has(index)}
onChange={() => handleSelectForDeletion(index)}
/>
</td>
</tr>
))}
</tbody>
Expand All @@ -89,6 +114,12 @@ const Projects = ({
<button className="add-project-btn" onClick={addNewProject}>
Add Project
</button>
<button
className="delete-project-btn"
onClick={deleteSelectedProjects}
>
Delete
</button>
</div>
</div>
);
Expand Down

0 comments on commit 409841d

Please sign in to comment.