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

feat: 쪽지함 api 연결 #196

Merged
merged 26 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ac3c285
feat: message list query 구현
Dec 16, 2023
45a1d42
feat: message list api 연결
Dec 16, 2023
feb4077
feat: message 내용 조회 query 추가
Dec 16, 2023
365321e
feat: message 내용 api 연결
Dec 16, 2023
fd0149d
Merge branch 'develop' into feat/#195_messagebox-api
Jan 2, 2024
21adf89
Merge branch 'feat/api-changes' into feat/#195_messagebox-api
Jan 4, 2024
76e2a7c
Merge branch 'develop' into feat/#195_messagebox-api
Jan 5, 2024
bb80733
feat: roomId가 있는 경우 해당 메세지룸 열기
Jan 9, 2024
5903515
feat: message 보내기 api 작성
Jan 9, 2024
1e6059e
Merge branch 'develop' into feat/#195_messagebox-api
Jan 9, 2024
06e1b5a
feat: 메세지 전송 api 연결
Jan 9, 2024
fbcbd76
feat: 채팅시 스크롤 하단에 고정, 시간 다른경우 시간 보이기
Jan 9, 2024
9a8a44d
feat: 쪽지함 나가기 api 작성
Jan 9, 2024
847db70
feat: Sidebar 쪽지함 링크 수정
Jan 9, 2024
e5e5f49
feat: 쪽지함 나가기 api 연결
Jan 9, 2024
51c21e2
feat: 쪽지내용 refresh 기능 추가
Jan 9, 2024
0108540
design: 쪽지함 시간 보여주는 스타일 변경
Jan 9, 2024
fdb7333
feat: 메세지 리스트 sort 항목 추가
Jan 10, 2024
bf234d0
design: pc 채팅창 최하단으로 가지 않는 이슈 수정
Jan 10, 2024
e1845a4
feat: 메세지 리스트 dto 변경 반영
Jan 10, 2024
c334aa3
chore: Res에 messageId 추가, 코드 가독성을 위한 여백 추가
Jan 12, 2024
d0fb4bb
chore: 코드 가독성을 위한 변수명 수정, 불필요한 코드 제거
Jan 12, 2024
32e7e96
chore: 가독성을 위한 변수명 수정
Jan 12, 2024
ddacbb1
Merge branch 'develop' into feat/#195_messagebox-api
Jan 15, 2024
cd91046
feat: useGetMessageRoomsQuery 의존성 변경
Jan 21, 2024
2776145
Merge branch 'develop' into feat/#195_messagebox-api
shinhyojeong Jan 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/apis/message/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ export const getMessage = (params: GetMessageReq) =>
params
)

export const createMessage = (
messageRoomId: number,
params: CreateMessageReq
) =>
http.post<CreateMessageReq, CreateMessageRes>(
export const createMessage = ({ messageRoomId, ...params }: CreateMessageReq) =>
http.post<Omit<CreateMessageReq, 'messageRoomId'>, CreateMessageRes>(
`/msgrooms/${messageRoomId}/msgs`,
params
)
Expand Down
9 changes: 4 additions & 5 deletions src/apis/message/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
GetMessageRoomsReq
} from './types'

export const useGetMessageRooms = (params: GetMessageRoomsReq) =>
export const useGetMessageRoomsQuery = (params: GetMessageRoomsReq) =>
useQuery({
queryKey: ['getMessageRooms'],
sonsurim marked this conversation as resolved.
Show resolved Hide resolved
queryFn: () => getMessageRooms(params)
Expand All @@ -25,13 +25,12 @@ export const useGetMessageQuery = ({ msgRoomId, ...res }: GetMessageReq) =>
msgRoomId,
...res
}),
enabled: Boolean(msgRoomId)
enabled: typeof msgRoomId === 'number'
})

export const useCreateMessageMutation = (messageRoomId: number) =>
export const useCreateMessageMutation = () =>
useMutation({
sonsurim marked this conversation as resolved.
Show resolved Hide resolved
mutationFn: (params: CreateMessageReq) =>
createMessage(messageRoomId, params)
mutationFn: (params: CreateMessageReq) => createMessage(params)
})

export const useDeleteMessageRoomMutation = (messageRoomId: number) =>
Expand Down
1 change: 1 addition & 0 deletions src/apis/message/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type GetMessageReq = {
export type GetMessageRes = MessageInfo[]

export type CreateMessageReq = {
messageRoomId: number
content: string
}
export type CreateMessageRes = CommonCreation
26 changes: 15 additions & 11 deletions src/components/messagebox/ChattingRoom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ export const ChattingRoom = ({ roomId, onClose }: ChattingRoomProps) => {
msgRoomId: roomId,
page: 0
})
const createMessageMutation = useCreateMessageMutation(roomId)
const createMessageMutation = useCreateMessageMutation()
const deleteMessageRoomMutation = useDeleteMessageRoomMutation(roomId)

const chattingBoxRef = useRef<HTMLDivElement | null>(null)
const inputRef = useRef<HTMLInputElement | null>(null)
const { desktop, tablet, mobile } = useMedia()

const [messages, setMessages] = useState<ChattingProps['messages']>([])
const { desktop, tablet, mobile } = useMedia()
const { isOpen, openModal, closeModal } = useModal()
const { user } = useAuth()

const senderInfo = {
id: user.id,
nickname: user.nickname,
Expand All @@ -62,13 +65,10 @@ export const ChattingRoom = ({ roomId, onClose }: ChattingRoomProps) => {
handleCloseRoom()
}

const refetchMessage = async () => {
await getMessageQuery.refetch()
}

const handleSubmitMessage = async (message: string) => {
const handleSubmitMessage = async (content: string) => {
const res = await createMessageMutation.mutateAsync({
content: message
messageRoomId: roomId,
content
})

if (inputRef.current) {
Expand All @@ -79,11 +79,11 @@ export const ChattingRoom = ({ roomId, onClose }: ChattingRoomProps) => {
...prev,
{
member: senderInfo,
content: message,
content,
sendTime: res.createdAt
}
])
await refetchMessage()
await getMessageQuery.refetch()
}

useEffect(() => {
Expand All @@ -100,7 +100,11 @@ export const ChattingRoom = ({ roomId, onClose }: ChattingRoomProps) => {
<IconButton icon="arrowLeft" size={24} onClick={handleCloseRoom} />
<Styled.Nickname>{user.nickname}</Styled.Nickname>
<Styled.IconButtonContainer>
<IconButton icon="refresh" size={24} onClick={refetchMessage} />
<IconButton
icon="refresh"
size={24}
onClick={async () => await getMessageQuery.refetch()}
sonsurim marked this conversation as resolved.
Show resolved Hide resolved
/>
<Styled.MoreButtonWrapper>
<IconButton icon="more" size={24} onClick={openModal} />
{isOpen && (
Expand Down