Add emoji suggestions to CW and poll option fields (#10555)
* Refactor selectComposeSuggestion so that different paths can be updated * Add suggestions in CW field * Add emoji suggestion to poll options * Attempt to fix CSS * Hide suggestions by default They will be enabled if the input has focus
This commit is contained in:
parent
62f5235b6f
commit
f2be71c293
10 changed files with 328 additions and 24 deletions
|
@ -131,13 +131,15 @@ function removeMedia(state, mediaId) {
|
|||
});
|
||||
};
|
||||
|
||||
const insertSuggestion = (state, position, token, completion) => {
|
||||
const insertSuggestion = (state, position, token, completion, path) => {
|
||||
return state.withMutations(map => {
|
||||
map.update('text', oldText => `${oldText.slice(0, position)}${completion} ${oldText.slice(position + token.length)}`);
|
||||
map.updateIn(path, oldText => `${oldText.slice(0, position)}${completion} ${oldText.slice(position + token.length)}`);
|
||||
map.set('suggestion_token', null);
|
||||
map.update('suggestions', ImmutableList(), list => list.clear());
|
||||
map.set('focusDate', new Date());
|
||||
map.set('caretPosition', position + completion.length + 1);
|
||||
map.set('suggestions', ImmutableList());
|
||||
if (path.length === 1 && path[0] === 'text') {
|
||||
map.set('focusDate', new Date());
|
||||
map.set('caretPosition', position + completion.length + 1);
|
||||
}
|
||||
map.set('idempotencyKey', uuid());
|
||||
});
|
||||
};
|
||||
|
@ -304,7 +306,7 @@ export default function compose(state = initialState, action) {
|
|||
case COMPOSE_SUGGESTIONS_READY:
|
||||
return state.set('suggestions', ImmutableList(action.accounts ? action.accounts.map(item => item.id) : action.emojis)).set('suggestion_token', action.token);
|
||||
case COMPOSE_SUGGESTION_SELECT:
|
||||
return insertSuggestion(state, action.position, action.token, action.completion);
|
||||
return insertSuggestion(state, action.position, action.token, action.completion, action.path);
|
||||
case COMPOSE_SUGGESTION_TAGS_UPDATE:
|
||||
return updateSuggestionTags(state, action.token);
|
||||
case COMPOSE_TAG_HISTORY_UPDATE:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue