refactor: remove bookmarks actions
This commit is contained in:
parent
ab8a2de1c8
commit
b344de8425
|
@ -1,102 +0,0 @@
|
|||
import api from '../api/index.ts';
|
||||
|
||||
import { importFetchedStatuses } from './importer/index.ts';
|
||||
|
||||
import type { AppDispatch, RootState } from 'soapbox/store.ts';
|
||||
import type { APIEntity } from 'soapbox/types/entities.ts';
|
||||
|
||||
const BOOKMARKED_STATUSES_FETCH_REQUEST = 'BOOKMARKED_STATUSES_FETCH_REQUEST';
|
||||
const BOOKMARKED_STATUSES_FETCH_SUCCESS = 'BOOKMARKED_STATUSES_FETCH_SUCCESS';
|
||||
const BOOKMARKED_STATUSES_FETCH_FAIL = 'BOOKMARKED_STATUSES_FETCH_FAIL';
|
||||
|
||||
const BOOKMARKED_STATUSES_EXPAND_REQUEST = 'BOOKMARKED_STATUSES_EXPAND_REQUEST';
|
||||
const BOOKMARKED_STATUSES_EXPAND_SUCCESS = 'BOOKMARKED_STATUSES_EXPAND_SUCCESS';
|
||||
const BOOKMARKED_STATUSES_EXPAND_FAIL = 'BOOKMARKED_STATUSES_EXPAND_FAIL';
|
||||
|
||||
const noOp = () => new Promise(f => f(undefined));
|
||||
|
||||
const fetchBookmarkedStatuses = () =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (getState().status_lists.get('bookmarks')?.isLoading) {
|
||||
return dispatch(noOp);
|
||||
}
|
||||
|
||||
dispatch(fetchBookmarkedStatusesRequest());
|
||||
|
||||
return api(getState).get('/api/v1/bookmarks').then(async (response) => {
|
||||
const next = response.next();
|
||||
const data = await response.json();
|
||||
dispatch(importFetchedStatuses(data));
|
||||
return dispatch(fetchBookmarkedStatusesSuccess(data, next));
|
||||
}).catch(error => {
|
||||
dispatch(fetchBookmarkedStatusesFail(error));
|
||||
});
|
||||
};
|
||||
|
||||
const fetchBookmarkedStatusesRequest = () => ({
|
||||
type: BOOKMARKED_STATUSES_FETCH_REQUEST,
|
||||
});
|
||||
|
||||
const fetchBookmarkedStatusesSuccess = (statuses: APIEntity[], next: string | null) => ({
|
||||
type: BOOKMARKED_STATUSES_FETCH_SUCCESS,
|
||||
statuses,
|
||||
next,
|
||||
});
|
||||
|
||||
const fetchBookmarkedStatusesFail = (error: unknown) => ({
|
||||
type: BOOKMARKED_STATUSES_FETCH_FAIL,
|
||||
error,
|
||||
});
|
||||
|
||||
const expandBookmarkedStatuses = () =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
const bookmarks = 'bookmarks';
|
||||
const url = getState().status_lists.get(bookmarks)?.next || null;
|
||||
|
||||
if (url === null || getState().status_lists.get(bookmarks)?.isLoading) {
|
||||
return dispatch(noOp);
|
||||
}
|
||||
|
||||
dispatch(expandBookmarkedStatusesRequest());
|
||||
|
||||
return api(getState).get(url).then(async (response) => {
|
||||
const next = response.next();
|
||||
const data = await response.json();
|
||||
dispatch(importFetchedStatuses(data));
|
||||
return dispatch(expandBookmarkedStatusesSuccess(data, next));
|
||||
}).catch(error => {
|
||||
dispatch(expandBookmarkedStatusesFail(error));
|
||||
});
|
||||
};
|
||||
|
||||
const expandBookmarkedStatusesRequest = () => ({
|
||||
type: BOOKMARKED_STATUSES_EXPAND_REQUEST,
|
||||
});
|
||||
|
||||
const expandBookmarkedStatusesSuccess = (statuses: APIEntity[], next: string | null) => ({
|
||||
type: BOOKMARKED_STATUSES_EXPAND_SUCCESS,
|
||||
statuses,
|
||||
next,
|
||||
});
|
||||
|
||||
const expandBookmarkedStatusesFail = (error: unknown) => ({
|
||||
type: BOOKMARKED_STATUSES_EXPAND_FAIL,
|
||||
error,
|
||||
});
|
||||
|
||||
export {
|
||||
BOOKMARKED_STATUSES_FETCH_REQUEST,
|
||||
BOOKMARKED_STATUSES_FETCH_SUCCESS,
|
||||
BOOKMARKED_STATUSES_FETCH_FAIL,
|
||||
BOOKMARKED_STATUSES_EXPAND_REQUEST,
|
||||
BOOKMARKED_STATUSES_EXPAND_SUCCESS,
|
||||
BOOKMARKED_STATUSES_EXPAND_FAIL,
|
||||
fetchBookmarkedStatuses,
|
||||
fetchBookmarkedStatusesRequest,
|
||||
fetchBookmarkedStatusesSuccess,
|
||||
fetchBookmarkedStatusesFail,
|
||||
expandBookmarkedStatuses,
|
||||
expandBookmarkedStatusesRequest,
|
||||
expandBookmarkedStatusesSuccess,
|
||||
expandBookmarkedStatusesFail,
|
||||
};
|
|
@ -14,14 +14,6 @@ import {
|
|||
} from 'soapbox/actions/status-quotes.ts';
|
||||
import { STATUS_CREATE_SUCCESS } from 'soapbox/actions/statuses.ts';
|
||||
|
||||
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 '../actions/bookmarks.ts';
|
||||
import {
|
||||
RECENT_EVENTS_FETCH_REQUEST,
|
||||
RECENT_EVENTS_FETCH_SUCCESS,
|
||||
|
@ -156,16 +148,6 @@ export default function statusLists(state = initialState, action: AnyAction) {
|
|||
return normalizeList(state, `favourites:${action.accountId}`, action.statuses, action.next);
|
||||
case ACCOUNT_FAVOURITED_STATUSES_EXPAND_SUCCESS:
|
||||
return appendToList(state, `favourites:${action.accountId}`, action.statuses, action.next);
|
||||
case BOOKMARKED_STATUSES_FETCH_REQUEST:
|
||||
case BOOKMARKED_STATUSES_EXPAND_REQUEST:
|
||||
return setLoading(state, 'bookmarks', true);
|
||||
case BOOKMARKED_STATUSES_FETCH_FAIL:
|
||||
case BOOKMARKED_STATUSES_EXPAND_FAIL:
|
||||
return setLoading(state, 'bookmarks', 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:
|
||||
|
|
Loading…
Reference in New Issue