diff --git a/app/soapbox/actions/compose.ts b/app/soapbox/actions/compose.ts index f33a9fa18..804141cd8 100644 --- a/app/soapbox/actions/compose.ts +++ b/app/soapbox/actions/compose.ts @@ -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) => ({ type: COMPOSE_SUGGESTION_TAGS_UPDATE, token, + currentTrends, }); const updateTagHistory = (tags: string[]) => ({ diff --git a/app/soapbox/reducers/__tests__/compose.test.ts b/app/soapbox/reducers/__tests__/compose.test.ts index b1cc01b58..6c129023e 100644 --- a/app/soapbox/reducers/__tests__/compose.test.ts +++ b/app/soapbox/reducers/__tests__/compose.test.ts @@ -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', diff --git a/app/soapbox/reducers/compose.ts b/app/soapbox/reducers/compose.ts index a6e3b94a0..d8fd41c3b 100644 --- a/app/soapbox/reducers/compose.ts +++ b/app/soapbox/reducers/compose.ts @@ -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) => { 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); case TIMELINE_DELETE: