0
0
Fork 0

Add featured tags selector for WebUI (#19358)

* Add featured tags selector for WebUI

* Add title to tag count
This commit is contained in:
Takeshi Umeda 2022-10-16 15:43:59 +09:00 committed by GitHub
parent c618d3a0a5
commit 4c7b5fb6c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 194 additions and 20 deletions

View file

@ -22,7 +22,7 @@ import {
FOLLOW_REQUESTS_EXPAND_FAIL,
FOLLOW_REQUEST_AUTHORIZE_SUCCESS,
FOLLOW_REQUEST_REJECT_SUCCESS,
} from '../actions/accounts';
} from '../actions/accounts';
import {
REBLOGS_FETCH_SUCCESS,
FAVOURITES_FETCH_SUCCESS,
@ -51,7 +51,12 @@ import {
DIRECTORY_EXPAND_SUCCESS,
DIRECTORY_EXPAND_FAIL,
} from 'mastodon/actions/directory';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import {
FEATURED_TAGS_FETCH_REQUEST,
FEATURED_TAGS_FETCH_SUCCESS,
FEATURED_TAGS_FETCH_FAIL,
} from 'mastodon/actions/featured_tags';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
const initialListState = ImmutableMap({
next: null,
@ -67,6 +72,7 @@ const initialState = ImmutableMap({
follow_requests: initialListState,
blocks: initialListState,
mutes: initialListState,
featured_tags: initialListState,
});
const normalizeList = (state, path, accounts, next) => {
@ -89,6 +95,18 @@ const normalizeFollowRequest = (state, notification) => {
});
};
const normalizeFeaturedTag = (featuredTags, accountId) => {
const normalizeFeaturedTag = { ...featuredTags, accountId: accountId };
return fromJS(normalizeFeaturedTag);
};
const normalizeFeaturedTags = (state, path, featuredTags, accountId) => {
return state.setIn(path, ImmutableMap({
items: ImmutableList(featuredTags.map(featuredTag => normalizeFeaturedTag(featuredTag, accountId)).sort((a, b) => b.get('statuses_count') - a.get('statuses_count'))),
isLoading: false,
}));
};
export default function userLists(state = initialState, action) {
switch(action.type) {
case FOLLOWERS_FETCH_SUCCESS:
@ -160,6 +178,12 @@ export default function userLists(state = initialState, action) {
case DIRECTORY_FETCH_FAIL:
case DIRECTORY_EXPAND_FAIL:
return state.setIn(['directory', 'isLoading'], false);
case FEATURED_TAGS_FETCH_SUCCESS:
return normalizeFeaturedTags(state, ['featured_tags', action.id], action.tags, action.id);
case FEATURED_TAGS_FETCH_REQUEST:
return state.setIn(['featured_tags', action.id, 'isLoading'], true);
case FEATURED_TAGS_FETCH_FAIL:
return state.setIn(['featured_tags', action.id, 'isLoading'], false);
default:
return state;
}