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 ACCOUNT_SEARCH_REGEX = new RegExp(`(?:\\s|^)(@\\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) {
|
||||
store.compute(key,
|
||||
['currentInstance', 'currentComposeRealm', `autosuggestData_${key}`],
|
||||
(currentInstance, currentComposeRealm, root) => {
|
||||
let instanceData = root && root[currentInstance]
|
||||
return (currentComposeRealm && instanceData && currentComposeRealm in instanceData) ? instanceData[currentComposeRealm] : defaultValue
|
||||
})
|
||||
(currentInstance, currentComposeRealm, root) => (
|
||||
get(root, [currentInstance, currentComposeRealm], defaultValue)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export function autosuggestComputations (store) {
|
||||
|
@ -22,7 +24,8 @@ export function autosuggestComputations (store) {
|
|||
'currentComposeText',
|
||||
['currentComposeData', 'currentComposeRealm'],
|
||||
(currentComposeData, currentComposeRealm) => (
|
||||
currentComposeData[currentComposeRealm] && currentComposeData[currentComposeRealm].text) || ''
|
||||
get(currentComposeData, [currentComposeRealm, 'text'], '')
|
||||
)
|
||||
)
|
||||
|
||||
store.compute(
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import get from 'lodash-es/get'
|
||||
|
||||
function computeForTimeline (store, key, defaultValue) {
|
||||
store.compute(key,
|
||||
['currentInstance', 'currentTimeline', `timelineData_${key}`],
|
||||
(currentInstance, currentTimeline, root) => {
|
||||
let instanceData = root && root[currentInstance]
|
||||
return (currentTimeline && instanceData && currentTimeline in instanceData) ? instanceData[currentTimeline] : defaultValue
|
||||
})
|
||||
(currentInstance, currentTimeline, root) => (
|
||||
get(root, [currentInstance, currentTimeline], defaultValue)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export function timelineComputations (store) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import pickBy from 'lodash-es/pickBy'
|
||||
import get from 'lodash-es/get'
|
||||
|
||||
export function timelineMixins (Store) {
|
||||
Store.prototype.setForTimeline = function (instanceName, timelineName, obj) {
|
||||
|
@ -17,7 +18,7 @@ export function timelineMixins (Store) {
|
|||
Store.prototype.getForTimeline = function (instanceName, timelineName, key) {
|
||||
let rootKey = `timelineData_${key}`
|
||||
let root = this.get()[rootKey]
|
||||
return root && root[instanceName] && root[instanceName][timelineName]
|
||||
return get(root, [instanceName, timelineName])
|
||||
}
|
||||
|
||||
Store.prototype.getForCurrentTimeline = function (key) {
|
||||
|
|
|
@ -28,15 +28,14 @@ export function autosuggestObservers (store) {
|
|||
if (!composeFocused || !autosuggestSearchText) {
|
||||
return
|
||||
}
|
||||
let type = autosuggestSearchText.startsWith('@') ? 'account' : 'emoji'
|
||||
let results = (type === 'account')
|
||||
let autosuggestType = autosuggestSearchText.startsWith('@') ? 'account' : 'emoji'
|
||||
let results = (autosuggestType === 'account')
|
||||
? await searchAccounts(store, autosuggestSearchText)
|
||||
: await searchEmoji(store, autosuggestSearchText)
|
||||
store.setForCurrentAutosuggest({
|
||||
autosuggestType,
|
||||
autosuggestSelected: 0,
|
||||
autosuggestSearchText: autosuggestSearchText,
|
||||
autosuggestSearchResults: results,
|
||||
autosuggestType: type
|
||||
autosuggestSearchResults: results
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue