Use current trends for hashtag searching in composer
This commit is contained in:
parent
a716629bae
commit
8fbe8a90e0
3 changed files with 18 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
||||||
import axios, { AxiosError, Canceler } from 'axios';
|
import axios, { AxiosError, Canceler } from 'axios';
|
||||||
|
import { List as ImmutableList } from 'immutable';
|
||||||
import throttle from 'lodash/throttle';
|
import throttle from 'lodash/throttle';
|
||||||
import { defineMessages, IntlShape } from 'react-intl';
|
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 { Emoji } from 'soapbox/components/autosuggest_emoji';
|
||||||
import type { AutoSuggestion } from 'soapbox/components/autosuggest_input';
|
import type { AutoSuggestion } from 'soapbox/components/autosuggest_input';
|
||||||
import type { AppDispatch, RootState } from 'soapbox/store';
|
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;
|
const { CancelToken, isCancel } = axios;
|
||||||
|
|
||||||
|
@ -505,7 +506,10 @@ const fetchComposeSuggestionsEmojis = (dispatch: AppDispatch, getState: () => Ro
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchComposeSuggestionsTags = (dispatch: AppDispatch, getState: () => RootState, token: string) => {
|
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) =>
|
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,
|
type: COMPOSE_SUGGESTION_TAGS_UPDATE,
|
||||||
token,
|
token,
|
||||||
|
currentTrends,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateTagHistory = (tags: string[]) => ({
|
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 { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from 'soapbox/actions/me';
|
||||||
import { SETTING_CHANGE } from 'soapbox/actions/settings';
|
import { SETTING_CHANGE } from 'soapbox/actions/settings';
|
||||||
import { TIMELINE_DELETE } from 'soapbox/actions/timelines';
|
import { TIMELINE_DELETE } from 'soapbox/actions/timelines';
|
||||||
|
import { TagRecord } from 'soapbox/normalizers';
|
||||||
import { normalizeStatus } from 'soapbox/normalizers/status';
|
import { normalizeStatus } from 'soapbox/normalizers/status';
|
||||||
|
|
||||||
import reducer, { ReducerRecord } from '../compose';
|
import reducer, { ReducerRecord } from '../compose';
|
||||||
|
@ -401,6 +402,9 @@ describe('compose reducer', () => {
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SUGGESTION_TAGS_UPDATE,
|
type: actions.COMPOSE_SUGGESTION_TAGS_UPDATE,
|
||||||
token: 'aaadken3',
|
token: 'aaadken3',
|
||||||
|
currentTrends: ImmutableList([
|
||||||
|
TagRecord({ name: 'hashtag' }),
|
||||||
|
]),
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS()).toMatchObject({
|
expect(reducer(state, action).toJS()).toMatchObject({
|
||||||
suggestion_token: 'aaadken3',
|
suggestion_token: 'aaadken3',
|
||||||
|
|
|
@ -65,6 +65,7 @@ import type {
|
||||||
APIEntity,
|
APIEntity,
|
||||||
Attachment as AttachmentEntity,
|
Attachment as AttachmentEntity,
|
||||||
Status as StatusEntity,
|
Status as StatusEntity,
|
||||||
|
Tag,
|
||||||
} from 'soapbox/types/entities';
|
} from 'soapbox/types/entities';
|
||||||
|
|
||||||
const getResetFileKey = () => Math.floor((Math.random() * 0x10000));
|
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);
|
const prefix = token.slice(1);
|
||||||
|
|
||||||
return state.merge({
|
return state.merge({
|
||||||
suggestions: state.tagHistory
|
suggestions: ImmutableList(currentTrends
|
||||||
.filter(tag => tag.toLowerCase().startsWith(prefix.toLowerCase()))
|
.filter((tag) => tag.get('name').toLowerCase().startsWith(prefix.toLowerCase()))
|
||||||
.slice(0, 4)
|
.slice(0, 4)
|
||||||
.map(tag => '#' + tag),
|
.map((tag) => '#' + tag.name)),
|
||||||
suggestion_token: token,
|
suggestion_token: token,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -406,7 +407,7 @@ export default function compose(state = ReducerRecord({ idempotencyKey: uuid(),
|
||||||
case COMPOSE_SUGGESTION_SELECT:
|
case COMPOSE_SUGGESTION_SELECT:
|
||||||
return insertSuggestion(state, action.position, action.token, action.completion, action.path);
|
return insertSuggestion(state, action.position, action.token, action.completion, action.path);
|
||||||
case COMPOSE_SUGGESTION_TAGS_UPDATE:
|
case COMPOSE_SUGGESTION_TAGS_UPDATE:
|
||||||
return updateSuggestionTags(state, action.token);
|
return updateSuggestionTags(state, action.token, action.currentTrends);
|
||||||
case COMPOSE_TAG_HISTORY_UPDATE:
|
case COMPOSE_TAG_HISTORY_UPDATE:
|
||||||
return state.set('tagHistory', ImmutableList(fromJS(action.tags)) as ImmutableList<string>);
|
return state.set('tagHistory', ImmutableList(fromJS(action.tags)) as ImmutableList<string>);
|
||||||
case TIMELINE_DELETE:
|
case TIMELINE_DELETE:
|
||||||
|
|
Loading…
Reference in a new issue