flisk
6fdef479d0
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
~~(not intended for merging yet, just submitting this for preliminary review and discussion)~~ this patch adds a tab with recently used emojis to the emoji picker: https://akko.lain.gay/notice/ASoGCtyoiXbYPJjqpk there's a couple of things i'm ~~still trying to work out~~ not totally happy with and i'd appreciate any feedback on them: * the recentEmojis getter is called very frequently and has to do a possibly somewhat expensive lookup of emoji objects by their `displayName` each time, which i'm not sure is ideal * ~~emoji reactions on posts added through the picker are picked up by the recentEmojis module, but clicks on existing emoji reactions are not, because `addReaction` in `react_button.js` only currently receives the replacement and not the full emoji object (if there even is one wherever that method is called from)~~ this works now and does the same stupid full search of all emojis by their name which i guess is less bad because this only happens when you hit a reaction emoji button that already existed Reviewed-on: #283 Co-authored-by: flisk <akkomadev.mvch71fq@flisk.xyz> Co-committed-by: flisk <akkomadev.mvch71fq@flisk.xyz>
163 lines
4.3 KiB
JavaScript
163 lines
4.3 KiB
JavaScript
import { defineAsyncComponent } from 'vue'
|
|
import Checkbox from '../checkbox/checkbox.vue'
|
|
import EmojiGrid from '../emoji_grid/emoji_grid.vue'
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
import {
|
|
faBoxOpen,
|
|
faStickyNote,
|
|
faSmileBeam
|
|
} from '@fortawesome/free-solid-svg-icons'
|
|
import { trim, escapeRegExp, startCase } from 'lodash'
|
|
|
|
library.add(
|
|
faBoxOpen,
|
|
faStickyNote,
|
|
faSmileBeam
|
|
)
|
|
|
|
const EmojiPicker = {
|
|
props: {
|
|
enableStickerPicker: {
|
|
required: false,
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
showKeepOpen: {
|
|
required: false,
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
},
|
|
data () {
|
|
return {
|
|
keyword: '',
|
|
activeGroup: 'standard',
|
|
showingStickers: false,
|
|
keepOpen: false
|
|
}
|
|
},
|
|
components: {
|
|
StickerPicker: defineAsyncComponent(() => import('../sticker_picker/sticker_picker.vue')),
|
|
Checkbox,
|
|
EmojiGrid
|
|
},
|
|
methods: {
|
|
onStickerUploaded (e) {
|
|
this.$emit('sticker-uploaded', e)
|
|
},
|
|
onStickerUploadFailed (e) {
|
|
this.$emit('sticker-upload-failed', e)
|
|
},
|
|
onEmoji (emoji) {
|
|
const value = emoji.imageUrl ? `:${emoji.displayText}:` : emoji.replacement
|
|
this.$emit('emoji', { insertion: value, keepOpen: this.keepOpen })
|
|
this.$store.commit('emojiUsed', emoji)
|
|
},
|
|
onWheel (e) {
|
|
e.preventDefault()
|
|
this.$refs['emoji-tabs'].scrollBy(e.deltaY, 0)
|
|
},
|
|
highlight (key) {
|
|
this.setShowStickers(false)
|
|
this.activeGroup = key
|
|
if (this.keyword.length) {
|
|
this.$refs.emojiGrid.scrollToItem(key)
|
|
}
|
|
},
|
|
onActiveGroup (group) {
|
|
this.activeGroup = group
|
|
},
|
|
toggleStickers () {
|
|
this.showingStickers = !this.showingStickers
|
|
},
|
|
setShowStickers (value) {
|
|
this.showingStickers = value
|
|
},
|
|
filterByKeyword (list) {
|
|
if (this.keyword === '') return list
|
|
const regex = new RegExp(escapeRegExp(trim(this.keyword)), 'i')
|
|
return list.filter(emoji => {
|
|
return (regex.test(emoji.displayText) || (!emoji.imageUrl && emoji.replacement === this.keyword))
|
|
})
|
|
}
|
|
},
|
|
computed: {
|
|
activeGroupView () {
|
|
return this.showingStickers ? '' : this.activeGroup
|
|
},
|
|
stickersAvailable () {
|
|
if (this.$store.state.instance.stickers) {
|
|
return this.$store.state.instance.stickers.length > 0
|
|
}
|
|
return 0
|
|
},
|
|
filteredEmoji () {
|
|
return this.filterByKeyword(
|
|
this.$store.state.instance.customEmoji || []
|
|
)
|
|
},
|
|
emojis () {
|
|
const recentEmojis = this.$store.getters.recentEmojis
|
|
const standardEmojis = this.$store.state.instance.emoji || []
|
|
const customEmojis = this.sortedEmoji
|
|
const emojiPacks = []
|
|
customEmojis.forEach((pack, id) => {
|
|
emojiPacks.push({
|
|
id: id.replace(/^pack:/, ''),
|
|
text: startCase(id.replace(/^pack:/, '')),
|
|
first: pack[0],
|
|
emojis: this.filterByKeyword(pack)
|
|
})
|
|
})
|
|
return [
|
|
{
|
|
id: 'recent',
|
|
text: this.$t('emoji.recent'),
|
|
first: {
|
|
imageUrl: '',
|
|
replacement: '🕒',
|
|
},
|
|
emojis: this.filterByKeyword(recentEmojis)
|
|
},
|
|
{
|
|
id: 'standard',
|
|
text: this.$t('emoji.unicode'),
|
|
first: {
|
|
imageUrl: '',
|
|
replacement: '🥴'
|
|
},
|
|
emojis: this.filterByKeyword(standardEmojis)
|
|
}
|
|
].concat(emojiPacks)
|
|
},
|
|
sortedEmoji () {
|
|
const customEmojis = this.$store.state.instance.customEmoji || []
|
|
const sortedEmojiGroups = new Map()
|
|
customEmojis.forEach((emoji) => {
|
|
if (!sortedEmojiGroups.has(emoji.tags[0])) {
|
|
sortedEmojiGroups.set(emoji.tags[0], [emoji])
|
|
} else {
|
|
sortedEmojiGroups.get(emoji.tags[0]).push(emoji)
|
|
}
|
|
})
|
|
return new Map([...sortedEmojiGroups.entries()].sort())
|
|
},
|
|
emojisView () {
|
|
if (this.keyword === '') {
|
|
return this.emojis.filter(pack => {
|
|
return pack.id === this.activeGroup
|
|
})
|
|
} else {
|
|
return this.emojis.filter(pack => {
|
|
return pack.emojis.length > 0
|
|
})
|
|
}
|
|
},
|
|
stickerPickerEnabled () {
|
|
return (this.$store.state.instance.stickers || []).length !== 0 && this.enableStickerPicker
|
|
}
|
|
}
|
|
}
|
|
|
|
export default EmojiPicker
|