This commit is contained in:
Henry Jameson 2019-06-18 21:30:35 +03:00
parent e5020d6936
commit 0032802f0a
4 changed files with 61 additions and 65 deletions

View file

@ -8,7 +8,7 @@ import { take } from 'lodash'
* Intended usage is: * Intended usage is:
* <emoji-input v-model="something"> * <emoji-input v-model="something">
* <input v-model="something"/> * <input v-model="something"/>
* </emoji-input> * </EmojiInput>
* *
* Works only with <input> and <textarea>. Intended to use with only one nested * Works only with <input> and <textarea>. Intended to use with only one nested
* input. It will find first input or textarea and work with that, multiple * input. It will find first input or textarea and work with that, multiple

View file

@ -21,8 +21,7 @@ export default function suggest (data) {
} }
} }
function suggestEmoji (emojis) { export const suggestEmoji = (emojis) => input => {
return input => {
const noPrefix = input.toLowerCase().substr(1) const noPrefix = input.toLowerCase().substr(1)
return emojis return emojis
.filter(({ displayText }) => displayText.toLowerCase().startsWith(noPrefix)) .filter(({ displayText }) => displayText.toLowerCase().startsWith(noPrefix))
@ -31,8 +30,8 @@ function suggestEmoji (emojis) {
let bScore = 0 let bScore = 0
// Make custom emojis a priority // Make custom emojis a priority
aScore += Number(!!a.imageUrl) * 10 aScore += a.imageUrl ? 10 : 0
bScore += Number(!!b.imageUrl) * 10 bScore += b.imageUrl ? 10 : 0
// Sort alphabetically // Sort alphabetically
const alphabetically = a.displayText > b.displayText ? 1 : -1 const alphabetically = a.displayText > b.displayText ? 1 : -1
@ -40,10 +39,8 @@ function suggestEmoji (emojis) {
return bScore - aScore + alphabetically return bScore - aScore + alphabetically
}) })
} }
}
function suggestUsers (users) { export const suggestUsers = (users) => input => {
return input => {
const noPrefix = input.toLowerCase().substr(1) const noPrefix = input.toLowerCase().substr(1)
return users.filter( return users.filter(
user => user =>
@ -59,14 +56,14 @@ function suggestUsers (users) {
let bScore = 0 let bScore = 0
// Matches on screen name (i.e. user@instance) makes a priority // Matches on screen name (i.e. user@instance) makes a priority
aScore += a.screen_name.toLowerCase().startsWith(noPrefix) * 2 aScore += a.screen_name.toLowerCase().startsWith(noPrefix) ? 2 : 0
bScore += b.screen_name.toLowerCase().startsWith(noPrefix) * 2 bScore += b.screen_name.toLowerCase().startsWith(noPrefix) ? 2 : 0
// Matches on name takes second priority // Matches on name takes second priority
aScore += a.name.toLowerCase().startsWith(noPrefix) aScore += a.name.toLowerCase().startsWith(noPrefix) ? 1 : 0
bScore += b.name.toLowerCase().startsWith(noPrefix) bScore += b.name.toLowerCase().startsWith(noPrefix) ? 1 : 0
const diff = bScore * 10 - aScore * 10 const diff = (bScore - aScore) * 10
// Then sort alphabetically // Then sort alphabetically
const nameAlphabetically = a.name > b.name ? 1 : -1 const nameAlphabetically = a.name > b.name ? 1 : -1
@ -82,4 +79,3 @@ function suggestUsers (users) {
})) }))
/* eslint-enable camelcase */ /* eslint-enable camelcase */
} }
}

View file

@ -31,7 +31,7 @@
<span v-if="safeDMEnabled">{{ $t('post_status.direct_warning_to_first_only') }}</span> <span v-if="safeDMEnabled">{{ $t('post_status.direct_warning_to_first_only') }}</span>
<span v-else>{{ $t('post_status.direct_warning_to_all') }}</span> <span v-else>{{ $t('post_status.direct_warning_to_all') }}</span>
</p> </p>
<emoji-input <EmojiInput
v-if="newStatus.spoilerText || alwaysShowSubject" v-if="newStatus.spoilerText || alwaysShowSubject"
:suggest="emojiSuggestor" :suggest="emojiSuggestor"
v-model="newStatus.spoilerText" v-model="newStatus.spoilerText"
@ -44,8 +44,8 @@
v-model="newStatus.spoilerText" v-model="newStatus.spoilerText"
class="form-post-subject" class="form-post-subject"
/> />
</emoji-input> </EmojiInput>
<emoji-input <EmojiInput
:suggest="emojiUserSuggestor" :suggest="emojiUserSuggestor"
v-model="newStatus.status" v-model="newStatus.status"
class="form-control" class="form-control"
@ -65,7 +65,7 @@
class="form-post-body" class="form-post-body"
> >
</textarea> </textarea>
</emoji-input> </EmojiInput>
<div class="visibility-tray"> <div class="visibility-tray">
<div class="text-format" v-if="formattingOptionsEnabled"> <div class="text-format" v-if="formattingOptionsEnabled">
<label for="post-content-type" class="select"> <label for="post-content-type" class="select">

View file

@ -22,20 +22,20 @@
<div class="setting-item" > <div class="setting-item" >
<h2>{{$t('settings.name_bio')}}</h2> <h2>{{$t('settings.name_bio')}}</h2>
<p>{{$t('settings.name')}}</p> <p>{{$t('settings.name')}}</p>
<emoji-input :suggest="emojiSuggestor" v-model="newName"> <EmojiInput :suggest="emojiSuggestor" v-model="newName">
<input <input
v-model="newName" v-model="newName"
id="username" id="username"
classname="name-changer" classname="name-changer"
/> />
</emoji-input> </EmojiInput>
<p>{{$t('settings.bio')}}</p> <p>{{$t('settings.bio')}}</p>
<emoji-input :suggest="emojiUserSuggestor" v-model="newBio"> <EmojiInput :suggest="emojiUserSuggestor" v-model="newBio">
<textarea <textarea
v-model="newBio" v-model="newBio"
classname="bio" classname="bio"
/> />
</emoji-input> </EmojiInput>
<p> <p>
<input type="checkbox" v-model="newLocked" id="account-locked"> <input type="checkbox" v-model="newLocked" id="account-locked">
<label for="account-locked">{{$t('settings.lock_account_description')}}</label> <label for="account-locked">{{$t('settings.lock_account_description')}}</label>