-
Notifications
You must be signed in to change notification settings - Fork 11
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주차] 이은비 미션 제출합니다 #22
Open
silverain02
wants to merge
30
commits into
CEOS-Developers:master
Choose a base branch
from
silverain02:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
1b4d440
[chore] 공통 스타일 지정
silverain02 eb950ab
[chore] 초기세팅 typescript 맞춰 변경
silverain02 e0575dd
[feat] 채팅박스 컴포넌트
silverain02 20f7b02
[chore] icon 컴포넌트화
silverain02 e386d5f
[feat] input컴포넌트
silverain02 ae09e79
[feat] 입력값 처리 기능
silverain02 62802b9
[feat] localStorage에 chatData저장
silverain02 3864efe
[feat] input클릭 시 하단 스크롤 기능
silverain02 0e7ca9d
[chore] css일부 마진조정
silverain02 673e270
[chore] package 의존설정 변화
silverain02 472337b
[chore] 대화 시 사용자 전환 CSS 메시지 박스 변화
silverain02 134a720
[chore] 같은 시간 보여주지 않기
silverain02 50f6eae
[feat] 프로필 추가
silverain02 042a35b
[chore] redux 설치
silverain02 490b640
[chore]react router 설치
silverain02 4b8201d
[feat] 페이지 라우팅 적용
silverain02 bd359ad
[feat] footer구현
silverain02 ce23bd6
[chore] userData 세팅
silverain02 0f008bc
[chore] profile 스타일링
silverain02 add8959
[feat]친구리스트 배열 매핑
silverain02 bf9286c
[chore] 친구리스트 스타일링
silverain02 e03d921
[feat]myPage완성
silverain02 204a243
[feat]chatList mock data불러오기
silverain02 e1a59cb
[feat]chatList구현
silverain02 8201dc3
[feat]경로변경 후 userMock데이터 받아오기
silverain02 d821755
[feat]chatData연동
silverain02 f13b150
[feat]input기능 재건
silverain02 1a35cb6
[chore]mock data수정
silverain02 71f3f8b
[chore]말풍선 시간 조정
silverain02 567f19f
[chore] link색조정
silverain02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ | ||
{ | ||
"userId": 4, | ||
"chatData": [ | ||
{ "userId": 4, "isLike": false, "chat": "어디냐", "time": "15:00" }, | ||
{ "userId": 0, "isLike": false, "chat": "집", "time": "15:40" }, | ||
{ "userId": 4, "isLike": false, "chat": "중도가자", "time": "15:50" } | ||
] | ||
}, | ||
{ | ||
"userId": 5, | ||
"chatData": [ | ||
{ "userId": 5, "isLike": false, "chat": "과제안함?", "time": "18:00" }, | ||
{ "userId": 0, "isLike": false, "chat": "할거야", "time": "18:50" }, | ||
{ "userId": 5, "isLike": false, "chat": "언제", "time": "18:55" }, | ||
{ | ||
"userId": 0, | ||
"isLike": false, | ||
"chat": "어쩌라고 화나게하지마", | ||
"time": "19:00" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,108 +6,36 @@ import Header from '../components/Header'; | |
import ProfileSmallIcon from '../static/ProfileSmallIcon'; | ||
import ChatInputBar from '../components/ChatInputBar'; | ||
import { useEffect, useState, useRef } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
interface UserInfo { | ||
id: number; | ||
interface UserData { | ||
id: string; | ||
userName: string; | ||
comment: string; | ||
} | ||
|
||
const ChatRoom: React.FC<UserInfo> = ({ id }) => { | ||
const userIdArr: string[] = ['이은비', '윤서윤']; | ||
const [userId, setUserId] = useState(id); | ||
const [inputText, setInputText] = useState(''); | ||
const [isInputFocused, setInputFocused] = useState(false); | ||
|
||
const bodyRef = React.useRef<HTMLDivElement | null>(null); | ||
|
||
const initialData = JSON.parse( | ||
localStorage.getItem('chatData') || '[]' | ||
) as any[]; | ||
const [chatData, setChatData] = useState<any[]>(initialData); | ||
|
||
const handleHeaderClick = () => { | ||
// id를 0과 1 사이에서 토글 | ||
setUserId((prevId) => (prevId === 0 ? 1 : 0)); | ||
}; | ||
|
||
// 날짜 형식을 지정하는 함수 | ||
const getCurrentDate = () => { | ||
const now = new Date(); | ||
// const year = now.getFullYear(); | ||
// const month = String(now.getMonth() + 1).padStart(2, '0'); | ||
// const day = String(now.getDate()).padStart(2, '0'); | ||
const hours = String(now.getHours()).padStart(2, '0'); | ||
const minutes = String(now.getMinutes()).padStart(2, '0'); | ||
return `${hours}:${minutes}`; | ||
}; | ||
interface ChatData { | ||
userId: string; | ||
isLike: boolean; | ||
chat: string; | ||
time: string; | ||
} | ||
|
||
//inputText변동시 chatData추가 | ||
const ChatRoom = () => { | ||
const { userId } = useParams(); | ||
const [userData, setUserData] = useState<UserData[]>([]); | ||
useEffect(() => { | ||
const currentDate = getCurrentDate(); | ||
if (inputText.trim() !== '') { | ||
setChatData((prevChatData) => { | ||
if (prevChatData) { | ||
return [ | ||
...prevChatData, | ||
{ | ||
userId: userId, | ||
isLike: false, | ||
chat: inputText, | ||
time: currentDate, | ||
}, | ||
]; | ||
} else { | ||
return [ | ||
{ | ||
userId: userId, | ||
isLike: false, | ||
chat: inputText, | ||
time: currentDate, | ||
}, | ||
]; | ||
} | ||
fetch('/data/userData.json') | ||
.then((res) => res.json()) | ||
.then((result) => { | ||
setUserData(result); | ||
console.log(userData); | ||
}); | ||
} | ||
}, [inputText]); | ||
|
||
useEffect(() => { | ||
if (isInputFocused && bodyRef.current) { | ||
bodyRef.current.scrollTop = bodyRef.current.scrollHeight; | ||
} | ||
}, [isInputFocused]); | ||
|
||
// chatData가 업데이트될 때마다 로컬 스토리지에 저장 | ||
useEffect(() => { | ||
localStorage.setItem('chatData', JSON.stringify(chatData)); | ||
}, [chatData]); | ||
}, []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fetch를 사용하셔서 나중에 백 쪽과 연결할 때 편리할 것 같습니다:) |
||
|
||
return ( | ||
<Wrapper> | ||
<Header text={userIdArr[userId]} onClick={handleHeaderClick} /> | ||
<Body ref={bodyRef}> | ||
{chatData.map((chatItem, index) => ( | ||
<ChatBox | ||
text={chatItem.chat} | ||
hasTail={false} | ||
isMe={chatItem.userId === userId} | ||
time={ | ||
index === 0 || chatData[index - 1].time !== chatItem.time | ||
? chatItem.time | ||
: '' | ||
} | ||
isFirst={ | ||
index === 0 || chatData[index - 1].userId !== chatItem.userId | ||
} | ||
user={userIdArr[chatItem.userId]} | ||
/> | ||
))} | ||
</Body> | ||
|
||
<ChatInputBar | ||
inputText={inputText} | ||
setInputText={setInputText} | ||
isInputFocused={isInputFocused} | ||
setInputFocused={setInputFocused} | ||
/> | ||
{userData.map((it) => it.id === userId && <div>{it.userName}</div>)} | ||
</Wrapper> | ||
); | ||
}; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개인적인 생각인데, styled-component 이름을 명명함에 있어서
Wrapper
보다는 좀 더 구체적인 명명이 좋지 않을까 생각합니다! 만약 page별로 동일한 Wrapper를 적용한다면, 최상위 컴포넌트에 동일한 스타일을 지정해줄 수도 있을 거 같아용