fix uniq issue
This commit is contained in:
parent
bfa383a337
commit
7a5c61b0c4
|
@ -38,6 +38,7 @@
|
|||
"emojibase-data": "^5.0.1",
|
||||
"esm": "^3.2.25",
|
||||
"if-emoji": "^0.1.0",
|
||||
"lodash-es": "^4.17.15",
|
||||
"rollup": "^2.8.2",
|
||||
"rollup-plugin-svelte": "^5.2.1",
|
||||
"standard": "^14.3.3",
|
||||
|
|
|
@ -8,14 +8,17 @@ import { versionsAndTestEmoji } from './bin/versionsAndTestEmoji'
|
|||
const baseConfig = {
|
||||
plugins: [
|
||||
resolve(),
|
||||
cjs(),
|
||||
cjs({
|
||||
exclude: ['node_modules/lodash-es/**']
|
||||
}),
|
||||
json(),
|
||||
replace({
|
||||
'process.env.VERSIONS_AND_TEST_EMOJI': JSON.stringify(versionsAndTestEmoji)
|
||||
}),
|
||||
svelte({
|
||||
css: true,
|
||||
customElement: true,
|
||||
css: true
|
||||
dev: process.env.NODE_ENV !== 'production'
|
||||
})
|
||||
]
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import { assertETag } from './utils/assertETag'
|
|||
import { assertEmojiBaseData } from './utils/assertEmojiBaseData'
|
||||
import { assertNumber } from './utils/assertNumber'
|
||||
import { DEFAULT_DATA_SOURCE, DEFAULT_LOCALE } from './constants'
|
||||
import { uniqEmoji } from './utils/uniqEmoji'
|
||||
|
||||
export class Database {
|
||||
constructor ({ dataSource = DEFAULT_DATA_SOURCE, locale = DEFAULT_LOCALE } = {}) {
|
||||
|
@ -44,19 +45,22 @@ export class Database {
|
|||
async getEmojiByGroup (group) {
|
||||
assertNumber(group)
|
||||
await this._readyPromise
|
||||
return this._idbEngine.getEmojiByGroup(group)
|
||||
const emojis = await this._idbEngine.getEmojiByGroup(group)
|
||||
return uniqEmoji(emojis)
|
||||
}
|
||||
|
||||
async getEmojiBySearchPrefix (prefix) {
|
||||
assertNonEmptyString(prefix)
|
||||
await this._readyPromise
|
||||
return this._idbEngine.getEmojiBySearchPrefix(prefix)
|
||||
const emojis = await this._idbEngine.getEmojiBySearchPrefix(prefix)
|
||||
return uniqEmoji(emojis)
|
||||
}
|
||||
|
||||
async getEmojiByShortcode (shortcode) {
|
||||
assertNonEmptyString(shortcode)
|
||||
await this._readyPromise
|
||||
return this._idbEngine.getEmojiByShortcode(shortcode)
|
||||
const emojis = await this._idbEngine.getEmojiByShortcode(shortcode)
|
||||
return uniqEmoji(emojis)
|
||||
}
|
||||
|
||||
async getEmojiByUnicode (unicode) {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import uniqBy from 'lodash-es/uniqBy'
|
||||
|
||||
export function uniqEmoji (emojis) {
|
||||
return uniqBy(emojis, _ => _.unicode)
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
aria-label={i18n.categories[currentCategory.name]}
|
||||
id="lite-emoji-picker-tab-{currentCategory.group}">
|
||||
<div class="lep-emoji-menu" role="menu">
|
||||
{#each currentEmojis as emoji (emoji.order)}
|
||||
{#each currentEmojis as emoji (emoji.unicode)}
|
||||
<button role="menuitem" class="lep-emoji">
|
||||
{emoji.unicode}
|
||||
</button>
|
||||
|
@ -93,17 +93,18 @@
|
|||
let searchText = ''
|
||||
$: database = new Database({ dataSource, locale })
|
||||
$: {
|
||||
getEmojisByGroup(currentCategory.group).then(emojis => {
|
||||
currentEmojis = emojis
|
||||
})
|
||||
(async () => {
|
||||
currentEmojis = await getEmojisByGroup(currentCategory.group)
|
||||
})()
|
||||
}
|
||||
$: {
|
||||
if (searchText.length >= MIN_SEARCH_TEXT_LENGTH) {
|
||||
database.getEmojiBySearchPrefix(searchText).then(emojis => {
|
||||
console.log('emojis', emojis)
|
||||
currentEmojis = emojis
|
||||
})
|
||||
}
|
||||
(async () => {
|
||||
if (searchText.length >= MIN_SEARCH_TEXT_LENGTH) {
|
||||
currentEmojis = await getEmojisBySearchPrefix(searchText)
|
||||
} else {
|
||||
currentEmojis = await getEmojisByGroup(currentCategory.group)
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
||||
function filterEmojis (emojis) {
|
||||
|
|
|
@ -980,6 +980,11 @@ locate-path@^3.0.0:
|
|||
p-locate "^3.0.0"
|
||||
path-exists "^3.0.0"
|
||||
|
||||
lodash-es@^4.17.15:
|
||||
version "4.17.15"
|
||||
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78"
|
||||
integrity sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ==
|
||||
|
||||
lodash@^4.17.14, lodash@^4.17.15:
|
||||
version "4.17.15"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
|
||||
|
|
Loading…
Reference in New Issue