kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
refactor: remove BOOKMARK_SUCCESS fragments
rodzic
4f9eefd524
commit
40fbdd952c
|
@ -61,7 +61,6 @@ const UNPIN_SUCCESS = 'UNPIN_SUCCESS';
|
|||
const UNPIN_FAIL = 'UNPIN_FAIL';
|
||||
|
||||
const BOOKMARK_REQUEST = 'BOOKMARK_REQUEST';
|
||||
const BOOKMARK_SUCCESS = 'BOOKMARKED_SUCCESS';
|
||||
const BOOKMARK_FAIL = 'BOOKMARKED_FAIL';
|
||||
|
||||
const UNBOOKMARK_REQUEST = 'UNBOOKMARKED_REQUEST';
|
||||
|
@ -368,22 +367,6 @@ const zapFail = (status: StatusEntity, error: unknown) => ({
|
|||
skipLoading: true,
|
||||
});
|
||||
|
||||
const bookmark = (status: StatusEntity) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch(bookmarkRequest(status));
|
||||
|
||||
return api(getState).post(`/api/v1/statuses/${status.id}/bookmark`).then((response) => response.json()).then((data) => {
|
||||
dispatch(importFetchedStatus(data));
|
||||
dispatch(bookmarkSuccess(status, data));
|
||||
|
||||
toast.success(messages.bookmarkAdded, {
|
||||
actionLink: '/bookmarks/all', actionLabel: messages.view,
|
||||
});
|
||||
}).catch(function(error) {
|
||||
dispatch(bookmarkFail(status, error));
|
||||
});
|
||||
};
|
||||
|
||||
const unbookmark = (status: StatusEntity) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch(unbookmarkRequest(status));
|
||||
|
@ -397,26 +380,11 @@ const unbookmark = (status: StatusEntity) =>
|
|||
});
|
||||
};
|
||||
|
||||
const toggleBookmark = (status: StatusEntity) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (status.bookmarked) {
|
||||
dispatch(unbookmark(status));
|
||||
} else {
|
||||
dispatch(bookmark(status));
|
||||
}
|
||||
};
|
||||
|
||||
const bookmarkRequest = (status: StatusEntity) => ({
|
||||
type: BOOKMARK_REQUEST,
|
||||
status: status,
|
||||
});
|
||||
|
||||
const bookmarkSuccess = (status: StatusEntity, response: APIEntity) => ({
|
||||
type: BOOKMARK_SUCCESS,
|
||||
status: status,
|
||||
response: response,
|
||||
});
|
||||
|
||||
const bookmarkFail = (status: StatusEntity, error: unknown) => ({
|
||||
type: BOOKMARK_FAIL,
|
||||
status: status,
|
||||
|
@ -844,7 +812,6 @@ export {
|
|||
UNPIN_SUCCESS,
|
||||
UNPIN_FAIL,
|
||||
BOOKMARK_REQUEST,
|
||||
BOOKMARK_SUCCESS,
|
||||
BOOKMARK_FAIL,
|
||||
UNBOOKMARK_REQUEST,
|
||||
UNBOOKMARK_SUCCESS,
|
||||
|
@ -890,11 +857,8 @@ export {
|
|||
undislikeRequest,
|
||||
undislikeSuccess,
|
||||
undislikeFail,
|
||||
bookmark,
|
||||
unbookmark,
|
||||
toggleBookmark,
|
||||
bookmarkRequest,
|
||||
bookmarkSuccess,
|
||||
bookmarkFail,
|
||||
unbookmarkRequest,
|
||||
unbookmarkSuccess,
|
||||
|
|
|
@ -29,12 +29,13 @@ import { blockAccount } from 'soapbox/actions/accounts.ts';
|
|||
import { launchChat } from 'soapbox/actions/chats.ts';
|
||||
import { directCompose, mentionCompose, quoteCompose } from 'soapbox/actions/compose.ts';
|
||||
import { editEvent, fetchEventIcs } from 'soapbox/actions/events.ts';
|
||||
import { toggleBookmark, togglePin } from 'soapbox/actions/interactions.ts';
|
||||
import { togglePin } from 'soapbox/actions/interactions.ts';
|
||||
import { openModal } from 'soapbox/actions/modals.ts';
|
||||
import { deleteStatusModal, toggleStatusSensitivityModal } from 'soapbox/actions/moderation.tsx';
|
||||
import { initMuteModal } from 'soapbox/actions/mutes.ts';
|
||||
import { initReport, ReportableEntities } from 'soapbox/actions/reports.ts';
|
||||
import { deleteStatus } from 'soapbox/actions/statuses.ts';
|
||||
import { useBookmark } from 'soapbox/api/hooks/index.ts';
|
||||
import StillImage from 'soapbox/components/still-image.tsx';
|
||||
import Button from 'soapbox/components/ui/button.tsx';
|
||||
import HStack from 'soapbox/components/ui/hstack.tsx';
|
||||
|
@ -106,6 +107,7 @@ const EventHeader: React.FC<IEventHeader> = ({ status }) => {
|
|||
const { account: ownAccount } = useOwnAccount();
|
||||
const isStaff = ownAccount ? ownAccount.staff : false;
|
||||
const isAdmin = ownAccount ? ownAccount.admin : false;
|
||||
const { bookmark, unbookmark } = useBookmark();
|
||||
|
||||
const { toggleReblog } = useReblog();
|
||||
|
||||
|
@ -147,7 +149,11 @@ const EventHeader: React.FC<IEventHeader> = ({ status }) => {
|
|||
};
|
||||
|
||||
const handleBookmarkClick = () => {
|
||||
dispatch(toggleBookmark(status));
|
||||
if (status.bookmarked) {
|
||||
unbookmark(status.id);
|
||||
} else {
|
||||
bookmark(status.id);
|
||||
}
|
||||
};
|
||||
|
||||
const handleReblogClick = () => {
|
||||
|
|
|
@ -39,7 +39,6 @@ import {
|
|||
import {
|
||||
FAVOURITE_SUCCESS,
|
||||
UNFAVOURITE_SUCCESS,
|
||||
BOOKMARK_SUCCESS,
|
||||
UNBOOKMARK_SUCCESS,
|
||||
PIN_SUCCESS,
|
||||
UNPIN_SUCCESS,
|
||||
|
@ -152,8 +151,6 @@ export default function statusLists(state = initialState, action: AnyAction) {
|
|||
return prependOneToList(state, 'favourites', action.status);
|
||||
case UNFAVOURITE_SUCCESS:
|
||||
return removeOneFromList(state, 'favourites', action.status);
|
||||
case BOOKMARK_SUCCESS:
|
||||
return prependOneToList(state, 'bookmarks', action.response);
|
||||
case UNBOOKMARK_SUCCESS:
|
||||
return removeOneFromList(state, 'bookmarks', action.status);
|
||||
case PINNED_STATUSES_FETCH_SUCCESS:
|
||||
|
|
Ładowanie…
Reference in New Issue