Merge branch 'feat/reorder-emojis-by-position-of-keyword' into 'develop'

feat/reorder-emojis-by-position-of-keyword

See merge request pleroma/pleroma-fe!1240
This commit is contained in:
Shpuld Shpludson 2020-10-13 15:00:06 +00:00
commit 0e14cd6102
2 changed files with 24 additions and 6 deletions

View file

@ -8,10 +8,20 @@ const LOAD_EMOJI_BY = 60
const LOAD_EMOJI_MARGIN = 64 const LOAD_EMOJI_MARGIN = 64
const filterByKeyword = (list, keyword = '') => { const filterByKeyword = (list, keyword = '') => {
if (keyword === '') return list
const keywordLowercase = keyword.toLowerCase() const keywordLowercase = keyword.toLowerCase()
return list.filter(emoji => let orderedEmojiList = []
emoji.displayText.toLowerCase().includes(keywordLowercase) for (const emoji of list) {
) const indexOfKeyword = emoji.displayText.toLowerCase().indexOf(keywordLowercase)
if (indexOfKeyword > -1) {
if (!Array.isArray(orderedEmojiList[indexOfKeyword])) {
orderedEmojiList[indexOfKeyword] = []
}
orderedEmojiList[indexOfKeyword].push(emoji)
}
}
return orderedEmojiList.flat()
} }
const EmojiPicker = { const EmojiPicker = {

View file

@ -28,9 +28,17 @@ const ReactButton = {
emojis () { emojis () {
if (this.filterWord !== '') { if (this.filterWord !== '') {
const filterWordLowercase = this.filterWord.toLowerCase() const filterWordLowercase = this.filterWord.toLowerCase()
return this.$store.state.instance.emoji.filter(emoji => let orderedEmojiList = []
emoji.displayText.toLowerCase().includes(filterWordLowercase) for (const emoji of this.$store.state.instance.emoji) {
) const indexOfFilterWord = emoji.displayText.toLowerCase().indexOf(filterWordLowercase)
if (indexOfFilterWord > -1) {
if (!Array.isArray(orderedEmojiList[indexOfFilterWord])) {
orderedEmojiList[indexOfFilterWord] = []
}
orderedEmojiList[indexOfFilterWord].push(emoji)
}
}
return orderedEmojiList.flat()
} }
return this.$store.state.instance.emoji || [] return this.$store.state.instance.emoji || []
}, },