Merge branch 'use-trends' into 'develop'

Use current trends for hashtag searching in composer

See merge request soapbox-pub/soapbox-fe!1740
environments/review-develop-3zknud/deployments/810
Justin 2 years ago
commit d38aa68870

@ -1,4 +1,5 @@
import axios, { AxiosError, Canceler } from 'axios';
import { List as ImmutableList } from 'immutable';
import throttle from 'lodash/throttle';
import { defineMessages, IntlShape } from 'react-intl';
@ -23,7 +24,7 @@ import type { History } from 'history';
import type { Emoji } from 'soapbox/components/autosuggest_emoji';
import type { AutoSuggestion } from 'soapbox/components/autosuggest_input';
import type { AppDispatch, RootState } from 'soapbox/store';
import type { Account, APIEntity, Status } from 'soapbox/types/entities';
import type { Account, APIEntity, Status, Tag } from 'soapbox/types/entities';
const { CancelToken, isCancel } = axios;
@ -505,7 +506,10 @@ const fetchComposeSuggestionsEmojis = (dispatch: AppDispatch, getState: () => Ro
};
const fetchComposeSuggestionsTags = (dispatch: AppDispatch, getState: () => RootState, token: string) => {
dispatch(updateSuggestionTags(token));
const state = getState();
const currentTrends = state.trends.items;
dispatch(updateSuggestionTags(token, currentTrends));
};
const fetchComposeSuggestions = (token: string) =>
@ -561,9 +565,10 @@ const selectComposeSuggestion = (position: number, token: string | null, suggest
});
};
const updateSuggestionTags = (token: string) => ({
const updateSuggestionTags = (token: string, currentTrends: ImmutableList<Tag>) => ({
type: COMPOSE_SUGGESTION_TAGS_UPDATE,
token,
currentTrends,
});
const updateTagHistory = (tags: string[]) => ({

@ -4,6 +4,7 @@ import * as actions from 'soapbox/actions/compose';
import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from 'soapbox/actions/me';
import { SETTING_CHANGE } from 'soapbox/actions/settings';
import { TIMELINE_DELETE } from 'soapbox/actions/timelines';
import { TagRecord } from 'soapbox/normalizers';
import { normalizeStatus } from 'soapbox/normalizers/status';
import reducer, { ReducerRecord } from '../compose';
@ -401,6 +402,9 @@ describe('compose reducer', () => {
const action = {
type: actions.COMPOSE_SUGGESTION_TAGS_UPDATE,
token: 'aaadken3',
currentTrends: ImmutableList([
TagRecord({ name: 'hashtag' }),
]),
};
expect(reducer(state, action).toJS()).toMatchObject({
suggestion_token: 'aaadken3',

@ -65,6 +65,7 @@ import type {
APIEntity,
Attachment as AttachmentEntity,
Status as StatusEntity,
Tag,
} from 'soapbox/types/entities';
const getResetFileKey = () => Math.floor((Math.random() * 0x10000));
@ -188,14 +189,14 @@ const insertSuggestion = (state: State, position: number, token: string, complet
});
};
const updateSuggestionTags = (state: State, token: string) => {
const updateSuggestionTags = (state: State, token: string, currentTrends: ImmutableList<Tag>) => {
const prefix = token.slice(1);
return state.merge({
suggestions: state.tagHistory
.filter(tag => tag.toLowerCase().startsWith(prefix.toLowerCase()))
suggestions: ImmutableList(currentTrends
.filter((tag) => tag.get('name').toLowerCase().startsWith(prefix.toLowerCase()))
.slice(0, 4)
.map(tag => '#' + tag),
.map((tag) => '#' + tag.name)),
suggestion_token: token,
});
};
@ -406,7 +407,7 @@ export default function compose(state = ReducerRecord({ idempotencyKey: uuid(),
case COMPOSE_SUGGESTION_SELECT:
return insertSuggestion(state, action.position, action.token, action.completion, action.path);
case COMPOSE_SUGGESTION_TAGS_UPDATE:
return updateSuggestionTags(state, action.token);
return updateSuggestionTags(state, action.token, action.currentTrends);
case COMPOSE_TAG_HISTORY_UPDATE:
return state.set('tagHistory', ImmutableList(fromJS(action.tags)) as ImmutableList<string>);
case TIMELINE_DELETE:

Loading…
Cancel
Save