Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma-fe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pleroma
pleroma-fe
Commits
20923d59
Commit
20923d59
authored
5 years ago
by
HJ
Browse files
Options
Downloads
Patches
Plain Diff
Some comments, added sorting for emojis
parent
76b9a66e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!1028
`master` refresh with `develop`
,
!824
EmojiInput refactoring
Pipeline
#12964
failed
5 years ago
Stage: lint
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/emoji-input/suggestor.js
+22
-6
22 additions, 6 deletions
src/components/emoji-input/suggestor.js
with
22 additions
and
6 deletions
src/components/emoji-input/suggestor.js
+
22
−
6
View file @
20923d59
export
default
function
suggest
(
data
)
{
return
input
=>
{
const
trimmed
=
input
.
trim
()
const
firstChar
=
trimmed
[
0
]
console
.
log
(
`'
${
trimmed
}
'`
,
firstChar
,
firstChar
===
'
:
'
)
const
firstChar
=
input
[
0
]
if
(
firstChar
===
'
:
'
&&
data
.
emoji
)
{
return
suggestEmoji
(
data
.
emoji
)(
trimmed
)
return
suggestEmoji
(
data
.
emoji
)(
input
)
}
if
(
firstChar
===
'
@
'
&&
data
.
users
)
{
return
suggestUsers
(
data
.
users
)(
trimmed
)
return
suggestUsers
(
data
.
users
)(
input
)
}
return
[]
}
...
...
@@ -18,6 +16,19 @@ function suggestEmoji (emojis) {
const
noPrefix
=
input
.
toLowerCase
().
substr
(
1
)
return
emojis
.
filter
(({
displayText
})
=>
displayText
.
toLowerCase
().
startsWith
(
noPrefix
))
.
sort
((
a
,
b
)
=>
{
let
aScore
=
0
let
bScore
=
0
// Make custom emojis a priority
aScore
+=
Number
(
!!
a
.
imageUrl
)
*
10
bScore
+=
Number
(
!!
b
.
imageUrl
)
*
10
// Sort alphabetically
const
alphabetically
=
a
.
displayText
>
b
.
displayText
?
1
:
-
1
return
bScore
-
aScore
+
alphabetically
})
}
}
...
...
@@ -33,12 +44,17 @@ function suggestUsers (users) {
let
aScore
=
0
let
bScore
=
0
// Matches on screen name (i.e. user@instance) makes a priority
aScore
+=
a
.
screen_name
.
toLowerCase
().
startsWith
(
noPrefix
)
*
2
aScore
+=
a
.
name
.
toLowerCase
().
startsWith
(
noPrefix
)
bScore
+=
b
.
screen_name
.
toLowerCase
().
startsWith
(
noPrefix
)
*
2
// Matches on name takes second priority
aScore
+=
a
.
name
.
toLowerCase
().
startsWith
(
noPrefix
)
bScore
+=
b
.
name
.
toLowerCase
().
startsWith
(
noPrefix
)
const
diff
=
bScore
*
10
-
aScore
*
10
// Then sort alphabetically
const
nameAlphabetically
=
a
.
name
>
b
.
name
?
1
:
-
1
const
screenNameAlphabetically
=
a
.
screen_name
>
b
.
screen_name
?
1
:
-
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment