Add explore page to web UI (#17123)
* Add explore page to web UI * Fix not removing loaded statuses from trends on mute/block action
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import {
|
||||
SEARCH_CHANGE,
|
||||
SEARCH_CLEAR,
|
||||
SEARCH_FETCH_REQUEST,
|
||||
SEARCH_FETCH_FAIL,
|
||||
SEARCH_FETCH_SUCCESS,
|
||||
SEARCH_SHOW,
|
||||
SEARCH_EXPAND_SUCCESS,
|
||||
@@ -17,6 +19,7 @@ const initialState = ImmutableMap({
|
||||
submitted: false,
|
||||
hidden: false,
|
||||
results: ImmutableMap(),
|
||||
isLoading: false,
|
||||
searchTerm: '',
|
||||
});
|
||||
|
||||
@@ -37,12 +40,22 @@ export default function search(state = initialState, action) {
|
||||
case COMPOSE_MENTION:
|
||||
case COMPOSE_DIRECT:
|
||||
return state.set('hidden', true);
|
||||
case SEARCH_FETCH_REQUEST:
|
||||
return state.set('isLoading', true);
|
||||
case SEARCH_FETCH_FAIL:
|
||||
return state.set('isLoading', false);
|
||||
case SEARCH_FETCH_SUCCESS:
|
||||
return state.set('results', ImmutableMap({
|
||||
accounts: ImmutableList(action.results.accounts.map(item => item.id)),
|
||||
statuses: ImmutableList(action.results.statuses.map(item => item.id)),
|
||||
hashtags: fromJS(action.results.hashtags),
|
||||
})).set('submitted', true).set('searchTerm', action.searchTerm);
|
||||
return state.withMutations(map => {
|
||||
map.set('results', ImmutableMap({
|
||||
accounts: ImmutableList(action.results.accounts.map(item => item.id)),
|
||||
statuses: ImmutableList(action.results.statuses.map(item => item.id)),
|
||||
hashtags: fromJS(action.results.hashtags),
|
||||
}));
|
||||
|
||||
map.set('submitted', true);
|
||||
map.set('searchTerm', action.searchTerm);
|
||||
map.set('isLoading', false);
|
||||
});
|
||||
case SEARCH_EXPAND_SUCCESS:
|
||||
const results = action.searchType === 'hashtags' ? fromJS(action.results.hashtags) : action.results[action.searchType].map(item => item.id);
|
||||
return state.updateIn(['results', action.searchType], list => list.concat(results));
|
||||
|
@@ -17,6 +17,11 @@ import {
|
||||
import {
|
||||
PINNED_STATUSES_FETCH_SUCCESS,
|
||||
} from '../actions/pin_statuses';
|
||||
import {
|
||||
TRENDS_STATUSES_FETCH_REQUEST,
|
||||
TRENDS_STATUSES_FETCH_SUCCESS,
|
||||
TRENDS_STATUSES_FETCH_FAIL,
|
||||
} from '../actions/trends';
|
||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
import {
|
||||
FAVOURITE_SUCCESS,
|
||||
@@ -26,6 +31,10 @@ import {
|
||||
PIN_SUCCESS,
|
||||
UNPIN_SUCCESS,
|
||||
} from '../actions/interactions';
|
||||
import {
|
||||
ACCOUNT_BLOCK_SUCCESS,
|
||||
ACCOUNT_MUTE_SUCCESS,
|
||||
} from '../actions/accounts';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
favourites: ImmutableMap({
|
||||
@@ -43,6 +52,11 @@ const initialState = ImmutableMap({
|
||||
loaded: false,
|
||||
items: ImmutableList(),
|
||||
}),
|
||||
trending: ImmutableMap({
|
||||
next: null,
|
||||
loaded: false,
|
||||
items: ImmutableList(),
|
||||
}),
|
||||
});
|
||||
|
||||
const normalizeList = (state, listType, statuses, next) => {
|
||||
@@ -96,6 +110,12 @@ export default function statusLists(state = initialState, action) {
|
||||
return normalizeList(state, 'bookmarks', action.statuses, action.next);
|
||||
case BOOKMARKED_STATUSES_EXPAND_SUCCESS:
|
||||
return appendToList(state, 'bookmarks', action.statuses, action.next);
|
||||
case TRENDS_STATUSES_FETCH_REQUEST:
|
||||
return state.setIn(['trending', 'isLoading'], true);
|
||||
case TRENDS_STATUSES_FETCH_FAIL:
|
||||
return state.setIn(['trending', 'isLoading'], false);
|
||||
case TRENDS_STATUSES_FETCH_SUCCESS:
|
||||
return normalizeList(state, 'trending', action.statuses, action.next);
|
||||
case FAVOURITE_SUCCESS:
|
||||
return prependOneToList(state, 'favourites', action.status);
|
||||
case UNFAVOURITE_SUCCESS:
|
||||
@@ -110,6 +130,9 @@ export default function statusLists(state = initialState, action) {
|
||||
return prependOneToList(state, 'pins', action.status);
|
||||
case UNPIN_SUCCESS:
|
||||
return removeOneFromList(state, 'pins', action.status);
|
||||
case ACCOUNT_BLOCK_SUCCESS:
|
||||
case ACCOUNT_MUTE_SUCCESS:
|
||||
return state.updateIn(['trending', 'items'], ImmutableList(), list => list.filterNot(statusId => action.statuses.getIn([statusId, 'account']) === action.relationship.id));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@@ -1,22 +1,45 @@
|
||||
import { TRENDS_FETCH_REQUEST, TRENDS_FETCH_SUCCESS, TRENDS_FETCH_FAIL } from '../actions/trends';
|
||||
import {
|
||||
TRENDS_TAGS_FETCH_REQUEST,
|
||||
TRENDS_TAGS_FETCH_SUCCESS,
|
||||
TRENDS_TAGS_FETCH_FAIL,
|
||||
TRENDS_LINKS_FETCH_REQUEST,
|
||||
TRENDS_LINKS_FETCH_SUCCESS,
|
||||
TRENDS_LINKS_FETCH_FAIL,
|
||||
} from 'mastodon/actions/trends';
|
||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
isLoading: false,
|
||||
tags: ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
isLoading: false,
|
||||
}),
|
||||
|
||||
links: ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
isLoading: false,
|
||||
}),
|
||||
});
|
||||
|
||||
export default function trendsReducer(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case TRENDS_FETCH_REQUEST:
|
||||
return state.set('isLoading', true);
|
||||
case TRENDS_FETCH_SUCCESS:
|
||||
case TRENDS_TAGS_FETCH_REQUEST:
|
||||
return state.setIn(['tags', 'isLoading'], true);
|
||||
case TRENDS_TAGS_FETCH_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.set('items', fromJS(action.trends));
|
||||
map.set('isLoading', false);
|
||||
map.setIn(['tags', 'items'], fromJS(action.trends));
|
||||
map.setIn(['tags', 'isLoading'], false);
|
||||
});
|
||||
case TRENDS_FETCH_FAIL:
|
||||
return state.set('isLoading', false);
|
||||
case TRENDS_TAGS_FETCH_FAIL:
|
||||
return state.setIn(['tags', 'isLoading'], false);
|
||||
case TRENDS_LINKS_FETCH_REQUEST:
|
||||
return state.setIn(['links', 'isLoading'], true);
|
||||
case TRENDS_LINKS_FETCH_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.setIn(['links', 'items'], fromJS(action.trends));
|
||||
map.setIn(['links', 'isLoading'], false);
|
||||
});
|
||||
case TRENDS_LINKS_FETCH_FAIL:
|
||||
return state.setIn(['links', 'isLoading'], false);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
Reference in New Issue
Block a user