This repository has been archived by the owner on Feb 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 259
Emoji Picker feature #55
Open
DevFlex
wants to merge
5
commits into
lukejacksonn:master
Choose a base branch
from
DevFlex:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5965563
Initial attempt to add notification support. There is still and issue…
DevFlex 21f2f58
fixed merge conflicts: I kept the changes from the original repo beca…
DevFlex f5589f8
Added emoji picker feature.
DevFlex 040304f
fixed up code formatting using prettier
DevFlex 1664fe5
made more updates to code formatting so it matches the origin. I also…
DevFlex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,109 @@ | ||
import React from 'react' | ||
import React, { Component } from 'react' | ||
import style from './index.module.css' | ||
import { FileInput } from '../FileInput' | ||
import EmojiPicker from '../EmojiPicker' | ||
|
||
export const CreateMessageForm = ({ | ||
state: { user = {}, room = {}, message = '' }, | ||
actions: { runCommand }, | ||
}) => | ||
room.id ? ( | ||
<form | ||
className={style.component} | ||
onSubmit={e => { | ||
e.preventDefault() | ||
const message = e.target[0].value | ||
e.target[0].value = '' | ||
message.startsWith('/') | ||
? runCommand(message.slice(1)) | ||
: message.length > 0 && | ||
user.sendMessage({ | ||
text: message, | ||
roomId: room.id, | ||
}) | ||
}} | ||
> | ||
<input | ||
placeholder="Type a Message.." | ||
onInput={e => user.isTypingIn({ roomId: room.id })} | ||
/> | ||
<FileInput state={{ user, room, message }} /> | ||
<button type="submit"> | ||
<svg> | ||
<use xlinkHref="index.svg#send" /> | ||
</svg> | ||
</button> | ||
</form> | ||
) : null | ||
export class CreateMessageForm extends Component { | ||
constructor(props) { | ||
super(props) | ||
|
||
this.state = { | ||
message: '', | ||
cursorPostion: 0 | ||
} | ||
} | ||
|
||
render() { | ||
const { runCommand, toggleEmojiPicker } = this.props.actions | ||
const { user, room, message, isPickerShowing } = this.props.state | ||
|
||
return room.id ? ( | ||
<form | ||
className={style.component} | ||
onSubmit={e => { | ||
e.preventDefault() | ||
const message = this.state.message | ||
message.startsWith('/') | ||
? runCommand(message.slice(1)) | ||
: message.length > 0 && | ||
user.sendMessage({ | ||
text: message, | ||
roomId: room.id | ||
}) | ||
|
||
this.setState({ | ||
message: '' | ||
}) | ||
}} | ||
> | ||
<input | ||
ref={input => { | ||
this.messageInput = input | ||
}} | ||
placeholder="Type a Message.." | ||
onInput={this.handleInput.bind(this)} | ||
onClick={this.updateCursorPostion.bind(this)} | ||
onKeyUp={e => { | ||
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') { | ||
this.updateCursorPostion(e) | ||
} | ||
}} | ||
value={this.state.message} | ||
/> | ||
<EmojiPicker | ||
state={{ isPickerShowing }} | ||
actions={{ | ||
toggleEmojiPicker, | ||
handleEmojiSelection: this.addEmojiToMessage.bind(this) | ||
}} | ||
/> | ||
<FileInput state={{ user, room, message }} /> | ||
<button type="submit"> | ||
<svg> | ||
<use xlinkHref="index.svg#send" /> | ||
</svg> | ||
</button> | ||
</form> | ||
) : null | ||
} | ||
|
||
handleInput(e) { | ||
const { user, room } = this.props.state | ||
user.isTypingIn({ roomId: room.id }) | ||
|
||
this.setState({ | ||
message: e.target.value, | ||
cursorPostion: e.target.selectionStart | ||
}) | ||
} | ||
|
||
updateCursorPostion(e) { | ||
this.setState({ | ||
cursorPostion: e.target.selectionStart | ||
}) | ||
} | ||
|
||
addEmojiToMessage(emoji) { | ||
let message = this.state.message | ||
let newMessage = '' | ||
let cursor = this.state.cursorPostion | ||
let beforeCursorStr = '' | ||
let afterCursorStr = '' | ||
|
||
beforeCursorStr = message.substring(0, cursor) | ||
afterCursorStr = message.substr(cursor) | ||
newMessage = `${beforeCursorStr}${emoji}${afterCursorStr}` | ||
|
||
// reset the cursor to be after the emoji | ||
this.messageInput.setSelectionRange( | ||
this.state.cursorPostion + 2, | ||
this.state.cursorPostion + 2, | ||
0 | ||
) | ||
|
||
this.setState({ | ||
cursorPostion: this.state.cursorPostion + 2, | ||
message: newMessage | ||
}) | ||
} | ||
} |
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,42 @@ | ||
import EmojiPicker from 'emoji-picker-react' | ||
import style from './index.module.css' | ||
|
||
import React from 'react' | ||
import JSEMOJI from 'emoji-js' | ||
|
||
let jsemoji = new JSEMOJI() | ||
|
||
const Picker = ({ | ||
state: { isPickerShowing }, | ||
actions: { toggleEmojiPicker, handleEmojiSelection }, | ||
}) => ( | ||
<div | ||
onClick={e => { | ||
e.nativeEvent.stopImmediatePropagation() | ||
}} | ||
className={style.component} | ||
> | ||
<div | ||
className={`${style.overlayWrapper} ${isPickerShowing ? style.show : ''}`} | ||
> | ||
<EmojiPicker | ||
onEmojiClick={(emojiCode, emojiObj, e) => { | ||
e.nativeEvent.stopImmediatePropagation() | ||
const emoji = jsemoji.replace_colons(`:${emojiObj.name}:`) | ||
handleEmojiSelection(emoji) | ||
toggleEmojiPicker(!isPickerShowing) | ||
}} | ||
/> | ||
</div> | ||
<input | ||
type={'button'} | ||
className={style.button} | ||
onClick={e => { | ||
e.preventDefault() | ||
toggleEmojiPicker(!isPickerShowing) | ||
}} | ||
/> | ||
</div> | ||
) | ||
|
||
export default Picker |
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,34 @@ | ||
.component { | ||
width: 2rem; | ||
height: 2rem; | ||
position: relative; | ||
} | ||
|
||
.overlayWrapper { | ||
height: 0; | ||
overflow: hidden; | ||
position: absolute; | ||
bottom: 32px; | ||
right: 0; | ||
-webkit-transition: height .25s ease-in-out; /* Safari */ | ||
transition: height .25s ease-in-out; | ||
} | ||
|
||
.button { | ||
width: 32px; | ||
height: 32px; | ||
position: absolute; | ||
bottom: 0; | ||
right: 0; | ||
background-image: url("https://cdn.jsdelivr.net/emojione/assets/3.0/png/32/1f600.png"); | ||
background-position: center center; | ||
background-repeat: no-repeat; | ||
background-size: contain; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
|
||
.show { | ||
/* find a better way to set this height */ | ||
height: 333px; | ||
} |
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 |
---|---|---|
|
@@ -1063,7 +1063,7 @@ | |
lodash "^4.2.0" | ||
to-fast-properties "^2.0.0" | ||
|
||
"@pusher/chatkit@^0.7.3": | ||
"@pusher/chatkit@^0.7.9": | ||
version "0.7.9" | ||
resolved "https://registry.yarnpkg.com/@pusher/chatkit/-/chatkit-0.7.9.tgz#34587299107baf55b36b3fe1c9870ea99e90a62a" | ||
dependencies: | ||
|
@@ -1611,7 +1611,7 @@ babel-register@^6.26.0: | |
mkdirp "^0.5.1" | ||
source-map-support "^0.4.15" | ||
|
||
babel-runtime@^6.22.0, babel-runtime@^6.26.0: | ||
babel-runtime@^6.22.0, babel-runtime@^6.25.0, babel-runtime@^6.26.0: | ||
version "6.26.0" | ||
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" | ||
dependencies: | ||
|
@@ -2964,6 +2964,23 @@ elliptic@^6.0.0: | |
minimalistic-assert "^1.0.0" | ||
minimalistic-crypto-utils "^1.0.0" | ||
|
||
[email protected]: | ||
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/emoji-datasource/-/emoji-datasource-4.0.0.tgz#3fc9c0c2f4fb321d9291138819f6d100603d3e2f" | ||
|
||
emoji-js@^3.4.0: | ||
version "3.4.0" | ||
resolved "https://registry.yarnpkg.com/emoji-js/-/emoji-js-3.4.0.tgz#dabdeda60c92d1948a5177e51ba9421d2029b052" | ||
dependencies: | ||
emoji-datasource "4.0.0" | ||
|
||
emoji-picker-react@^2.0.4: | ||
version "2.0.4" | ||
resolved "https://registry.yarnpkg.com/emoji-picker-react/-/emoji-picker-react-2.0.4.tgz#a58edc3412d39726dbcd64a7811806ccc90d9b46" | ||
dependencies: | ||
babel-runtime "^6.25.0" | ||
throttle-debounce "^1.0.1" | ||
|
||
emoji-regex@^6.1.0: | ||
version "6.5.1" | ||
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-6.5.1.tgz#9baea929b155565c11ea41c6626eaa65cef992c2" | ||
|
@@ -7955,6 +7972,10 @@ throat@^4.0.0: | |
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a" | ||
|
||
throttle-debounce@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-1.0.1.tgz#dad0fe130f9daf3719fdea33dc36a8e6ba7f30b5" | ||
|
||
through2@^2.0.0: | ||
version "2.0.3" | ||
resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.3.tgz#0004569b37c7c74ba39c43f3ced78d1ad94140be" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this name is missing the letter
i
Should be
updateCursorPosition