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
Open
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
462 changes: 448 additions & 14 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.11.60",
"@types/node": "^16.11.65",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"@types/recoil": "^0.0.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "^6.4.2",
"react-router-dom": "^6.4.2",
"react-scripts": "5.0.1",
"typescript": "^4.8.3",
"recoil": "^0.7.6",
"styled-components": "^5.3.6",
"typescript": "^4.8.4",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand All @@ -39,5 +44,10 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/react-router": "^5.1.19",
"@types/react-router-dom": "^5.3.3",
"@types/styled-components": "^5.1.26"
}
}
Binary file added public/img/a.jfif
Binary file not shown.
Binary file added public/img/b.jfif
Binary file not shown.
Binary file added public/img/c.jfif
Binary file not shown.
Binary file added public/img/d.jfif
Binary file not shown.
Binary file added public/img/e.jfif
Binary file not shown.
Binary file added public/img/짱구.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import { Route, Routes } from 'react-router-dom';
import Friends from "./pages/Friends/Friends";
import Chat from "./pages/Chatting/Chat";
import Setting from "./pages/Setting/Setting";
import Room from './pages/Room/Room';
import GlobalStyle from './styles/GlobalStyle';

function App() {
return <div>화이팅!!</div>;

return (
<>
<GlobalStyle/>
<Routes>
<Route path = '/' element={<Friends/>}/>
<Route path = '/chat' element={<Chat/>}/>
<Route path = '/setting' element={<Setting/>}/>
<Route path = '/room/:id' element={<Room/>}/>
</Routes>
</>
);
}

export default App;
58 changes: 58 additions & 0 deletions src/assets/ContentInfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"id":0,
"from":0,
"to":3,
"content":"짱구짱구",
"date":"02:11"
},
{
"id":1,
"from":3,
"to":0,
"content":"스폰지밥",
"date":"02:12"
},
{
"id":2,
"from":0,
"to":1,
"content":"난 짱구",
"date":"02:14"
},
{
"id":3,
"from":2,
"to":0,
"content":"난 그로밋",
"date":"02:16"
},
{
"id":4,
"from":5,
"to":0,
"content":"난 징징이",
"date":"02:17"
},
{
"id":5,
"from":3,
"to":0,
"content":"스폰지밥밥",
"date":"02:19"
},
{
"id":6,
"from":0,
"to":3,
"content":"짱구",
"date":"02:20"
},
{
"id":7,
"from":4,
"to":0,
"content":"난 뚱이",
"date":"02:21"
}
Copy link
Member

Choose a reason for hiding this comment

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

희수님이 코드리뷰 남겨주신대로 저랑 이 부분이 조금 다르군요..!
저는 기존 과제에서는 concat을 사용했고, 이번 과제에 roomId를 추가하면서 concat 사용이 힘들었는데, 희수님처럼 구현하면 제가 저번 과제 했던 것 처럼 concat을 쉽게 사용할 수 있었겠네요! 방법하나 알아갑니다 👍

]
32 changes: 32 additions & 0 deletions src/assets/UserInfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"id":0,
"name":"짱구",
"src":"img/짱구.png"
},
{
"id":1,
"name":"숀",
"src":"img/a.jfif"
},
{
"id":2,
"name":"그로밋",
"src":"img/b.jfif"
},
{
"id":3,
"name":"스폰지밥",
"src":"img/c.jfif"
},
{
"id":4,
"name":"뚱이",
"src":"img/d.jfif"
},
{
"id":5,
"name":"징징이",
"src":"img/e.jfif"
}
]
46 changes: 46 additions & 0 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import { Link } from 'react-router-dom';
import styled from "styled-components"

const StyledBlock = styled.div`
height: 700px;
width: 80px;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: #EAEAEA;
border-radius:30px 0px 0px 30px;
`

const StyledList = styled.ul`
display: flex;
font-size: 30px;
flex-direction: column;
align-items: center;
justify-content: center;
width: 0px;
`

const StyledLink = styled(Link)`
text-decoration: none;
text-align: center;
width: 80px;
`;

const Header = () => {
return (
<StyledBlock>
<StyledList>
<StyledLink to="/">👥</StyledLink>
</StyledList>
<StyledList>
<StyledLink to="/chat">💬​</StyledLink>
</StyledList>
<StyledList>
<StyledLink to="/setting">⚙️​</StyledLink>
</StyledList>
</StyledBlock>
);
};

export default Header;
12 changes: 9 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
import { RecoilRoot } from "recoil";

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
<RecoilRoot>
<BrowserRouter>
<React.StrictMode>
<App />
</React.StrictMode>
</BrowserRouter>
</RecoilRoot>
);
53 changes: 53 additions & 0 deletions src/pages/Chatting/Chat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import Header from '../../components/Header';
import { userState } from '../../recoil/atom';
import {useRecoilState,useRecoilValue,} from 'recoil';
import styled from "styled-components"
import ChatItem from './ChatItem';

const StyledBlock = styled.div`
display: flex;
flex-direction: row;
border-radius: 30px;
box-shadow: 5px 5px 10px #000;
height: 700px;
`
const StyledContent = styled.div`
height: 650px;
width: 280px;
justify-content: center;
align-items: center;
background-color: white;
border-radius:0px 30px 30px 0px;
margin: 20px;
`

const Chat = () => {

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

return (
<StyledBlock>
<Header/>
<StyledContent>
채팅
{
user.map((u)=>(
Object.values(u)[0] === 0 ?
null
:
<ChatItem
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}
/>
))
}
</StyledContent>
</StyledBlock>
);
};

export default Chat;
86 changes: 86 additions & 0 deletions src/pages/Chatting/ChatItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import { contentState} from '../../recoil/atom';
import {useRecoilState,useRecoilValue,} from 'recoil';

type ChatItemProps = {
id: number;
name: string;
src: string;
number: number;
};

function ChatItem({id,name,src,number}:ChatItemProps){
const chatLink = '/room/' + id;

const [content, setContent] = useRecoilState(contentState);
const result = content.filter(c=>(c.to === id || c.from === id));
const lastContent = result[result.length-1];

return (
<StyledItem to={chatLink}>
<StyledBox>
<StyledImage width={"45px"} height={"45px"} src={src}/>&nbsp;
<StyledFontBox>
Copy link
Member

Choose a reason for hiding this comment

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

큰 styled component 안에 있는 요소들은 선택자로 관리하시면 굳이 새로운 styled component 만들지 않으셔도 돼요!.!

{name}
<StyledFont>
{lastContent.content}
</StyledFont>
</StyledFontBox>
<StyledDate>
{lastContent.date}
</StyledDate>
</StyledBox>
</StyledItem>
);
};

type StyledProps = {
width: string;
height: string;
}

const StyledDate = styled.div`
float: right;
object-align: top;
color: gray;
font-size: small;
`

const StyledFontBox = styled.div`
display: flex;
flex-direction: column;
width:200px;
color: black;
`
const StyledFont = styled.div`
font-size: small;
color: gray;
`
const StyledBox = styled.div`
display: flex;
margin: 2px;
heigth: 16px;
width: 280px;
align-items: center;
&:hover{
background-color : #EEEEEE;
}
`

const StyledImage = styled.img<StyledProps>`
margin: 5px;
border-radius: 15px;
height: ${(props) => props.height}
width: ${(props) => props.width}
`;

const StyledItem = styled(Link)`
text-decoration: none;
height: auto;
width: 280px;
`


export default ChatItem;
Loading