From fe255c231fcfcb541d4b6141d8e512ab83ee51fb Mon Sep 17 00:00:00 2001 From: qhahd78 Date: Thu, 24 Feb 2022 21:00:16 +0900 Subject: [PATCH] [Feat]::Reservation List control redux add #90 --- package.json | 1 + src/Components/Detail/Reservation/Step1.jsx | 28 +++++++++++---------- src/index.jsx | 5 ++-- src/module/redux/reservation.jsx | 27 ++++++++++++-------- yarn.lock | 5 ++++ 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 8e7b720..67626af 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "recoil": "^0.5.2", "recoil-persist": "^4.0.0", "redux": "^4.1.2", + "redux-devtools-extension": "^2.13.9", "redux-persist": "^6.0.0", "styled-components": "^5.3.3", "web-vitals": "^1.1.2" diff --git a/src/Components/Detail/Reservation/Step1.jsx b/src/Components/Detail/Reservation/Step1.jsx index 6ef818f..a97a0d9 100644 --- a/src/Components/Detail/Reservation/Step1.jsx +++ b/src/Components/Detail/Reservation/Step1.jsx @@ -9,7 +9,7 @@ import { ReactComponent as Id } from '../../../Assets/Icons/Id.svg'; import Colors from '../../../Assets/Colors/Colors'; import { friendsState } from '../../../Recoil/Reservation'; import Button from '../../Common/Button'; -import { addList } from '../../../module/redux/reservation'; +import { addList, clearList, delList } from '../../../module/redux/reservation'; const Container = styled.div` width: 100%; @@ -98,8 +98,11 @@ const NoneInfo = styled.p` `; const Step1 = ({ increasePageFunc }) => { + // dispatch 를 사용하여 redux 에서 값을 변경하도록 함. const dispatch = useDispatch(); - const list = useSelector(state => state.reservation); + // list 목록을 불러오는 selector + const FriendsList = useSelector(state => state.reservation); + // 입력된 사람을 저장하는 people state const [people, setpeople] = useState(''); const [Friends, setFriends] = useState([]); const [Active, setActive] = useState(true); @@ -110,16 +113,14 @@ const Step1 = ({ increasePageFunc }) => { const changeList = e => { if (e.keyCode === 13 && people) { - console.log(Friends); - setFriends([...Friends, { username: people }]); - dispatch(addList(Friends)); + dispatch(addList(people)); setpeople(''); e.target.value = ''; } }; const checkList = () => { - if (Friends.length === 0) { + if (FriendsList.length === 0) { setActive(true); } else { setActive(false); @@ -127,14 +128,15 @@ const Step1 = ({ increasePageFunc }) => { }; useEffect(() => { + // DOM 이 생성되고, 사라질 때 return 문 실행 checkList(); - }, [Friends]); + return dispatch(clearList()); + }, [FriendsList]); // 삭제 로직 const delItem = e => { - setFriends( - Friends.filter(friend => friend.username !== e.target.innerHTML), - ); + dispatch(delList(e.target.innerHTML)); + // console.log(FriendsList); }; return ( @@ -151,12 +153,12 @@ const Step1 = ({ increasePageFunc }) => { /> - {Friends.length === 0 ? ( + {FriendsList.length === 0 ? ( 현재 태그된 계정이 없습니다. ) : ( - Friends.map(tag => ( + FriendsList.map(tag => ( {tag.username} @@ -165,7 +167,7 @@ const Step1 = ({ increasePageFunc }) => {

현재 입력된 인원

-

{Friends.length} 명

+

{FriendsList.length} 명