Change design of lists in web UI (#32881)
This commit is contained in:
parent
7385016837
commit
62603508c7
39 changed files with 1395 additions and 1350 deletions
49
app/javascript/mastodon/reducers/lists.ts
Normal file
49
app/javascript/mastodon/reducers/lists.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import type { Reducer } from '@reduxjs/toolkit';
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
|
||||
import { createList, updateList } from 'mastodon/actions/lists_typed';
|
||||
import type { ApiListJSON } from 'mastodon/api_types/lists';
|
||||
import { createList as createListFromJSON } from 'mastodon/models/list';
|
||||
import type { List } from 'mastodon/models/list';
|
||||
|
||||
import {
|
||||
LIST_FETCH_SUCCESS,
|
||||
LIST_FETCH_FAIL,
|
||||
LISTS_FETCH_SUCCESS,
|
||||
LIST_DELETE_SUCCESS,
|
||||
} from '../actions/lists';
|
||||
|
||||
const initialState = ImmutableMap<string, List | null>();
|
||||
type State = typeof initialState;
|
||||
|
||||
const normalizeList = (state: State, list: ApiListJSON) =>
|
||||
state.set(list.id, createListFromJSON(list));
|
||||
|
||||
const normalizeLists = (state: State, lists: ApiListJSON[]) => {
|
||||
lists.forEach((list) => {
|
||||
state = normalizeList(state, list);
|
||||
});
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
export const listsReducer: Reducer<State> = (state = initialState, action) => {
|
||||
if (
|
||||
createList.fulfilled.match(action) ||
|
||||
updateList.fulfilled.match(action)
|
||||
) {
|
||||
return normalizeList(state, action.payload);
|
||||
} else {
|
||||
switch (action.type) {
|
||||
case LIST_FETCH_SUCCESS:
|
||||
return normalizeList(state, action.list as ApiListJSON);
|
||||
case LISTS_FETCH_SUCCESS:
|
||||
return normalizeLists(state, action.lists as ApiListJSON[]);
|
||||
case LIST_DELETE_SUCCESS:
|
||||
case LIST_FETCH_FAIL:
|
||||
return state.set(action.id as string, null);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue