kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Merge branch 'main' into remove-immutable-compose
commit
f4887ab5ab
|
@ -1,6 +1,3 @@
|
||||||
import { defineMessages } from 'react-intl';
|
|
||||||
|
|
||||||
import toast from 'soapbox/toast.tsx';
|
|
||||||
import { isLoggedIn } from 'soapbox/utils/auth.ts';
|
import { isLoggedIn } from 'soapbox/utils/auth.ts';
|
||||||
|
|
||||||
import api from '../api/index.ts';
|
import api from '../api/index.ts';
|
||||||
|
@ -61,11 +58,9 @@ const UNPIN_SUCCESS = 'UNPIN_SUCCESS';
|
||||||
const UNPIN_FAIL = 'UNPIN_FAIL';
|
const UNPIN_FAIL = 'UNPIN_FAIL';
|
||||||
|
|
||||||
const BOOKMARK_REQUEST = 'BOOKMARK_REQUEST';
|
const BOOKMARK_REQUEST = 'BOOKMARK_REQUEST';
|
||||||
const BOOKMARK_SUCCESS = 'BOOKMARKED_SUCCESS';
|
|
||||||
const BOOKMARK_FAIL = 'BOOKMARKED_FAIL';
|
const BOOKMARK_FAIL = 'BOOKMARKED_FAIL';
|
||||||
|
|
||||||
const UNBOOKMARK_REQUEST = 'UNBOOKMARKED_REQUEST';
|
const UNBOOKMARK_REQUEST = 'UNBOOKMARKED_REQUEST';
|
||||||
const UNBOOKMARK_SUCCESS = 'UNBOOKMARKED_SUCCESS';
|
|
||||||
const UNBOOKMARK_FAIL = 'UNBOOKMARKED_FAIL';
|
const UNBOOKMARK_FAIL = 'UNBOOKMARKED_FAIL';
|
||||||
|
|
||||||
const REMOTE_INTERACTION_REQUEST = 'REMOTE_INTERACTION_REQUEST';
|
const REMOTE_INTERACTION_REQUEST = 'REMOTE_INTERACTION_REQUEST';
|
||||||
|
@ -89,12 +84,6 @@ const ZAPS_FETCH_FAIL = 'ZAPS_FETCH_FAIL';
|
||||||
const ZAPS_EXPAND_SUCCESS = 'ZAPS_EXPAND_SUCCESS';
|
const ZAPS_EXPAND_SUCCESS = 'ZAPS_EXPAND_SUCCESS';
|
||||||
const ZAPS_EXPAND_FAIL = 'ZAPS_EXPAND_FAIL';
|
const ZAPS_EXPAND_FAIL = 'ZAPS_EXPAND_FAIL';
|
||||||
|
|
||||||
const messages = defineMessages({
|
|
||||||
bookmarkAdded: { id: 'status.bookmarked', defaultMessage: 'Bookmark added.' },
|
|
||||||
bookmarkRemoved: { id: 'status.unbookmarked', defaultMessage: 'Bookmark removed.' },
|
|
||||||
view: { id: 'toast.view', defaultMessage: 'View' },
|
|
||||||
});
|
|
||||||
|
|
||||||
type ReblogEffects = {
|
type ReblogEffects = {
|
||||||
reblogEffect: (statusId: string) => void;
|
reblogEffect: (statusId: string) => void;
|
||||||
unreblogEffect: (statusId: string) => void;
|
unreblogEffect: (statusId: string) => void;
|
||||||
|
@ -368,55 +357,11 @@ const zapFail = (status: StatusEntity, error: unknown) => ({
|
||||||
skipLoading: true,
|
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));
|
|
||||||
|
|
||||||
api(getState).post(`/api/v1/statuses/${status.id}/unbookmark`).then((response) => response.json()).then((data) => {
|
|
||||||
dispatch(importFetchedStatus(data));
|
|
||||||
dispatch(unbookmarkSuccess(status, data));
|
|
||||||
toast.success(messages.bookmarkRemoved);
|
|
||||||
}).catch(error => {
|
|
||||||
dispatch(unbookmarkFail(status, error));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggleBookmark = (status: StatusEntity) =>
|
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
||||||
if (status.bookmarked) {
|
|
||||||
dispatch(unbookmark(status));
|
|
||||||
} else {
|
|
||||||
dispatch(bookmark(status));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const bookmarkRequest = (status: StatusEntity) => ({
|
const bookmarkRequest = (status: StatusEntity) => ({
|
||||||
type: BOOKMARK_REQUEST,
|
type: BOOKMARK_REQUEST,
|
||||||
status: status,
|
status: status,
|
||||||
});
|
});
|
||||||
|
|
||||||
const bookmarkSuccess = (status: StatusEntity, response: APIEntity) => ({
|
|
||||||
type: BOOKMARK_SUCCESS,
|
|
||||||
status: status,
|
|
||||||
response: response,
|
|
||||||
});
|
|
||||||
|
|
||||||
const bookmarkFail = (status: StatusEntity, error: unknown) => ({
|
const bookmarkFail = (status: StatusEntity, error: unknown) => ({
|
||||||
type: BOOKMARK_FAIL,
|
type: BOOKMARK_FAIL,
|
||||||
status: status,
|
status: status,
|
||||||
|
@ -428,12 +373,6 @@ const unbookmarkRequest = (status: StatusEntity) => ({
|
||||||
status: status,
|
status: status,
|
||||||
});
|
});
|
||||||
|
|
||||||
const unbookmarkSuccess = (status: StatusEntity, response: APIEntity) => ({
|
|
||||||
type: UNBOOKMARK_SUCCESS,
|
|
||||||
status: status,
|
|
||||||
response: response,
|
|
||||||
});
|
|
||||||
|
|
||||||
const unbookmarkFail = (status: StatusEntity, error: unknown) => ({
|
const unbookmarkFail = (status: StatusEntity, error: unknown) => ({
|
||||||
type: UNBOOKMARK_FAIL,
|
type: UNBOOKMARK_FAIL,
|
||||||
status: status,
|
status: status,
|
||||||
|
@ -844,10 +783,8 @@ export {
|
||||||
UNPIN_SUCCESS,
|
UNPIN_SUCCESS,
|
||||||
UNPIN_FAIL,
|
UNPIN_FAIL,
|
||||||
BOOKMARK_REQUEST,
|
BOOKMARK_REQUEST,
|
||||||
BOOKMARK_SUCCESS,
|
|
||||||
BOOKMARK_FAIL,
|
BOOKMARK_FAIL,
|
||||||
UNBOOKMARK_REQUEST,
|
UNBOOKMARK_REQUEST,
|
||||||
UNBOOKMARK_SUCCESS,
|
|
||||||
UNBOOKMARK_FAIL,
|
UNBOOKMARK_FAIL,
|
||||||
REMOTE_INTERACTION_REQUEST,
|
REMOTE_INTERACTION_REQUEST,
|
||||||
REMOTE_INTERACTION_SUCCESS,
|
REMOTE_INTERACTION_SUCCESS,
|
||||||
|
@ -890,14 +827,9 @@ export {
|
||||||
undislikeRequest,
|
undislikeRequest,
|
||||||
undislikeSuccess,
|
undislikeSuccess,
|
||||||
undislikeFail,
|
undislikeFail,
|
||||||
bookmark,
|
|
||||||
unbookmark,
|
|
||||||
toggleBookmark,
|
|
||||||
bookmarkRequest,
|
bookmarkRequest,
|
||||||
bookmarkSuccess,
|
|
||||||
bookmarkFail,
|
bookmarkFail,
|
||||||
unbookmarkRequest,
|
unbookmarkRequest,
|
||||||
unbookmarkSuccess,
|
|
||||||
unbookmarkFail,
|
unbookmarkFail,
|
||||||
fetchReblogs,
|
fetchReblogs,
|
||||||
fetchReblogsRequest,
|
fetchReblogsRequest,
|
||||||
|
|
|
@ -29,12 +29,13 @@ import { blockAccount } from 'soapbox/actions/accounts.ts';
|
||||||
import { launchChat } from 'soapbox/actions/chats.ts';
|
import { launchChat } from 'soapbox/actions/chats.ts';
|
||||||
import { directCompose, mentionCompose, quoteCompose } from 'soapbox/actions/compose.ts';
|
import { directCompose, mentionCompose, quoteCompose } from 'soapbox/actions/compose.ts';
|
||||||
import { editEvent, fetchEventIcs } from 'soapbox/actions/events.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 { openModal } from 'soapbox/actions/modals.ts';
|
||||||
import { deleteStatusModal, toggleStatusSensitivityModal } from 'soapbox/actions/moderation.tsx';
|
import { deleteStatusModal, toggleStatusSensitivityModal } from 'soapbox/actions/moderation.tsx';
|
||||||
import { initMuteModal } from 'soapbox/actions/mutes.ts';
|
import { initMuteModal } from 'soapbox/actions/mutes.ts';
|
||||||
import { initReport, ReportableEntities } from 'soapbox/actions/reports.ts';
|
import { initReport, ReportableEntities } from 'soapbox/actions/reports.ts';
|
||||||
import { deleteStatus } from 'soapbox/actions/statuses.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 StillImage from 'soapbox/components/still-image.tsx';
|
||||||
import Button from 'soapbox/components/ui/button.tsx';
|
import Button from 'soapbox/components/ui/button.tsx';
|
||||||
import HStack from 'soapbox/components/ui/hstack.tsx';
|
import HStack from 'soapbox/components/ui/hstack.tsx';
|
||||||
|
@ -106,6 +107,7 @@ const EventHeader: React.FC<IEventHeader> = ({ status }) => {
|
||||||
const { account: ownAccount } = useOwnAccount();
|
const { account: ownAccount } = useOwnAccount();
|
||||||
const isStaff = ownAccount ? ownAccount.staff : false;
|
const isStaff = ownAccount ? ownAccount.staff : false;
|
||||||
const isAdmin = ownAccount ? ownAccount.admin : false;
|
const isAdmin = ownAccount ? ownAccount.admin : false;
|
||||||
|
const { bookmark, unbookmark } = useBookmark();
|
||||||
|
|
||||||
const { toggleReblog } = useReblog();
|
const { toggleReblog } = useReblog();
|
||||||
|
|
||||||
|
@ -147,7 +149,11 @@ const EventHeader: React.FC<IEventHeader> = ({ status }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBookmarkClick = () => {
|
const handleBookmarkClick = () => {
|
||||||
dispatch(toggleBookmark(status));
|
if (status.bookmarked) {
|
||||||
|
unbookmark(status.id);
|
||||||
|
} else {
|
||||||
|
bookmark(status.id);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReblogClick = () => {
|
const handleReblogClick = () => {
|
||||||
|
|
|
@ -39,8 +39,6 @@ import {
|
||||||
import {
|
import {
|
||||||
FAVOURITE_SUCCESS,
|
FAVOURITE_SUCCESS,
|
||||||
UNFAVOURITE_SUCCESS,
|
UNFAVOURITE_SUCCESS,
|
||||||
BOOKMARK_SUCCESS,
|
|
||||||
UNBOOKMARK_SUCCESS,
|
|
||||||
PIN_SUCCESS,
|
PIN_SUCCESS,
|
||||||
UNPIN_SUCCESS,
|
UNPIN_SUCCESS,
|
||||||
} from '../actions/interactions.ts';
|
} from '../actions/interactions.ts';
|
||||||
|
@ -73,7 +71,6 @@ type StatusList = ReturnType<typeof StatusListRecord>;
|
||||||
|
|
||||||
const initialState: State = ImmutableMap({
|
const initialState: State = ImmutableMap({
|
||||||
favourites: StatusListRecord(),
|
favourites: StatusListRecord(),
|
||||||
bookmarks: StatusListRecord(),
|
|
||||||
pins: StatusListRecord(),
|
pins: StatusListRecord(),
|
||||||
scheduled_statuses: StatusListRecord(),
|
scheduled_statuses: StatusListRecord(),
|
||||||
recent_events: StatusListRecord(),
|
recent_events: StatusListRecord(),
|
||||||
|
@ -152,10 +149,6 @@ export default function statusLists(state = initialState, action: AnyAction) {
|
||||||
return prependOneToList(state, 'favourites', action.status);
|
return prependOneToList(state, 'favourites', action.status);
|
||||||
case UNFAVOURITE_SUCCESS:
|
case UNFAVOURITE_SUCCESS:
|
||||||
return removeOneFromList(state, 'favourites', action.status);
|
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:
|
case PINNED_STATUSES_FETCH_SUCCESS:
|
||||||
return normalizeList(state, 'pins', action.statuses, action.next);
|
return normalizeList(state, 'pins', action.statuses, action.next);
|
||||||
case PIN_SUCCESS:
|
case PIN_SUCCESS:
|
||||||
|
|
Ładowanie…
Reference in New Issue