-
Notifications
You must be signed in to change notification settings - Fork 3
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 #172 from boostcamp-2020/feat/apply-markdown
Feat/apply markdown (#130)
- Loading branch information
Showing
10 changed files
with
453 additions
and
74 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 |
---|---|---|
@@ -1,29 +1,62 @@ | ||
import React, { useState } from 'react' | ||
|
||
import Input from '../../presenter/Input' | ||
import React, { useState, useRef } from 'react' | ||
import Editor from 'draft-js-plugins-editor' | ||
import createMarkdownShortcutsPlugin from 'draft-js-markdown-shortcuts-plugin' | ||
import { | ||
ContentState, | ||
EditorState, | ||
getDefaultKeyBinding, | ||
convertToRaw, | ||
} from 'draft-js' | ||
import styled from 'styled-components' | ||
import 'draft-js/dist/Draft.css' | ||
import { COLOR } from '../../constant/style' | ||
|
||
function MessageEditor({ channelTitle, sendMessage }) { | ||
const [message, setMessage] = useState('') | ||
const handleInput = e => { | ||
setMessage(e.target.value) | ||
const plugins = useRef([createMarkdownShortcutsPlugin()]) | ||
const [message, setMessage] = useState(EditorState.createEmpty()) | ||
|
||
const keyBindingFn = e => { | ||
if (e.key === 'Enter') return 'send-message' | ||
return getDefaultKeyBinding(e) | ||
} | ||
const handleKey = e => { | ||
if (e.key === 'Enter' && e.target.value) { | ||
sendMessage(message) | ||
setMessage('') | ||
const handleKey = command => { | ||
if (command === 'send-message' && message.getCurrentContent().hasText()) { | ||
sendMessage(JSON.stringify(convertToRaw(message.getCurrentContent()))) | ||
setMessage( | ||
EditorState.moveFocusToEnd( | ||
EditorState.push( | ||
message, | ||
ContentState.createFromText(''), | ||
'remove-range', | ||
), | ||
), | ||
) | ||
} | ||
} | ||
return ( | ||
<div> | ||
<Input | ||
placeholder={`Send a message to #${channelTitle}`} | ||
handleChange={handleInput} | ||
handleKey={handleKey} | ||
value={message} | ||
/> | ||
{/* TODO markdown, chat action μ μ© νμ */} | ||
</div> | ||
<MessageEditorContainer> | ||
<MessageEditorArea> | ||
<Editor | ||
placeholder={`Send a message to #${channelTitle}`} | ||
editorState={message} | ||
onChange={setMessage} | ||
plugins={plugins.current} | ||
handleKeyCommand={handleKey} | ||
keyBindingFn={keyBindingFn} | ||
/> | ||
|
||
{/* TODO markdown, chat action μ μ© νμ */} | ||
</MessageEditorArea> | ||
</MessageEditorContainer> | ||
) | ||
} | ||
|
||
const MessageEditorContainer = styled.div` | ||
padding: 20px; | ||
background-color: ${COLOR.WHITE}; | ||
` | ||
const MessageEditorArea = styled.div` | ||
border: 1px solid ${COLOR.LIGHT_GRAY}; | ||
padding: 10px; | ||
border-radius: 5px; | ||
` | ||
export default MessageEditor |
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import { createGlobalStyle } from 'styled-components' | ||
|
||
const GlobalStyle = createGlobalStyle` | ||
html{ | ||
height: 100%; | ||
} | ||
body { | ||
padding: 0px; | ||
margin: 0px; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
} | ||
#root{ | ||
height:100%; | ||
} | ||
` | ||
|
||
export default GlobalStyle |