From acb434b0c998353e9e39379ecab27f68df41a100 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Wed, 11 Apr 2018 19:42:25 +0200 Subject: Add glitch-soc front-end support for bookmarks Unlike boosts and like, there is no confirmation dialog as misclicking can be recovered without another user seeing it. --- .../flavours/glitch/reducers/accounts.js | 10 ++++++++ .../flavours/glitch/reducers/accounts_counters.js | 10 ++++++++ .../flavours/glitch/reducers/status_lists.js | 29 ++++++++++++++++++++++ .../flavours/glitch/reducers/statuses.js | 16 ++++++++++++ 4 files changed, 65 insertions(+) (limited to 'app/javascript/flavours/glitch/reducers') diff --git a/app/javascript/flavours/glitch/reducers/accounts.js b/app/javascript/flavours/glitch/reducers/accounts.js index 1c5581347..61354f2e1 100644 --- a/app/javascript/flavours/glitch/reducers/accounts.js +++ b/app/javascript/flavours/glitch/reducers/accounts.js @@ -21,6 +21,8 @@ import { UNREBLOG_SUCCESS, FAVOURITE_SUCCESS, UNFAVOURITE_SUCCESS, + BOOKMARK_SUCCESS, + UNBOOKMARK_SUCCESS, REBLOGS_FETCH_SUCCESS, FAVOURITES_FETCH_SUCCESS, } from 'flavours/glitch/actions/interactions'; @@ -43,6 +45,10 @@ import { FAVOURITED_STATUSES_FETCH_SUCCESS, FAVOURITED_STATUSES_EXPAND_SUCCESS, } from 'flavours/glitch/actions/favourites'; +import { + BOOKMARKED_STATUSES_FETCH_SUCCESS, + BOOKMARKED_STATUSES_EXPAND_SUCCESS, +} from 'flavours/glitch/actions/bookmarks'; import { LIST_ACCOUNTS_FETCH_SUCCESS, LIST_EDITOR_SUGGESTIONS_READY, @@ -131,11 +137,15 @@ export default function accounts(state = initialState, action) { case CONTEXT_FETCH_SUCCESS: case FAVOURITED_STATUSES_FETCH_SUCCESS: case FAVOURITED_STATUSES_EXPAND_SUCCESS: + case BOOKMARKED_STATUSES_FETCH_SUCCESS: + case BOOKMARKED_STATUSES_EXPAND_SUCCESS: return normalizeAccountsFromStatuses(state, action.statuses); case REBLOG_SUCCESS: case FAVOURITE_SUCCESS: case UNREBLOG_SUCCESS: case UNFAVOURITE_SUCCESS: + case BOOKMARK_SUCCESS: + case UNBOOKMARK_SUCCESS: return normalizeAccountFromStatus(state, action.response); case TIMELINE_UPDATE: case STATUS_FETCH_SUCCESS: diff --git a/app/javascript/flavours/glitch/reducers/accounts_counters.js b/app/javascript/flavours/glitch/reducers/accounts_counters.js index 0fd985a08..7abcb5dec 100644 --- a/app/javascript/flavours/glitch/reducers/accounts_counters.js +++ b/app/javascript/flavours/glitch/reducers/accounts_counters.js @@ -23,6 +23,8 @@ import { UNREBLOG_SUCCESS, FAVOURITE_SUCCESS, UNFAVOURITE_SUCCESS, + BOOKMARK_SUCCESS, + UNBOOKMARK_SUCCESS, REBLOGS_FETCH_SUCCESS, FAVOURITES_FETCH_SUCCESS, } from 'flavours/glitch/actions/interactions'; @@ -45,6 +47,10 @@ import { FAVOURITED_STATUSES_FETCH_SUCCESS, FAVOURITED_STATUSES_EXPAND_SUCCESS, } from 'flavours/glitch/actions/favourites'; +import { + BOOKMARKED_STATUSES_FETCH_SUCCESS, + BOOKMARKED_STATUSES_EXPAND_SUCCESS, +} from 'flavours/glitch/actions/bookmarks'; import { LIST_ACCOUNTS_FETCH_SUCCESS, LIST_EDITOR_SUGGESTIONS_READY, @@ -122,11 +128,15 @@ export default function accountsCounters(state = initialState, action) { case CONTEXT_FETCH_SUCCESS: case FAVOURITED_STATUSES_FETCH_SUCCESS: case FAVOURITED_STATUSES_EXPAND_SUCCESS: + case BOOKMARKED_STATUSES_FETCH_SUCCESS: + case BOOKMARKED_STATUSES_EXPAND_SUCCESS: return normalizeAccountsFromStatuses(state, action.statuses); case REBLOG_SUCCESS: case FAVOURITE_SUCCESS: case UNREBLOG_SUCCESS: case UNFAVOURITE_SUCCESS: + case BOOKMARK_SUCCESS: + case UNBOOKMARK_SUCCESS: return normalizeAccountFromStatus(state, action.response); case TIMELINE_UPDATE: case STATUS_FETCH_SUCCESS: diff --git a/app/javascript/flavours/glitch/reducers/status_lists.js b/app/javascript/flavours/glitch/reducers/status_lists.js index 6de81c6b1..241833bfe 100644 --- a/app/javascript/flavours/glitch/reducers/status_lists.js +++ b/app/javascript/flavours/glitch/reducers/status_lists.js @@ -6,6 +6,14 @@ import { FAVOURITED_STATUSES_EXPAND_SUCCESS, FAVOURITED_STATUSES_EXPAND_FAIL, } from 'flavours/glitch/actions/favourites'; +import { + BOOKMARKED_STATUSES_FETCH_REQUEST, + BOOKMARKED_STATUSES_FETCH_SUCCESS, + BOOKMARKED_STATUSES_FETCH_FAIL, + BOOKMARKED_STATUSES_EXPAND_REQUEST, + BOOKMARKED_STATUSES_EXPAND_SUCCESS, + BOOKMARKED_STATUSES_EXPAND_FAIL, +} from 'flavours/glitch/actions/bookmarks'; import { PINNED_STATUSES_FETCH_SUCCESS, } from 'flavours/glitch/actions/pin_statuses'; @@ -13,6 +21,8 @@ import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; import { FAVOURITE_SUCCESS, UNFAVOURITE_SUCCESS, + BOOKMARK_SUCCESS, + UNBOOKMARK_SUCCESS, PIN_SUCCESS, UNPIN_SUCCESS, } from 'flavours/glitch/actions/interactions'; @@ -23,6 +33,11 @@ const initialState = ImmutableMap({ loaded: false, items: ImmutableList(), }), + bookmarks: ImmutableMap({ + next: null, + loaded: false, + items: ImmutableList(), + }), pins: ImmutableMap({ next: null, loaded: false, @@ -71,10 +86,24 @@ export default function statusLists(state = initialState, action) { return normalizeList(state, 'favourites', action.statuses, action.next); case FAVOURITED_STATUSES_EXPAND_SUCCESS: return appendToList(state, 'favourites', action.statuses, action.next); + case BOOKMARKED_STATUSES_FETCH_REQUEST: + case BOOKMARKED_STATUSES_EXPAND_REQUEST: + return state.setIn(['bookmarks', 'isLoading'], true); + case BOOKMARKED_STATUSES_FETCH_FAIL: + case BOOKMARKED_STATUSES_EXPAND_FAIL: + return state.setIn(['bookmarks', 'isLoading'], false); + case BOOKMARKED_STATUSES_FETCH_SUCCESS: + return normalizeList(state, 'bookmarks', action.statuses, action.next); + case BOOKMARKED_STATUSES_EXPAND_SUCCESS: + return appendToList(state, 'bookmarks', action.statuses, action.next); case FAVOURITE_SUCCESS: return prependOneToList(state, 'favourites', action.status); case UNFAVOURITE_SUCCESS: return removeOneFromList(state, 'favourites', action.status); + case BOOKMARK_SUCCESS: + return prependOneToList(state, 'bookmarks', action.status); + case UNBOOKMARK_SUCCESS: + return removeOneFromList(state, 'bookmarks', action.status); case PINNED_STATUSES_FETCH_SUCCESS: return normalizeList(state, 'pins', action.statuses, action.next); case PIN_SUCCESS: diff --git a/app/javascript/flavours/glitch/reducers/statuses.js b/app/javascript/flavours/glitch/reducers/statuses.js index 410bc013b..a3af3152d 100644 --- a/app/javascript/flavours/glitch/reducers/statuses.js +++ b/app/javascript/flavours/glitch/reducers/statuses.js @@ -7,6 +7,10 @@ import { FAVOURITE_SUCCESS, FAVOURITE_FAIL, UNFAVOURITE_SUCCESS, + BOOKMARK_REQUEST, + BOOKMARK_SUCCESS, + BOOKMARK_FAIL, + UNBOOKMARK_SUCCESS, PIN_SUCCESS, UNPIN_SUCCESS, } from 'flavours/glitch/actions/interactions'; @@ -35,6 +39,10 @@ import { FAVOURITED_STATUSES_FETCH_SUCCESS, FAVOURITED_STATUSES_EXPAND_SUCCESS, } from 'flavours/glitch/actions/favourites'; +import { + BOOKMARKED_STATUSES_FETCH_SUCCESS, + BOOKMARKED_STATUSES_EXPAND_SUCCESS, +} from 'flavours/glitch/actions/bookmarks'; import { PINNED_STATUSES_FETCH_SUCCESS, } from 'flavours/glitch/actions/pin_statuses'; @@ -112,6 +120,8 @@ export default function statuses(state = initialState, action) { case UNREBLOG_SUCCESS: case FAVOURITE_SUCCESS: case UNFAVOURITE_SUCCESS: + case BOOKMARK_SUCCESS: + case UNBOOKMARK_SUCCESS: case PIN_SUCCESS: case UNPIN_SUCCESS: return normalizeStatus(state, action.response); @@ -119,6 +129,10 @@ export default function statuses(state = initialState, action) { return state.setIn([action.status.get('id'), 'favourited'], true); case FAVOURITE_FAIL: return state.setIn([action.status.get('id'), 'favourited'], false); + case BOOKMARK_REQUEST: + return state.setIn([action.status.get('id'), 'bookmarked'], true); + case BOOKMARK_FAIL: + return state.setIn([action.status.get('id'), 'bookmarked'], false); case REBLOG_REQUEST: return state.setIn([action.status.get('id'), 'reblogged'], true); case REBLOG_FAIL: @@ -134,6 +148,8 @@ export default function statuses(state = initialState, action) { case NOTIFICATIONS_EXPAND_SUCCESS: case FAVOURITED_STATUSES_FETCH_SUCCESS: case FAVOURITED_STATUSES_EXPAND_SUCCESS: + case BOOKMARKED_STATUSES_FETCH_SUCCESS: + case BOOKMARKED_STATUSES_EXPAND_SUCCESS: case PINNED_STATUSES_FETCH_SUCCESS: case SEARCH_FETCH_SUCCESS: return normalizeStatuses(state, action.statuses); -- cgit