-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/BookwooriAlpineClub/Bookwoor…
…i-Front into deploy-1.1
- Loading branch information
Showing
19 changed files
with
394 additions
and
111 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import styled from 'styled-components'; | ||
import React, { useState } from 'react'; | ||
import { sendHandler } from '@src/apis/chat'; | ||
import { ReactComponent as Send } from '@src/assets/icons/send.svg'; | ||
import { ReactComponent as SendGreen } from '@src/assets/icons/send_green.svg'; | ||
|
||
interface ChannelChatBarProps { | ||
channelName: string; | ||
channelId: number; | ||
} | ||
|
||
const ChannelChatBar = ({ channelName, channelId }: ChannelChatBarProps) => { | ||
const [chat, setChat] = useState(''); | ||
|
||
const handleChangeInput = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setChat(e.target.value); | ||
}; | ||
|
||
const handleKeyDown = (e: React.KeyboardEvent) => { | ||
if (e.key === 'Enter') { | ||
handleSendMessage(); | ||
} | ||
}; | ||
|
||
const handleSendMessage = async () => { | ||
if (!chat.trim()) return; | ||
|
||
const message: MessageRequest = { | ||
channelId, | ||
type: 'text', | ||
content: chat, | ||
}; | ||
|
||
try { | ||
await sendHandler(message, '/pub/channel/send'); | ||
console.log('Message sent successfully'); | ||
setChat(''); | ||
} catch (error) { | ||
console.error('Failed to send message:', error); | ||
} | ||
}; | ||
return ( | ||
<SLayout> | ||
<SInput | ||
type='text' | ||
value={chat} | ||
onChange={handleChangeInput} | ||
placeholder={`${channelName}에 문자 보내기`} | ||
onKeyDown={handleKeyDown} | ||
/> | ||
<SButton type='button' onClick={handleSendMessage}> | ||
{chat ? <SendGreen /> : <Send />} | ||
</SButton> | ||
</SLayout> | ||
); | ||
}; | ||
|
||
export default ChannelChatBar; | ||
|
||
const SLayout = styled.div` | ||
display: flex; | ||
gap: 0.625rem; | ||
position: sticky; | ||
bottom: 0; | ||
width: 100%; | ||
padding: 0.9375rem; | ||
background-color: ${({ theme }) => theme.colors.white}; | ||
`; | ||
const SInput = styled.input` | ||
padding: 0 0.625rem; | ||
width: 100%; | ||
border-radius: 1.875rem; | ||
${({ theme }) => theme.fonts.body}; | ||
background-color: ${({ theme }) => theme.colors.black300}; | ||
`; | ||
const SButton = styled.button` | ||
display: flex; | ||
justify-content: center; | ||
align-itmes: center; | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useInfiniteQuery } from '@tanstack/react-query'; | ||
import { getChannelMessages } from '@src/apis/channel'; | ||
|
||
const SIZE = 10; | ||
|
||
const useChattingLog = (channelId: number) => { | ||
return useInfiniteQuery({ | ||
queryKey: ['getChannelMessages', channelId], | ||
queryFn: ({ pageParam = 0 }) => | ||
getChannelMessages(channelId, pageParam, SIZE), | ||
initialPageParam: 0, | ||
getNextPageParam: (lastPage, allPages) => { | ||
if (!lastPage || !lastPage.messages || lastPage.messages.length < SIZE) { | ||
return undefined; | ||
} | ||
|
||
const isLastPage = lastPage.messages.length < SIZE; | ||
return isLastPage ? undefined : allPages.length; | ||
}, | ||
}); | ||
}; | ||
|
||
export default useChattingLog; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { AxiosError } from 'axios'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { Server } from '@src/types/apis/server'; | ||
import { getServerOne } from '@src/apis/server'; | ||
|
||
const useChannel = (channelId: number) => {}; |
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
Oops, something went wrong.