Skip to content

Commit

Permalink
refs #564 Suggest native emoji in New Toot modal
Browse files Browse the repository at this point in the history
  • Loading branch information
h3poteto committed Aug 29, 2018
1 parent 4010078 commit e273573
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"electron-log": "^2.2.14",
"electron-window-state": "^4.1.1",
"element-ui": "^2.3.4",
"emojilib": "^2.3.0",
"hawk": "^7.0.7",
"hoek": "^5.0.3",
"i18next": "^11.5.0",
Expand Down
28 changes: 24 additions & 4 deletions src/renderer/components/TimelineSpace/Modals/NewToot/Status.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<span v-if="item.image">
<img :src="item.image" class="icon" />
</span>
<span v-if="item.code">
{{ item.code }}
</span>
{{ item.name }}
</li>
</ul>
Expand All @@ -35,6 +38,7 @@

<script>
import { mapState } from 'vuex'
import emojilib from 'emojilib'
import suggestText from '../../../../utils/suggestText'
export default {
Expand All @@ -60,7 +64,7 @@ export default {
computed: {
...mapState({
filteredAccounts: state => state.TimelineSpace.Modals.NewToot.Status.filteredAccounts,
emojis: state => state.TimelineSpace.emojis
customEmojis: state => state.TimelineSpace.emojis
}),
status: {
get: function () {
Expand Down Expand Up @@ -131,7 +135,18 @@ export default {
this.closeSuggest()
return false
}
const filtered = this.emojis.filter(emoji => emoji.name.includes(word))
// Find native emojis
const filteredEmojiName = emojilib.ordered.filter(emoji => `:${emoji}`.includes(word))
const filteredNativeEmoji = filteredEmojiName.map((name) => {
return {
name: `:${name}:`,
code: emojilib.lib[name].char
}
})
// Find custom emojis
const filteredCustomEmoji = this.customEmojis.filter(emoji => emoji.name.includes(word))
const filtered = filteredNativeEmoji.concat(filteredCustomEmoji)
console.log(filtered)
if (filtered.length > 0) {
this.openSuggest = true
this.startIndex = start
Expand Down Expand Up @@ -160,8 +175,13 @@ export default {
}
},
insertItem (item) {
const str = `${this.status.slice(0, this.startIndex - 1)}${item.name} ${this.status.slice(this.startIndex + this.matchWord.length)}`
this.status = str
if (item.code) {
const str = `${this.status.slice(0, this.startIndex - 1)}${item.code} ${this.status.slice(this.startIndex + this.matchWord.length)}`
this.status = str
} else {
const str = `${this.status.slice(0, this.startIndex - 1)}${item.name} ${this.status.slice(this.startIndex + this.matchWord.length)}`
this.status = str
}
this.closeSuggest()
},
selectCurrentItem () {
Expand Down

0 comments on commit e273573

Please sign in to comment.