Wip: bookmark statuses view and adder
This commit is contained in:
parent
f6bdd9b6de
commit
87490a3220
30 changed files with 616 additions and 24 deletions
|
@ -14,6 +14,9 @@ import {
|
|||
BOOKMARK_CATEGORY_STATUSES_EXPAND_SUCCESS,
|
||||
BOOKMARK_CATEGORY_STATUSES_EXPAND_FAIL,
|
||||
} from '../actions/bookmark_categories';
|
||||
import {
|
||||
UNBOOKMARK_SUCCESS,
|
||||
} from '../actions/interactions';
|
||||
|
||||
const initialState = ImmutableMap();
|
||||
|
||||
|
@ -27,8 +30,8 @@ const normalizeBookmarkCategories = (state, bookmarkCategories) => {
|
|||
return state;
|
||||
};
|
||||
|
||||
const normalizeBookmarkCategoryStatuses = (state, bookmaryCategoryId, statuses, next) => {
|
||||
return state.updateIn([bookmaryCategoryId, 'items'], listMap => listMap.withMutations(map => {
|
||||
const normalizeBookmarkCategoryStatuses = (state, bookmarkCategoryId, statuses, next) => {
|
||||
return state.update(bookmarkCategoryId, listMap => listMap.withMutations(map => {
|
||||
map.set('next', next);
|
||||
map.set('loaded', true);
|
||||
map.set('isLoading', false);
|
||||
|
@ -37,13 +40,20 @@ const normalizeBookmarkCategoryStatuses = (state, bookmaryCategoryId, statuses,
|
|||
};
|
||||
|
||||
const appendToBookmarkCategoryStatuses = (state, bookmarkCategoryId, statuses, next) => {
|
||||
return state.updateIn([bookmarkCategoryId, 'items'], listMap => listMap.withMutations(map => {
|
||||
return state.update(bookmarkCategoryId, listMap => listMap.withMutations(map => {
|
||||
map.set('next', next);
|
||||
map.set('isLoading', false);
|
||||
map.set('items', map.get('items').union(statuses.map(item => item.id)));
|
||||
}));
|
||||
};
|
||||
|
||||
const removeStatusFromAllBookmarkCategories = (state, status) => {
|
||||
state.toList().forEach((bookmarkCategory) => {
|
||||
state = state.updateIn([bookmarkCategory.get('id'), 'items'], items => items.delete(status.get('id')));
|
||||
});
|
||||
return state;
|
||||
};
|
||||
|
||||
export default function bookmarkCategories(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case BOOKMARK_CATEGORY_FETCH_SUCCESS:
|
||||
|
@ -65,6 +75,8 @@ export default function bookmarkCategories(state = initialState, action) {
|
|||
return normalizeBookmarkCategoryStatuses(state, action.id, action.statuses, action.next);
|
||||
case BOOKMARK_CATEGORY_STATUSES_EXPAND_SUCCESS:
|
||||
return appendToBookmarkCategoryStatuses(state, action.id, action.statuses, action.next);
|
||||
case UNBOOKMARK_SUCCESS:
|
||||
return removeStatusFromAllBookmarkCategories(state, action.status);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
48
app/javascript/mastodon/reducers/bookmark_category_adder.js
Normal file
48
app/javascript/mastodon/reducers/bookmark_category_adder.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
|
||||
import {
|
||||
BOOKMARK_CATEGORY_ADDER_RESET,
|
||||
BOOKMARK_CATEGORY_ADDER_SETUP,
|
||||
BOOKMARK_CATEGORY_ADDER_BOOKMARK_CATEGORIES_FETCH_REQUEST,
|
||||
BOOKMARK_CATEGORY_ADDER_BOOKMARK_CATEGORIES_FETCH_SUCCESS,
|
||||
BOOKMARK_CATEGORY_ADDER_BOOKMARK_CATEGORIES_FETCH_FAIL,
|
||||
BOOKMARK_CATEGORY_EDITOR_ADD_SUCCESS,
|
||||
BOOKMARK_CATEGORY_EDITOR_REMOVE_SUCCESS,
|
||||
} from '../actions/bookmark_categories';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
statusId: null,
|
||||
|
||||
bookmarkCategories: ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
loaded: false,
|
||||
isLoading: false,
|
||||
}),
|
||||
});
|
||||
|
||||
export default function bookmarkCategoryAdderReducer(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case BOOKMARK_CATEGORY_ADDER_RESET:
|
||||
return initialState;
|
||||
case BOOKMARK_CATEGORY_ADDER_SETUP:
|
||||
return state.withMutations(map => {
|
||||
map.set('statusId', action.status.get('id'));
|
||||
});
|
||||
case BOOKMARK_CATEGORY_ADDER_BOOKMARK_CATEGORIES_FETCH_REQUEST:
|
||||
return state.setIn(['bookmarkCategories', 'isLoading'], true);
|
||||
case BOOKMARK_CATEGORY_ADDER_BOOKMARK_CATEGORIES_FETCH_FAIL:
|
||||
return state.setIn(['bookmarkCategories', 'isLoading'], false);
|
||||
case BOOKMARK_CATEGORY_ADDER_BOOKMARK_CATEGORIES_FETCH_SUCCESS:
|
||||
return state.update('bookmarkCategories', bookmarkCategories => bookmarkCategories.withMutations(map => {
|
||||
map.set('isLoading', false);
|
||||
map.set('loaded', true);
|
||||
map.set('items', ImmutableList(action.bookmarkCategories.map(item => item.id)));
|
||||
}));
|
||||
case BOOKMARK_CATEGORY_EDITOR_ADD_SUCCESS:
|
||||
return state.updateIn(['bookmarkCategories', 'items'], bookmarkCategory => bookmarkCategory.unshift(action.bookmarkCategoryId));
|
||||
case BOOKMARK_CATEGORY_EDITOR_REMOVE_SUCCESS:
|
||||
return state.updateIn(['bookmarkCategories', 'items'], bookmarkCategory => bookmarkCategory.filterNot(item => item === action.bookmarkCategoryId));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
|
@ -10,12 +10,10 @@ import {
|
|||
BOOKMARK_CATEGORY_EDITOR_RESET,
|
||||
BOOKMARK_CATEGORY_EDITOR_SETUP,
|
||||
BOOKMARK_CATEGORY_EDITOR_TITLE_CHANGE,
|
||||
BOOKMARK_CATEGORY_EDITOR_ADD_SUCCESS,
|
||||
BOOKMARK_CATEGORY_EDITOR_REMOVE_SUCCESS,
|
||||
} from '../actions/bookmark_categories';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
bookmaryCategoryId: null,
|
||||
bookmarkCategoryId: null,
|
||||
isSubmitting: false,
|
||||
isChanged: false,
|
||||
title: '',
|
||||
|
@ -33,15 +31,15 @@ const initialState = ImmutableMap({
|
|||
}),
|
||||
});
|
||||
|
||||
export default function bookmaryCategoryEditorReducer(state = initialState, action) {
|
||||
export default function bookmarkCategoryEditorReducer(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case BOOKMARK_CATEGORY_EDITOR_RESET:
|
||||
return initialState;
|
||||
case BOOKMARK_CATEGORY_EDITOR_SETUP:
|
||||
return state.withMutations(map => {
|
||||
map.set('bookmaryCategoryId', action.bookmaryCategory.get('id'));
|
||||
map.set('title', action.bookmaryCategory.get('title'));
|
||||
map.set('isExclusive', action.bookmaryCategory.get('is_exclusive'));
|
||||
map.set('bookmarkCategoryId', action.bookmarkCategory.get('id'));
|
||||
map.set('title', action.bookmarkCategory.get('title'));
|
||||
map.set('isExclusive', action.bookmarkCategory.get('is_exclusive'));
|
||||
map.set('isSubmitting', false);
|
||||
});
|
||||
case BOOKMARK_CATEGORY_EDITOR_TITLE_CHANGE:
|
||||
|
@ -62,12 +60,8 @@ export default function bookmaryCategoryEditorReducer(state = initialState, acti
|
|||
case BOOKMARK_CATEGORY_UPDATE_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.set('isSubmitting', false);
|
||||
map.set('bookmaryCategoryId', action.bookmaryCategory.id);
|
||||
map.set('bookmarkCategoryId', action.bookmarkCategory.id);
|
||||
});
|
||||
case BOOKMARK_CATEGORY_EDITOR_ADD_SUCCESS:
|
||||
return state.updateIn(['accounts', 'items'], bookmaryCategory => bookmaryCategory.unshift(action.accountId));
|
||||
case BOOKMARK_CATEGORY_EDITOR_REMOVE_SUCCESS:
|
||||
return state.updateIn(['accounts', 'items'], bookmaryCategory => bookmaryCategory.filterNot(item => item === action.accountId));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import antennaEditor from './antenna_editor';
|
|||
import antennas from './antennas';
|
||||
import blocks from './blocks';
|
||||
import bookmark_categories from './bookmark_categories';
|
||||
import bookmarkCategoryAdder from './bookmark_category_adder';
|
||||
import bookmarkCategoryEditor from './bookmark_category_editor';
|
||||
import boosts from './boosts';
|
||||
import circleAdder from './circle_adder';
|
||||
|
@ -93,6 +94,7 @@ const reducers = {
|
|||
circleAdder,
|
||||
bookmark_categories,
|
||||
bookmarkCategoryEditor,
|
||||
bookmarkCategoryAdder,
|
||||
filters,
|
||||
conversations,
|
||||
suggestions,
|
||||
|
|
|
@ -4,6 +4,9 @@ import {
|
|||
ACCOUNT_BLOCK_SUCCESS,
|
||||
ACCOUNT_MUTE_SUCCESS,
|
||||
} from '../actions/accounts';
|
||||
import {
|
||||
BOOKMARK_CATEGORY_EDITOR_ADD_SUCCESS,
|
||||
} from '../actions/bookmark_categories';
|
||||
import {
|
||||
BOOKMARKED_STATUSES_FETCH_REQUEST,
|
||||
BOOKMARKED_STATUSES_FETCH_SUCCESS,
|
||||
|
@ -98,11 +101,15 @@ const appendToList = (state, listType, statuses, next) => {
|
|||
};
|
||||
|
||||
const prependOneToList = (state, listType, status) => {
|
||||
return prependOneToListById(state, listType, status.get('id'));
|
||||
};
|
||||
|
||||
const prependOneToListById = (state, listType, statusId) => {
|
||||
return state.updateIn([listType, 'items'], (list) => {
|
||||
if (list.includes(status.get('id'))) {
|
||||
if (list.includes(statusId)) {
|
||||
return list;
|
||||
} else {
|
||||
return ImmutableOrderedSet([status.get('id')]).union(list);
|
||||
return ImmutableOrderedSet([statusId]).union(list);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -163,6 +170,8 @@ export default function statusLists(state = initialState, action) {
|
|||
return removeOneFromList(state, 'emoji_reactions', action.status);
|
||||
case BOOKMARK_SUCCESS:
|
||||
return prependOneToList(state, 'bookmarks', action.status);
|
||||
case BOOKMARK_CATEGORY_EDITOR_ADD_SUCCESS:
|
||||
return prependOneToListById(state, 'bookmarks', action.statusId);
|
||||
case UNBOOKMARK_SUCCESS:
|
||||
return removeOneFromList(state, 'bookmarks', action.status);
|
||||
case PINNED_STATUSES_FETCH_SUCCESS:
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||
|
||||
import {
|
||||
BOOKMARK_CATEGORY_EDITOR_ADD_REQUEST,
|
||||
BOOKMARK_CATEGORY_EDITOR_ADD_FAIL,
|
||||
} from '../actions/bookmark_categories';
|
||||
import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
|
||||
import { normalizeStatusTranslation } from '../actions/importer/normalizer';
|
||||
import {
|
||||
|
@ -111,6 +115,10 @@ export default function statuses(state = initialState, action) {
|
|||
return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'bookmarked'], true);
|
||||
case BOOKMARK_FAIL:
|
||||
return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'bookmarked'], false);
|
||||
case BOOKMARK_CATEGORY_EDITOR_ADD_REQUEST:
|
||||
return state.get(action.statusId) === undefined ? state : state.setIn([action.statusId, 'bookmarked'], true);
|
||||
case BOOKMARK_CATEGORY_EDITOR_ADD_FAIL:
|
||||
return state.get(action.statusId) === undefined ? state : state.setIn([action.statusId, 'bookmarked'], false);
|
||||
case UNBOOKMARK_REQUEST:
|
||||
return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'bookmarked'], false);
|
||||
case UNBOOKMARK_FAIL:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue