Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4주차] 정희수 미션 제출합니다. #16

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/pages/Friends/FriendItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function FriendItem({id,name,src,number}:FriendItemProps){
</StyledItem>
<hr/>
<StyledFont>
친구 {number}
친구 {number-1}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오옷 친구 수도 추가하셨네용..!!

</StyledFont>
<br/>
</>
Expand Down
22 changes: 22 additions & 0 deletions src/pages/Friends/Friends.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@ import {useRecoilState,useRecoilValue,} from 'recoil';
import { userState } from '../../recoil/atom';
import Header from '../../components/Header';
import FriendItem from './FriendItem';
import Search from './Search';
import styled from "styled-components"

const Friends = () => {
const [user, setUser] = useRecoilState<Object[]>(userState);
const [search, setSearch] = useState(0);

const onClick = () => {
if(search === 0){
setSearch(1);
}else{
setSearch(0);
}
}

return (
<StyledBlock>
<Header/>
<StyledContent>
친구
<StyledButton onClick={onClick}>🔍</StyledButton>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const [search, setSearch] = useState(false);
<StyledButton onClick={() => setSearch((prev) => !prev)}>

이렇게 해주면 onClick 함수를 따로 작성하지 않고 구현할 수 있을 것 같습니다.!

{
search === 0 ?
<Search/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 주절주절 한파일에 다 작성했는데 .. Search 컴포넌트를 따로 작성하셨군요.! 저도 이렇게 해야겠습니다..ㅎㅎ 👍

:
user.map((u)=>(
<FriendItem
key={Object.values(u)[0]}
Expand All @@ -29,6 +43,14 @@ const Friends = () => {
);
};

const StyledButton = styled.button`
float: right;
border: none;
outline:none;
background: white;
font-size: medium;
`

const StyledBlock = styled.div`
display: flex;
flex-direction: row;
Expand Down
45 changes: 45 additions & 0 deletions src/pages/Friends/Search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, {useState, useEffect} from 'react';
import {useRecoilState,useRecoilValue,} from 'recoil';
import { userState } from '../../recoil/atom';
import FriendItem from './FriendItem';
import styled from "styled-components"

const Search = () => {
const [user, setUser] = useRecoilState<Object[]>(userState);

const [search, setSearch] = useState("");
const onChange = (e:React.ChangeEvent<HTMLInputElement>) => {
setSearch(e.target.value);
}

const filterUser= user.filter((p) => {
let result = Object.values(p)[1].replace(" ","").toLocaleLowerCase().includes(search.toLocaleLowerCase());
console.log(Object.values(p)[1],result);
return result;
})

return (
<div>
<br/>
<StyledInput type="text" value={search} onChange={onChange}/>
{
filterUser.map((u)=>(
<FriendItem
key={Object.values(u)[0]}
id={Object.values(u)[0]}
name={Object.values(u)[1]}
src={Object.values(u)[2]}
number={Object.values(user).length}
/>
))
}
</div>
);
};

const StyledInput = styled.input`
width: 250px;
height: 20px;
`

export default Search;