-
Notifications
You must be signed in to change notification settings - Fork 2
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
#601 add unread num chatting #692
base: dev
Are you sure you want to change the base?
Changes from all commits
c206205
b7012da
a687cbe
7df84fc
6648b28
91a06ad
9c51bcb
66bcf6d
0363049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { memo, useCallback } from "react"; | ||
import { memo, useCallback, useMemo } from "react"; | ||
|
||
import type { BotChat, LayoutType, UserChat } from "@/types/chat"; | ||
|
||
|
@@ -59,6 +59,10 @@ type MessageSetProps = { | |
|
||
const MessageSet = ({ chats, layoutType, roomInfo }: MessageSetProps) => { | ||
const { oid: userOid } = useValueRecoilState("loginInfo") || {}; | ||
const readAts = useMemo(() => { | ||
const readAts = roomInfo?.part?.map((user) => user?.readAt); | ||
return readAts; | ||
}, [chats, roomInfo]); | ||
const authorId = chats?.[0]?.authorId; | ||
const authorProfileUrl = | ||
"authorProfileUrl" in chats?.[0] ? chats?.[0].authorProfileUrl : ""; | ||
|
@@ -127,12 +131,20 @@ const MessageSet = ({ chats, layoutType, roomInfo }: MessageSetProps) => { | |
}), | ||
[userOid, authorId, layoutType] | ||
); | ||
const styleSubinfoWrap = { | ||
display: "flex", | ||
flexDirection: "column" as any, | ||
alignItems: authorId === userOid ? "flex-end" : "flex-start", | ||
}; | ||
const styleTime = { | ||
...theme.font8, | ||
color: theme.gray_text, | ||
marginBottom: "1px", | ||
minWidth: "fit-content", | ||
}; | ||
const styleUnreadNum = { | ||
...theme.font8_medium, | ||
}; | ||
|
||
return ( | ||
<div css={style}> | ||
|
@@ -168,11 +180,18 @@ const MessageSet = ({ chats, layoutType, roomInfo }: MessageSetProps) => { | |
color={authorId === userOid ? theme.white : theme.black} | ||
/> | ||
</div> | ||
{index === chats.length - 1 && ( | ||
<div css={styleTime} className="selectable"> | ||
{dayjs(chat.time).format("H시 mm분")} | ||
<div css={styleSubinfoWrap}> | ||
<div css={styleUnreadNum} className="selectable"> | ||
{readAts?.filter((readAt) => readAt < chat.time).length == 0 | ||
? null | ||
: readAts?.filter((readAt) => readAt < chat.time).length} | ||
Comment on lines
+185
to
+187
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. 같은 연산이 두 번 반복되는데, 한 번의 계산으로 줄일 수 있을 것 같습니다 ! |
||
</div> | ||
)} | ||
{index === chats.length - 1 && ( | ||
<div css={styleTime} className="selectable"> | ||
{dayjs(chat.time).format("H시 mm분")} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -44,6 +44,17 @@ export default ( | |||||
chatBodyRef.current.scrollTop = scrollTop; | ||||||
}, [chats]); | ||||||
|
||||||
const lastChat = chats.length > 0 ? chats[chats.length - 1] : {}; | ||||||
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.
Suggested change
로 더 간단히 할 수 있을 것 같아요. |
||||||
useEffect(() => { | ||||||
socketReady(() => | ||||||
axios({ | ||||||
url: "/chats/read", | ||||||
method: "post", | ||||||
data: { roomId }, | ||||||
}) | ||||||
); | ||||||
}, ["time" in lastChat ? lastChat?.time : ""]); | ||||||
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.
Suggested change
과 차이가 없을 것 같습니다 ! 그리고 |
||||||
|
||||||
useEffect(() => { | ||||||
const chatBody = chatBodyRef?.current; | ||||||
let isBottomOnScrollCache: boolean = true; | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ declare global { | |||||
| `${PixelValue} ${PixelValue} ${PixelValue} ${PixelValue}`; | ||||||
type Padding = Margin; | ||||||
type User = { | ||||||
readAt: any; | ||||||
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. type을
Suggested change
|
||||||
_id: string; | ||||||
name: string; | ||||||
nickname: string; | ||||||
|
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.
연산에서
chats
가 사용되지 않아 dependency array 에서 제외되어도 될 것 같아요.