refactor some stuff (#274)
This commit is contained in:
parent
ee12ec9549
commit
5a1e10dee0
|
@ -1,3 +1,5 @@
|
||||||
|
import get from 'lodash-es/get'
|
||||||
|
|
||||||
const MIN_PREFIX_LENGTH = 1
|
const MIN_PREFIX_LENGTH = 1
|
||||||
const ACCOUNT_SEARCH_REGEX = new RegExp(`(?:\\s|^)(@\\S{${MIN_PREFIX_LENGTH},})$`)
|
const ACCOUNT_SEARCH_REGEX = new RegExp(`(?:\\s|^)(@\\S{${MIN_PREFIX_LENGTH},})$`)
|
||||||
const EMOJI_SEARCH_REGEX = new RegExp(`(?:\\s|^)(:[^:]{${MIN_PREFIX_LENGTH},})$`)
|
const EMOJI_SEARCH_REGEX = new RegExp(`(?:\\s|^)(:[^:]{${MIN_PREFIX_LENGTH},})$`)
|
||||||
|
@ -5,10 +7,10 @@ const EMOJI_SEARCH_REGEX = new RegExp(`(?:\\s|^)(:[^:]{${MIN_PREFIX_LENGTH},})$`
|
||||||
function computeForAutosuggest (store, key, defaultValue) {
|
function computeForAutosuggest (store, key, defaultValue) {
|
||||||
store.compute(key,
|
store.compute(key,
|
||||||
['currentInstance', 'currentComposeRealm', `autosuggestData_${key}`],
|
['currentInstance', 'currentComposeRealm', `autosuggestData_${key}`],
|
||||||
(currentInstance, currentComposeRealm, root) => {
|
(currentInstance, currentComposeRealm, root) => (
|
||||||
let instanceData = root && root[currentInstance]
|
get(root, [currentInstance, currentComposeRealm], defaultValue)
|
||||||
return (currentComposeRealm && instanceData && currentComposeRealm in instanceData) ? instanceData[currentComposeRealm] : defaultValue
|
)
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function autosuggestComputations (store) {
|
export function autosuggestComputations (store) {
|
||||||
|
@ -22,7 +24,8 @@ export function autosuggestComputations (store) {
|
||||||
'currentComposeText',
|
'currentComposeText',
|
||||||
['currentComposeData', 'currentComposeRealm'],
|
['currentComposeData', 'currentComposeRealm'],
|
||||||
(currentComposeData, currentComposeRealm) => (
|
(currentComposeData, currentComposeRealm) => (
|
||||||
currentComposeData[currentComposeRealm] && currentComposeData[currentComposeRealm].text) || ''
|
get(currentComposeData, [currentComposeRealm, 'text'], '')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
store.compute(
|
store.compute(
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
|
import get from 'lodash-es/get'
|
||||||
|
|
||||||
function computeForTimeline (store, key, defaultValue) {
|
function computeForTimeline (store, key, defaultValue) {
|
||||||
store.compute(key,
|
store.compute(key,
|
||||||
['currentInstance', 'currentTimeline', `timelineData_${key}`],
|
['currentInstance', 'currentTimeline', `timelineData_${key}`],
|
||||||
(currentInstance, currentTimeline, root) => {
|
(currentInstance, currentTimeline, root) => (
|
||||||
let instanceData = root && root[currentInstance]
|
get(root, [currentInstance, currentTimeline], defaultValue)
|
||||||
return (currentTimeline && instanceData && currentTimeline in instanceData) ? instanceData[currentTimeline] : defaultValue
|
)
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function timelineComputations (store) {
|
export function timelineComputations (store) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import pickBy from 'lodash-es/pickBy'
|
import pickBy from 'lodash-es/pickBy'
|
||||||
|
import get from 'lodash-es/get'
|
||||||
|
|
||||||
export function timelineMixins (Store) {
|
export function timelineMixins (Store) {
|
||||||
Store.prototype.setForTimeline = function (instanceName, timelineName, obj) {
|
Store.prototype.setForTimeline = function (instanceName, timelineName, obj) {
|
||||||
|
@ -17,7 +18,7 @@ export function timelineMixins (Store) {
|
||||||
Store.prototype.getForTimeline = function (instanceName, timelineName, key) {
|
Store.prototype.getForTimeline = function (instanceName, timelineName, key) {
|
||||||
let rootKey = `timelineData_${key}`
|
let rootKey = `timelineData_${key}`
|
||||||
let root = this.get()[rootKey]
|
let root = this.get()[rootKey]
|
||||||
return root && root[instanceName] && root[instanceName][timelineName]
|
return get(root, [instanceName, timelineName])
|
||||||
}
|
}
|
||||||
|
|
||||||
Store.prototype.getForCurrentTimeline = function (key) {
|
Store.prototype.getForCurrentTimeline = function (key) {
|
||||||
|
|
|
@ -28,15 +28,14 @@ export function autosuggestObservers (store) {
|
||||||
if (!composeFocused || !autosuggestSearchText) {
|
if (!composeFocused || !autosuggestSearchText) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let type = autosuggestSearchText.startsWith('@') ? 'account' : 'emoji'
|
let autosuggestType = autosuggestSearchText.startsWith('@') ? 'account' : 'emoji'
|
||||||
let results = (type === 'account')
|
let results = (autosuggestType === 'account')
|
||||||
? await searchAccounts(store, autosuggestSearchText)
|
? await searchAccounts(store, autosuggestSearchText)
|
||||||
: await searchEmoji(store, autosuggestSearchText)
|
: await searchEmoji(store, autosuggestSearchText)
|
||||||
store.setForCurrentAutosuggest({
|
store.setForCurrentAutosuggest({
|
||||||
|
autosuggestType,
|
||||||
autosuggestSelected: 0,
|
autosuggestSelected: 0,
|
||||||
autosuggestSearchText: autosuggestSearchText,
|
autosuggestSearchResults: results
|
||||||
autosuggestSearchResults: results,
|
|
||||||
autosuggestType: type
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue