-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from SWM-FIRE/FIRE-774-dm-프론트-개발
FIRE-774 add direct message frame
- Loading branch information
Showing
10 changed files
with
268 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import styled from 'styled-components'; | ||
import chattingModalStore from 'src/stores/chattingModalStore'; | ||
import useUser from 'src/hooks/useUser'; | ||
import MyAvatar from 'src/assets/avatar/MyAvatar'; | ||
import ChattingPortal from './ChattingPortal'; | ||
import SendChat from './SendChat'; | ||
import { ReactComponent as Close } from '../../../assets/svg/X.svg'; | ||
|
||
export default function ChattingModal() { | ||
const { closeChattingModal, chattingFriend } = chattingModalStore(); | ||
const { isLoading, error, data } = useUser(Number(chattingFriend)); | ||
if (isLoading) | ||
return ( | ||
<ChattingPortal> | ||
<Outside onClick={closeChattingModal}> | ||
<Container onClick={(e) => e.stopPropagation()}> | ||
<Header /> | ||
<Content>{chattingFriend}</Content> | ||
<Footer>메세지창</Footer> | ||
</Container> | ||
</Outside> | ||
</ChattingPortal> | ||
); | ||
if (error) | ||
return ( | ||
<ChattingPortal> | ||
<Outside onClick={closeChattingModal}> | ||
<Container onClick={(e) => e.stopPropagation()}> | ||
<Header /> | ||
<Content>{chattingFriend}</Content> | ||
<Footer>메세지창</Footer> | ||
</Container> | ||
</Outside> | ||
</ChattingPortal> | ||
); | ||
|
||
return ( | ||
<ChattingPortal> | ||
<Outside onClick={closeChattingModal}> | ||
<Container onClick={(e) => e.stopPropagation()}> | ||
<CloseContainer onClick={closeChattingModal}> | ||
<Close /> | ||
</CloseContainer> | ||
<Header> | ||
<Avatar> | ||
<MyAvatar num={data?.avatar} /> | ||
{data?.nickname} | ||
</Avatar> | ||
</Header> | ||
<Content>{chattingFriend}</Content> | ||
<Footer> | ||
<SendChat uid={data?.uid} /> | ||
</Footer> | ||
</Container> | ||
</Outside> | ||
</ChattingPortal> | ||
); | ||
} | ||
|
||
const CloseContainer = styled.div` | ||
position: absolute; | ||
top: 2rem; | ||
right: 2rem; | ||
cursor: pointer; | ||
`; | ||
|
||
const Avatar = styled.div` | ||
display: flex; | ||
height: 5rem; | ||
font-size: 1.6rem; | ||
align-items: center; | ||
svg { | ||
height: 100%; | ||
} | ||
`; | ||
|
||
const Outside = styled.div` | ||
position: fixed; | ||
width: 100vw; | ||
height: 100vh; | ||
z-index: 999; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
`; | ||
|
||
const Header = styled.div` | ||
width: 100%; | ||
height: 8rem; | ||
color: white; | ||
border-bottom: 1px solid #374151; | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
const Content = styled.div` | ||
width: 100%; | ||
flex-grow: 1; | ||
`; | ||
|
||
const Footer = styled.div` | ||
width: 100%; | ||
`; | ||
|
||
const Container = styled.div` | ||
width: 30%; | ||
min-width: 40rem; | ||
height: 80%; | ||
min-height: 30rem; | ||
position: relative; | ||
display: flex; | ||
justify-content: space-between; | ||
flex-direction: column; | ||
background-color: #23262f; | ||
padding: 2rem; | ||
border-radius: 1rem; | ||
`; |
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,8 @@ | ||
import ReactDOM from 'react-dom'; | ||
|
||
const ChattingPortal = ({ children }) => { | ||
const el = document.getElementById('chatting-modal'); | ||
return ReactDOM.createPortal(children, el); | ||
}; | ||
|
||
export default ChattingPortal; |
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,96 @@ | ||
import React, { useState, useRef } from 'react'; | ||
import styled from 'styled-components'; | ||
import { ReactComponent as MessageSend } from '../../../assets/svg/MessageSend.svg'; | ||
|
||
export default function SendChat({ uid }: { uid: number }) { | ||
const [newMessage, setNewMessage] = useState(''); | ||
const inputRef = useRef(null); | ||
|
||
const onMessageChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
event.preventDefault(); | ||
setNewMessage(() => event.target.value); | ||
autoGrow(); | ||
}; | ||
|
||
const autoGrow = () => { | ||
if (inputRef.current) { | ||
inputRef.current.style.height = '2rem'; | ||
inputRef.current.style.height = inputRef.current.scrollHeight | ||
.toString() | ||
.concat('px'); | ||
console.log(inputRef.current.style.height); | ||
} | ||
}; | ||
|
||
const onSubmit = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
event.preventDefault(); | ||
if (newMessage.trim() === '') return; | ||
console.log('send to', uid, newMessage); | ||
// emit | ||
setNewMessage(() => ''); | ||
if (inputRef.current) { | ||
inputRef.current.style.height = '2rem'; | ||
} | ||
}; | ||
|
||
const onKeyPress = (event) => { | ||
if (event.key === 'Enter') { | ||
if (!event.shiftKey) { | ||
event.preventDefault(); | ||
onSubmit(event); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<SubmitMessage> | ||
<Input | ||
placeholder="Write your message...." | ||
value={newMessage} | ||
ref={inputRef} | ||
rows={1} | ||
onChange={onMessageChange} | ||
onKeyPress={onKeyPress} | ||
/> | ||
<Button onClick={onSubmit}> | ||
<MessageSend /> | ||
</Button> | ||
</SubmitMessage> | ||
); | ||
} | ||
|
||
const SubmitMessage = styled.form` | ||
width: 100%; | ||
max-height: 19rem; | ||
border-radius: 1rem; | ||
padding: 1.5rem 2rem; | ||
background-color: #313540; | ||
z-index: 999; | ||
`; | ||
|
||
const Input = styled.textarea` | ||
width: calc(100% - 2.7rem); | ||
font-size: 1.3rem; | ||
background-color: #313540; | ||
font-family: IBMPlexSansKRRegular; | ||
color: rgba(255, 255, 255, 1); | ||
min-height: 2rem; | ||
max-height: 13rem; | ||
resize: none; | ||
::-webkit-scrollbar { | ||
width: 0.3rem; | ||
} | ||
&:focus { | ||
outline: none; | ||
} | ||
`; | ||
|
||
const Button = styled.button` | ||
cursor: pointer; | ||
float: right; | ||
svg { | ||
width: 2rem; | ||
height: 2rem; | ||
} | ||
`; |
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,11 @@ | ||
import chattingModalStore from 'src/stores/chattingModalStore'; | ||
|
||
export default function ChattingUtil() { | ||
const { openChattingModal, setChattingFriend } = chattingModalStore(); | ||
const openChat = (friendUid: number) => { | ||
setChattingFriend(friendUid); | ||
openChattingModal(); | ||
}; | ||
|
||
return { openChat }; | ||
} |
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
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 @@ | ||
import create from 'zustand'; | ||
|
||
interface Modal { | ||
chattingFriend: number; | ||
setChattingFriend: (_by: number) => void; | ||
isChattingModal: boolean; | ||
closeChattingModal: () => void; | ||
openChattingModal: () => void; | ||
} | ||
|
||
const chattingModalStore = create<Modal>((set) => ({ | ||
chattingFriend: -1, | ||
setChattingFriend: (by) => set(() => ({ chattingFriend: by })), | ||
isChattingModal: false, | ||
closeChattingModal: () => set(() => ({ isChattingModal: false })), | ||
openChattingModal: () => set(() => ({ isChattingModal: true })), | ||
})); | ||
|
||
export default chattingModalStore; |