Make emoji picker use grouped unicode emojis

This commit is contained in:
Tusooa Zhu 2022-01-08 16:55:00 -05:00
parent d865f572aa
commit 8f4f02683f
No known key found for this signature in database
GPG Key ID: 7B467EDE43A08224
6 changed files with 48 additions and 22 deletions

View File

@ -2,7 +2,7 @@
* suggest - generates a suggestor function to be used by emoji-input * suggest - generates a suggestor function to be used by emoji-input
* data: object providing source information for specific types of suggestions: * data: object providing source information for specific types of suggestions:
* data.emoji - optional, an array of all emoji available i.e. * data.emoji - optional, an array of all emoji available i.e.
* (state.instance.emoji + state.instance.customEmoji) * (getters.standardEmojiList + state.instance.customEmoji)
* data.users - optional, an array of all known users * data.users - optional, an array of all known users
* updateUsersList - optional, a function to search and append to users * updateUsersList - optional, a function to search and append to users
* *

View File

@ -214,16 +214,18 @@ const EmojiPicker = {
defaultGroup () { defaultGroup () {
return Object.keys(this.allCustomGroups)[0] return Object.keys(this.allCustomGroups)[0]
}, },
unicodeEmojiGroups () {
return this.$store.getters.standardEmojiGroupList.map(group => ({
id: `standard-${group.id}`,
text: this.$t(`emoji.unicode_groups.${group.id}`),
icon: 'box-open',
emojis: group.emojis
}))
},
allEmojiGroups () { allEmojiGroups () {
const standardEmojis = this.$store.state.instance.emoji || []
return Object.entries(this.allCustomGroups) return Object.entries(this.allCustomGroups)
.map(([_, v]) => v) .map(([_, v]) => v)
.concat({ .concat(this.unicodeEmojiGroups)
id: 'standard',
text: this.$t('emoji.unicode'),
icon: 'box-open',
emojis: filterByKeyword(standardEmojis, this.keyword)
})
}, },
filteredEmojiGroups () { filteredEmojiGroups () {
return this.allEmojiGroups return this.allEmojiGroups

View File

@ -189,7 +189,7 @@ const PostStatusForm = {
emojiUserSuggestor () { emojiUserSuggestor () {
return suggestor({ return suggestor({
emoji: [ emoji: [
...this.$store.state.instance.emoji, ...this.$store.getters.standardEmojiList,
...this.$store.state.instance.customEmoji ...this.$store.state.instance.customEmoji
], ],
store: this.$store store: this.$store
@ -198,13 +198,13 @@ const PostStatusForm = {
emojiSuggestor () { emojiSuggestor () {
return suggestor({ return suggestor({
emoji: [ emoji: [
...this.$store.state.instance.emoji, ...this.$store.getters.standardEmojiList,
...this.$store.state.instance.customEmoji ...this.$store.state.instance.customEmoji
] ]
}) })
}, },
emoji () { emoji () {
return this.$store.state.instance.emoji || [] return this.$store.getters.standardEmojiList || []
}, },
customEmoji () { customEmoji () {
return this.$store.state.instance.customEmoji || [] return this.$store.state.instance.customEmoji || []

View File

@ -59,7 +59,7 @@ const ReactButton = {
if (this.filterWord !== '') { if (this.filterWord !== '') {
const filterWordLowercase = trim(this.filterWord.toLowerCase()) const filterWordLowercase = trim(this.filterWord.toLowerCase())
const orderedEmojiList = [] const orderedEmojiList = []
for (const emoji of this.$store.state.instance.emoji) { for (const emoji of this.$store.getters.standardEmojiList) {
if (emoji.replacement === this.filterWord) return [emoji] if (emoji.replacement === this.filterWord) return [emoji]
const indexOfFilterWord = emoji.displayText.toLowerCase().indexOf(filterWordLowercase) const indexOfFilterWord = emoji.displayText.toLowerCase().indexOf(filterWordLowercase)
@ -72,7 +72,7 @@ const ReactButton = {
} }
return orderedEmojiList.flat() return orderedEmojiList.flat()
} }
return this.$store.state.instance.emoji || [] return this.$store.getters.standardEmojiList || []
}, },
mergedConfig () { mergedConfig () {
return this.$store.getters.mergedConfig return this.$store.getters.mergedConfig

View File

@ -64,7 +64,7 @@ const ProfileTab = {
emojiUserSuggestor () { emojiUserSuggestor () {
return suggestor({ return suggestor({
emoji: [ emoji: [
...this.$store.state.instance.emoji, ...this.$store.getters.standardEmojiList,
...this.$store.state.instance.customEmoji ...this.$store.state.instance.customEmoji
], ],
store: this.$store store: this.$store
@ -73,7 +73,7 @@ const ProfileTab = {
emojiSuggestor () { emojiSuggestor () {
return suggestor({ return suggestor({
emoji: [ emoji: [
...this.$store.state.instance.emoji, ...this.$store.getters.standardEmojiList,
...this.$store.state.instance.customEmoji ...this.$store.state.instance.customEmoji
] ]
}) })

View File

@ -3,6 +3,18 @@ import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
import apiService from '../services/api/api.service.js' import apiService from '../services/api/api.service.js'
import { instanceDefaultProperties } from './config.js' import { instanceDefaultProperties } from './config.js'
const SORTED_EMOJI_GROUP_IDS = [
'smileys-and-emotion',
'people-and-body',
'animals-and-nature',
'food-and-drink',
'travel-and-places',
'activities',
'objects',
'symbols',
'flags'
]
const defaultState = { const defaultState = {
// Stuff from apiConfig // Stuff from apiConfig
name: 'Pleroma FE', name: 'Pleroma FE',
@ -64,7 +76,7 @@ const defaultState = {
// Nasty stuff // Nasty stuff
customEmoji: [], customEmoji: [],
customEmojiFetched: false, customEmojiFetched: false,
emoji: [], emoji: {},
emojiFetched: false, emojiFetched: false,
pleromaBackend: true, pleromaBackend: true,
postFormats: [], postFormats: [],
@ -139,6 +151,17 @@ const instance = {
return res return res
}, {}) }, {})
}, },
standardEmojiList (state) {
return SORTED_EMOJI_GROUP_IDS
.map(groupId => state.emoji[groupId] || [])
.reduce((a, b) => a.concat(b), [])
},
standardEmojiGroupList (state) {
return SORTED_EMOJI_GROUP_IDS.map(groupId => ({
id: groupId,
emojis: state.emoji[groupId] || []
}))
},
instanceDomain (state) { instanceDomain (state) {
return new URL(state.server).hostname return new URL(state.server).hostname
} }
@ -165,13 +188,14 @@ const instance = {
const res = await window.fetch('/static/emoji.json') const res = await window.fetch('/static/emoji.json')
if (res.ok) { if (res.ok) {
const values = await res.json() const values = await res.json()
const emoji = Object.keys(values).map((key) => { const emoji = Object.keys(values).reduce((res, groupId) => {
return { res[groupId] = values[groupId].map(e => ({
displayText: key, displayText: e.name,
imageUrl: false, imageUrl: false,
replacement: values[key] replacement: e.emoji
} }))
}).sort((a, b) => a.name > b.name ? 1 : -1) return res
}, {})
commit('setInstanceOption', { name: 'emoji', value: emoji }) commit('setInstanceOption', { name: 'emoji', value: emoji })
} else { } else {
throw (res) throw (res)