Skip to content

Commit

Permalink
feat: Smart search (#146)
Browse files Browse the repository at this point in the history
Co-authored-by: Jakub Grzywacz <kontakt@jakubgrzywacz.pl>
  • Loading branch information
mateki0 and jakex7 authored Jul 20, 2023
1 parent 5271f43 commit f6e55d2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"react-test-renderer": "16.13.1",
"release-it": "^14.2.2",
"typescript": "^4.1.3",
"unicode-emoji-json": "^0.4.0"
"unicode-emoji-json": "^0.4.0",
"emojilib": "^3.0.10"
},
"peerDependencies": {
"react": "*",
Expand Down Expand Up @@ -137,6 +138,5 @@
}
]
]
},
"dependencies": {}
}
}
16 changes: 10 additions & 6 deletions scripts/generateIcons.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const json = require('unicode-emoji-json/data-by-group.json')
const fs = require('fs')
const emojisWithKeywords = require('emojilib')

const newArray = []
for (const [key, value] of Object.entries(json)) {
const newData = value
.filter((emoji) => parseFloat(emoji.unicode_version) < 12)
.map((emoji) => ({
emoji: emoji.emoji,
name: emoji.name,
v: emoji.unicode_version,
toneEnabled: emoji.skin_tone_support,
}))
.map((emoji) => {
return {
emoji: emoji.emoji,
name: emoji.name,
v: emoji.unicode_version,
toneEnabled: emoji.skin_tone_support,
keywords: emojisWithKeywords[emoji.emoji],
}
})
newArray.push({
title: key.replace(/ & /g, '_').replace(/ /g, '_').toLocaleLowerCase(),
data: newData,
Expand Down
2 changes: 1 addition & 1 deletion src/assets/emojis.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/contexts/KeyboardProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,18 @@ export const KeyboardProvider: React.FC<ProviderProps> = React.memo((props) => {
.flat()
.filter((emoji) => {
if (searchPhrase.length < 2) return false

const isInKeywords =
emoji?.keywords &&
emoji.keywords.length > 0 &&
emoji.keywords.some((keyword) =>
keyword.toLowerCase().includes(searchPhrase.toLowerCase())
)

return (
emoji.name.toLowerCase().includes(searchPhrase.toLowerCase()) ||
emoji.emoji.toLowerCase().includes(searchPhrase)
emoji.emoji.toLowerCase().includes(searchPhrase) ||
isInKeywords
)
}),
})
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type JsonEmoji = {
name: string
v: string
toneEnabled: boolean
keywords?: string[]
}

export type ToneSelectorEmoji = Omit<JsonEmoji, 'toneEnabled'> & { index: string }
Expand Down
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3766,6 +3766,11 @@ emoji-regex@^8.0.0:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==

emojilib@^3.0.10:
version "3.0.10"
resolved "https://registry.yarnpkg.com/emojilib/-/emojilib-3.0.10.tgz#e2f9baaee5fabbc1e011ebd3aa2761b65e4da02f"
integrity sha512-VQtCRroFykPTJaoEBEGFg5tI+rEluabjuaVDDbSftDtiRJ5GuqRG/LGV1mmDzkJP4bh5rzuEBOafMN68/YXQcQ==

encodeurl@~1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
Expand Down Expand Up @@ -9099,10 +9104,10 @@ unicode-canonical-property-names-ecmascript@^1.0.4:
resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818"
integrity sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==

unicode-emoji-json@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/unicode-emoji-json/-/unicode-emoji-json-0.3.1.tgz#495ddf9a3483da91d25a1a4817249f4b3a5ab03f"
integrity sha512-qA76zUIfOMSj+rdd8XAz/SpuubjTqoy2uW+dHrUVZivIvzMYzs7lNlbLMG4R32KB8SFwtVUJYQzbAafjBYDSuw==
unicode-emoji-json@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/unicode-emoji-json/-/unicode-emoji-json-0.4.0.tgz#021dd9a917b8af90756cf1eba21fda7b8e0ee5af"
integrity sha512-lVNOwh2AnmbwqtSrEVjAWKQoVzWgyWmXVqPuPkPfKb0tnA0+uYN/4ILCTdy9IRj/+3drAVhmjwjNJQr2dhCwnA==

unicode-match-property-ecmascript@^1.0.4:
version "1.0.4"
Expand Down

0 comments on commit f6e55d2

Please sign in to comment.