Skip to content

Commit

Permalink
✨ Make fuzzy gitmoji search
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Dec 27, 2019
1 parent 03d06ee commit 1669034
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
14 changes: 5 additions & 9 deletions src/commands/commit/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import inquirer from 'inquirer'

import configurationVault from '../../utils/configurationVault'
import filterGitmojis from '../../utils/filterGitmojis'
import guard from './guard'

const TITLE_MAX_LENGTH_COUNT: number = 48
Expand Down Expand Up @@ -29,15 +30,10 @@ export default (gitmojis: Array<Gitmoji>): Array<Object> => [
type: 'autocomplete',
source: (answersSoFor: any, input: string) => {
return Promise.resolve(
gitmojis
.filter((gitmoji) => {
const emoji = gitmoji.name.concat(gitmoji.description).toLowerCase()
return !input || emoji.indexOf(input.toLowerCase()) !== -1
})
.map((gitmoji) => ({
name: `${gitmoji.emoji} - ${gitmoji.description}`,
value: gitmoji[configurationVault.getEmojiFormat()]
}))
filterGitmojis(input, gitmojis).map((gitmoji) => ({
name: `${gitmoji.emoji} - ${gitmoji.description}`,
value: gitmoji[configurationVault.getEmojiFormat()]
}))
)
}
},
Expand Down
8 changes: 2 additions & 6 deletions src/commands/search/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
// @flow
import filterGitmojis from '../../utils/filterGitmojis'
import getEmojis from '../../utils/getEmojis'
import printEmojis from '../../utils/printEmojis'

const search = (query: string) => {
console.log('query', query)
return getEmojis()
.then((gitmojis) => {
return gitmojis.filter((gitmoji) => {
const emoji = gitmoji.name.concat(gitmoji.description).toLowerCase()
return emoji.indexOf(query.toLowerCase()) !== -1
})
})
.then((gitmojis) => filterGitmojis(query, gitmojis))
.then((gitmojisFiltered) => printEmojis(gitmojisFiltered))
.catch((err) => console.error(err))
}
Expand Down

0 comments on commit 1669034

Please sign in to comment.