Revert "Merge pull request #149 from glitch-soc/mojon-suggest"
This reverts commitfa3587645d
, reversing changes made to15c9c2fd7e
.
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import api from '../api';
|
||||
import emojione from 'emojione';
|
||||
|
||||
import {
|
||||
updateTimeline,
|
||||
@ -23,7 +22,6 @@ export const COMPOSE_UPLOAD_UNDO = 'COMPOSE_UPLOAD_UNDO';
|
||||
|
||||
export const COMPOSE_SUGGESTIONS_CLEAR = 'COMPOSE_SUGGESTIONS_CLEAR';
|
||||
export const COMPOSE_SUGGESTIONS_READY = 'COMPOSE_SUGGESTIONS_READY';
|
||||
export const COMPOSE_SUGGESTIONS_READY_TXT = 'COMPOSE_SUGGESTIONS_READY_TXT';
|
||||
export const COMPOSE_SUGGESTION_SELECT = 'COMPOSE_SUGGESTION_SELECT';
|
||||
|
||||
export const COMPOSE_MOUNT = 'COMPOSE_MOUNT';
|
||||
@ -213,56 +211,18 @@ export function clearComposeSuggestions() {
|
||||
};
|
||||
};
|
||||
|
||||
let allShortcodes = null; // cached list of all shortcodes for suggestions
|
||||
|
||||
export function fetchComposeSuggestions(token) {
|
||||
let leading = token[0];
|
||||
|
||||
if (leading === '@') {
|
||||
// handle search
|
||||
return (dispatch, getState) => {
|
||||
api(getState).get('/api/v1/accounts/search', {
|
||||
params: {
|
||||
q: token.slice(1), // remove the '@'
|
||||
resolve: false,
|
||||
limit: 4,
|
||||
},
|
||||
}).then(response => {
|
||||
dispatch(readyComposeSuggestions(token, response.data));
|
||||
});
|
||||
};
|
||||
} else if (leading === ':') {
|
||||
// shortcode
|
||||
if (!allShortcodes) {
|
||||
allShortcodes = Object.keys(emojione.emojioneList);
|
||||
// TODO when we have custom emojons merged, add them to this shortcode list
|
||||
}
|
||||
return (dispatch) => {
|
||||
const innertxt = token.slice(1);
|
||||
if (innertxt.length > 1) { // prevent searching single letter, causes lag
|
||||
dispatch(readyComposeSuggestionsTxt(token, allShortcodes.filter((sc) => {
|
||||
return sc.indexOf(innertxt) !== -1;
|
||||
}).sort((a, b) => {
|
||||
if (a.indexOf(token) === 0 && b.indexOf(token) === 0) return a.localeCompare(b);
|
||||
if (a.indexOf(token) === 0) return -1;
|
||||
if (b.indexOf(token) === 0) return 1;
|
||||
return a.localeCompare(b);
|
||||
})));
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// hashtag
|
||||
return (dispatch, getState) => {
|
||||
api(getState).get('/api/v1/search', {
|
||||
params: {
|
||||
q: token,
|
||||
resolve: true,
|
||||
},
|
||||
}).then(response => {
|
||||
dispatch(readyComposeSuggestionsTxt(token, response.data.hashtags.map((ht) => `#${ht}`)));
|
||||
});
|
||||
};
|
||||
}
|
||||
return (dispatch, getState) => {
|
||||
api(getState).get('/api/v1/accounts/search', {
|
||||
params: {
|
||||
q: token,
|
||||
resolve: false,
|
||||
limit: 4,
|
||||
},
|
||||
}).then(response => {
|
||||
dispatch(readyComposeSuggestions(token, response.data));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export function readyComposeSuggestions(token, accounts) {
|
||||
@ -273,19 +233,9 @@ export function readyComposeSuggestions(token, accounts) {
|
||||
};
|
||||
};
|
||||
|
||||
export function readyComposeSuggestionsTxt(token, items) {
|
||||
return {
|
||||
type: COMPOSE_SUGGESTIONS_READY_TXT,
|
||||
token,
|
||||
items,
|
||||
};
|
||||
};
|
||||
|
||||
export function selectComposeSuggestion(position, token, accountId) {
|
||||
return (dispatch, getState) => {
|
||||
const completion = (typeof accountId === 'string') ?
|
||||
accountId.slice(1) : // text suggestion: discard the leading : or # - the replacing code replaces only what follows
|
||||
getState().getIn(['accounts', accountId, 'acct']);
|
||||
const completion = getState().getIn(['accounts', accountId, 'acct']);
|
||||
|
||||
dispatch({
|
||||
type: COMPOSE_SUGGESTION_SELECT,
|
||||
|
Reference in New Issue
Block a user