Skip to content

Commit

Permalink
[FIX] 하나라도 선택 취소 시 전체 선택 버튼 선택 해제
Browse files Browse the repository at this point in the history
  • Loading branch information
eunxoo committed Feb 15, 2024
1 parent bfdce93 commit 2168096
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
25 changes: 0 additions & 25 deletions src/components/Board.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const Board = ({ pass, type, onAdd, onDelete }) => {
const postsData = (posts) => {
let filteredPosts = [];
if (posts && posts.length > 0) {
// posts가 정의되고 배열인지 확인
switch (selectTrack.value) {
case "all":
filteredPosts = posts[0];
Expand Down Expand Up @@ -130,30 +129,6 @@ const Board = ({ pass, type, onAdd, onDelete }) => {
}
};

const boardList = [];

for (let i = 1; i <= 131; i++) {
boardList.push({
id: i,
name: "김멋사",
phone: "01012345678",
num: "2345678",
track: "백엔드",
time: "2024-03-25 04:24:43",
});
}

for (let i = 131; i <= 150; i++) {
boardList.push({
id: i,
name: "김멋사",
phone: "01012345678",
num: "2345678",
track: "기획 · 디자인",
time: "2024-03-25 04:24:43",
});
}

const tracks = [
{ value: "all", label: "전체트랙" },
{ value: "pm", label: "기획 · 디자인" },
Expand Down
21 changes: 15 additions & 6 deletions src/components/Posts.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState, useEffect } from "react";
import styled from "styled-components";

const StyledInput = styled.input`
Expand Down Expand Up @@ -98,11 +98,16 @@ const Content = styled.div`
const ImageWrap = styled.div``;

const Posts = ({ list, checkedItems, setCheckedItems }) => {
const [isAllChecked, setIsAllChecked] = useState(false);

useEffect(() => {
setIsAllChecked(list.length > 0 && checkedItems.length === list.length);
}, [checkedItems, list]);

const onCheckBoxAll = (e) => {
if (e.target.checked) {
const checkedListArr = [];
list.forEach((item) => checkedListArr.push(item.joinerId));
setCheckedItems(checkedListArr);
if (!isAllChecked) {
const allItems = list.map((item) => item.joinerId);
setCheckedItems(allItems);
} else {
setCheckedItems([]);
}
Expand All @@ -128,7 +133,11 @@ const Posts = ({ list, checkedItems, setCheckedItems }) => {
<ContentWrap>
<ContentTitle>
<TableCell>
<StyledInput type="checkbox" onChange={(e) => onCheckBoxAll(e)} />
<StyledInput
type="checkbox"
onChange={onCheckBoxAll}
checked={isAllChecked}
/>
</TableCell>
<TableCell>번호</TableCell>
<TableCell>이름</TableCell>
Expand Down

0 comments on commit 2168096

Please sign in to comment.