-
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.
Browse files
Browse the repository at this point in the history
[Feat/#21] 채팅 입력창 컴포넌트 구현
- Loading branch information
Showing
13 changed files
with
918 additions
and
1,123 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,152 @@ | ||
"use client"; | ||
import { createUserKeyCookie } from "@/auth/utils/createUserKeyCookie"; | ||
import { useCreateChatRoom } from "@/chat/hooks/useCreateChatRoom"; | ||
import { useSendChatMessage } from "@/chat/hooks/useSendChatMesasge"; | ||
import ArrowUpIcon from "@/shared/assets/icons/arrow-up-default.svg"; | ||
import * as Tooltip from "@radix-ui/react-tooltip"; | ||
import { useRouter } from "next/navigation"; | ||
import { useState } from "react"; | ||
import TextareaAutosize from "react-textarea-autosize"; | ||
import { css } from "styled-components"; | ||
|
||
export default function ChatTextField() { | ||
const [message, setMessage] = useState(""); | ||
const [isSingleLineTextarea, setIsSingleLineTextarea] = useState(true); | ||
const { mutate: createChatRoom, isPending: isCreatingChatRoom } = useCreateChatRoom(); | ||
const { mutate: sendChatMessage, isPending: isSendingChatMessage } = useSendChatMessage(); | ||
const router = useRouter(); | ||
const textareaMinHeight = 52; | ||
|
||
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
const value = e.target.value; | ||
if (value.length <= maxMessageLength) { | ||
setMessage(value); | ||
} | ||
}; | ||
|
||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
setMessage(""); | ||
await createUserKeyCookie(); | ||
createChatRoom(undefined, { | ||
onSuccess: (data) => { | ||
sendChatMessage( | ||
{ | ||
roomId: data.roomId, | ||
message: message, | ||
intent: "NORMAL", | ||
}, | ||
{ | ||
onSuccess: () => { | ||
router.push(`/chats/${data.roomId}`); | ||
}, | ||
} | ||
); | ||
}, | ||
}); | ||
}; | ||
const maxMessageLength = 300; | ||
const disabled = isCreatingChatRoom || isSendingChatMessage; | ||
|
||
return ( | ||
<form | ||
onSubmit={handleSubmit} | ||
css={css` | ||
position: relative; | ||
border-radius: 8px; | ||
`} | ||
> | ||
<Tooltip.Provider> | ||
<Tooltip.Root open={message.length === maxMessageLength}> | ||
<Tooltip.Trigger asChild> | ||
<TextareaAutosize | ||
value={message} | ||
onChange={handleChange} | ||
placeholder="오늘의 운세는 어떨까?" | ||
minRows={1} | ||
maxRows={8} | ||
onHeightChange={(height) => { | ||
const isSingleLine = height <= textareaMinHeight; | ||
setIsSingleLineTextarea(isSingleLine); | ||
}} | ||
css={css` | ||
border: none; | ||
resize: none; | ||
padding: 10px 56px 10px 12px; | ||
width: 100%; | ||
height: ${isSingleLineTextarea ? `${textareaMinHeight}px` : "auto"}; | ||
min-height: ${textareaMinHeight}px; | ||
border-radius: 8px; | ||
${({ theme }) => theme.fonts.body3} | ||
line-height: ${isSingleLineTextarea ? "32px" : "24px"}; | ||
background-color: ${({ theme }) => theme.colors.grey00}; | ||
color: ${({ theme }) => theme.colors.grey90}; | ||
caret-color: ${({ theme }) => theme.colors.grey90}; | ||
&::placeholder { | ||
color: ${({ theme }) => theme.colors.grey30}; | ||
} | ||
&:focus-visible { | ||
outline: none; | ||
} | ||
${disabled && | ||
css` | ||
color: ${({ theme }) => theme.colors.grey40}; | ||
background-color: ${({ theme }) => theme.colors.grey10}; | ||
`} | ||
`} | ||
/> | ||
</Tooltip.Trigger> | ||
<Tooltip.Portal> | ||
<Tooltip.Content | ||
css={css` | ||
background-color: ${({ theme }) => theme.colors.grey90}; | ||
color: ${({ theme }) => theme.colors.white}; | ||
padding: 6px 8px; | ||
border-radius: 8px; | ||
${({ theme }) => theme.fonts.body1} | ||
text-align: center; | ||
`} | ||
> | ||
<Tooltip.Arrow | ||
width={16} | ||
height={10} | ||
css={css` | ||
fill: ${({ theme }) => theme.colors.grey90}; | ||
`} | ||
/> | ||
미안하지만 고양이가 알아들을 수 있는 | ||
<br /> | ||
글자 수는 300자까지야 냥 | ||
</Tooltip.Content> | ||
</Tooltip.Portal> | ||
</Tooltip.Root> | ||
</Tooltip.Provider> | ||
<button | ||
type="submit" | ||
disabled={disabled} | ||
css={css` | ||
position: absolute; | ||
right: 12px; | ||
bottom: 12px; | ||
padding: 4px; | ||
border-radius: 4px; | ||
background-color: ${({ theme }) => theme.colors.primary03}; | ||
&:disabled { | ||
background-color: ${({ theme }) => theme.colors.grey20}; | ||
pointer-events: none; | ||
} | ||
`} | ||
aria-label="메세지 전송" | ||
> | ||
<ArrowUpIcon | ||
width={24} | ||
height={24} | ||
css={css` | ||
display: block; | ||
color: ${({ theme }) => theme.colors.grey00}; | ||
`} | ||
/> | ||
</button> | ||
</form> | ||
); | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,19 @@ | ||
"use client"; | ||
|
||
import { css } from "styled-components"; | ||
|
||
export default function FullscreenOverflowDivider() { | ||
return ( | ||
<hr | ||
css={css` | ||
margin: 0; | ||
block-size: 1px; | ||
border: none; | ||
width: 100%; | ||
background-color: ${(props) => props.theme.colors.grey10}; | ||
box-shadow: 0 0 0 100vmax ${(props) => props.theme.colors.grey10}; | ||
clip-path: inset(0px -100vmax); | ||
`} | ||
/> | ||
); | ||
} |
Oops, something went wrong.