StatusActionBar: create toggle actions for status interactions
This commit is contained in:
parent
33fbb0f147
commit
522eba4b25
3 changed files with 59 additions and 31 deletions
|
@ -94,6 +94,15 @@ const unreblog = (status: StatusEntity) =>
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleReblog = (status: StatusEntity) =>
|
||||||
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
|
if (status.reblogged) {
|
||||||
|
dispatch(unreblog(status));
|
||||||
|
} else {
|
||||||
|
dispatch(reblog(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const reblogRequest = (status: StatusEntity) => ({
|
const reblogRequest = (status: StatusEntity) => ({
|
||||||
type: REBLOG_REQUEST,
|
type: REBLOG_REQUEST,
|
||||||
status: status,
|
status: status,
|
||||||
|
@ -158,6 +167,16 @@ const unfavourite = (status: StatusEntity) =>
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleFavourite = (status: StatusEntity) =>
|
||||||
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
|
if (status.favourited) {
|
||||||
|
dispatch(favourite(status));
|
||||||
|
} else {
|
||||||
|
dispatch(unfavourite(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const favouriteRequest = (status: StatusEntity) => ({
|
const favouriteRequest = (status: StatusEntity) => ({
|
||||||
type: FAVOURITE_REQUEST,
|
type: FAVOURITE_REQUEST,
|
||||||
status: status,
|
status: status,
|
||||||
|
@ -222,6 +241,15 @@ 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) => ({
|
const bookmarkRequest = (status: StatusEntity) => ({
|
||||||
type: BOOKMARK_REQUEST,
|
type: BOOKMARK_REQUEST,
|
||||||
status: status,
|
status: status,
|
||||||
|
@ -394,6 +422,15 @@ const unpin = (status: StatusEntity) =>
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const togglePin = (status: StatusEntity) =>
|
||||||
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
|
if (status.pinned) {
|
||||||
|
dispatch(unpin(status));
|
||||||
|
} else {
|
||||||
|
dispatch(pin(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const unpinRequest = (status: StatusEntity) => ({
|
const unpinRequest = (status: StatusEntity) => ({
|
||||||
type: UNPIN_REQUEST,
|
type: UNPIN_REQUEST,
|
||||||
status,
|
status,
|
||||||
|
@ -488,6 +525,7 @@ export {
|
||||||
REMOTE_INTERACTION_FAIL,
|
REMOTE_INTERACTION_FAIL,
|
||||||
reblog,
|
reblog,
|
||||||
unreblog,
|
unreblog,
|
||||||
|
toggleReblog,
|
||||||
reblogRequest,
|
reblogRequest,
|
||||||
reblogSuccess,
|
reblogSuccess,
|
||||||
reblogFail,
|
reblogFail,
|
||||||
|
@ -496,6 +534,7 @@ export {
|
||||||
unreblogFail,
|
unreblogFail,
|
||||||
favourite,
|
favourite,
|
||||||
unfavourite,
|
unfavourite,
|
||||||
|
toggleFavourite,
|
||||||
favouriteRequest,
|
favouriteRequest,
|
||||||
favouriteSuccess,
|
favouriteSuccess,
|
||||||
favouriteFail,
|
favouriteFail,
|
||||||
|
@ -504,6 +543,7 @@ export {
|
||||||
unfavouriteFail,
|
unfavouriteFail,
|
||||||
bookmark,
|
bookmark,
|
||||||
unbookmark,
|
unbookmark,
|
||||||
|
toggleBookmark,
|
||||||
bookmarkRequest,
|
bookmarkRequest,
|
||||||
bookmarkSuccess,
|
bookmarkSuccess,
|
||||||
bookmarkFail,
|
bookmarkFail,
|
||||||
|
@ -530,6 +570,7 @@ export {
|
||||||
unpinRequest,
|
unpinRequest,
|
||||||
unpinSuccess,
|
unpinSuccess,
|
||||||
unpinFail,
|
unpinFail,
|
||||||
|
togglePin,
|
||||||
remoteInteraction,
|
remoteInteraction,
|
||||||
remoteInteractionRequest,
|
remoteInteractionRequest,
|
||||||
remoteInteractionSuccess,
|
remoteInteractionSuccess,
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { openModal } from './modals';
|
||||||
import { deleteFromTimelines } from './timelines';
|
import { deleteFromTimelines } from './timelines';
|
||||||
|
|
||||||
import type { AppDispatch, RootState } from 'soapbox/store';
|
import type { AppDispatch, RootState } from 'soapbox/store';
|
||||||
import type { APIEntity } from 'soapbox/types/entities';
|
import type { APIEntity, Status } from 'soapbox/types/entities';
|
||||||
|
|
||||||
const STATUS_CREATE_REQUEST = 'STATUS_CREATE_REQUEST';
|
const STATUS_CREATE_REQUEST = 'STATUS_CREATE_REQUEST';
|
||||||
const STATUS_CREATE_SUCCESS = 'STATUS_CREATE_SUCCESS';
|
const STATUS_CREATE_SUCCESS = 'STATUS_CREATE_SUCCESS';
|
||||||
|
@ -266,6 +266,15 @@ const unmuteStatus = (id: string) =>
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleMuteStatus = (status: Status) =>
|
||||||
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
|
if (status.muted) {
|
||||||
|
dispatch(unmuteStatus(status.id));
|
||||||
|
} else {
|
||||||
|
dispatch(muteStatus(status.id));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const hideStatus = (ids: string[] | string) => {
|
const hideStatus = (ids: string[] | string) => {
|
||||||
if (!Array.isArray(ids)) {
|
if (!Array.isArray(ids)) {
|
||||||
ids = [ids];
|
ids = [ids];
|
||||||
|
@ -324,6 +333,7 @@ export {
|
||||||
fetchStatusWithContext,
|
fetchStatusWithContext,
|
||||||
muteStatus,
|
muteStatus,
|
||||||
unmuteStatus,
|
unmuteStatus,
|
||||||
|
toggleMuteStatus,
|
||||||
hideStatus,
|
hideStatus,
|
||||||
revealStatus,
|
revealStatus,
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,12 +7,12 @@ import { blockAccount } from 'soapbox/actions/accounts';
|
||||||
import { showAlertForError } from 'soapbox/actions/alerts';
|
import { showAlertForError } from 'soapbox/actions/alerts';
|
||||||
import { launchChat } from 'soapbox/actions/chats';
|
import { launchChat } from 'soapbox/actions/chats';
|
||||||
import { directCompose, mentionCompose, quoteCompose, replyCompose } from 'soapbox/actions/compose';
|
import { directCompose, mentionCompose, quoteCompose, replyCompose } from 'soapbox/actions/compose';
|
||||||
import { bookmark, favourite, pin, reblog, unbookmark, unfavourite, unpin, unreblog } from 'soapbox/actions/interactions';
|
import { toggleBookmark, toggleFavourite, togglePin, toggleReblog } from 'soapbox/actions/interactions';
|
||||||
import { openModal } from 'soapbox/actions/modals';
|
import { openModal } from 'soapbox/actions/modals';
|
||||||
import { deactivateUserModal, deleteStatusModal, deleteUserModal, toggleStatusSensitivityModal } from 'soapbox/actions/moderation';
|
import { deactivateUserModal, deleteStatusModal, deleteUserModal, toggleStatusSensitivityModal } from 'soapbox/actions/moderation';
|
||||||
import { initMuteModal } from 'soapbox/actions/mutes';
|
import { initMuteModal } from 'soapbox/actions/mutes';
|
||||||
import { initReport } from 'soapbox/actions/reports';
|
import { initReport } from 'soapbox/actions/reports';
|
||||||
import { deleteStatus, editStatus, muteStatus, unmuteStatus } from 'soapbox/actions/statuses';
|
import { deleteStatus, editStatus, toggleMuteStatus } from 'soapbox/actions/statuses';
|
||||||
import EmojiButtonWrapper from 'soapbox/components/emoji-button-wrapper';
|
import EmojiButtonWrapper from 'soapbox/components/emoji-button-wrapper';
|
||||||
import StatusActionButton from 'soapbox/components/status-action-button';
|
import StatusActionButton from 'soapbox/components/status-action-button';
|
||||||
import DropdownMenuContainer from 'soapbox/containers/dropdown_menu_container';
|
import DropdownMenuContainer from 'soapbox/containers/dropdown_menu_container';
|
||||||
|
@ -142,11 +142,7 @@ const StatusActionBar: React.FC<IStatusActionBar> = ({ status, withDismiss = fal
|
||||||
|
|
||||||
const handleFavouriteClick: React.EventHandler<React.MouseEvent> = (e) => {
|
const handleFavouriteClick: React.EventHandler<React.MouseEvent> = (e) => {
|
||||||
if (me) {
|
if (me) {
|
||||||
if (status.get('favourited')) {
|
toggleFavourite(status);
|
||||||
dispatch(unfavourite(status));
|
|
||||||
} else {
|
|
||||||
dispatch(favourite(status));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
onOpenUnauthorizedModal('FAVOURITE');
|
onOpenUnauthorizedModal('FAVOURITE');
|
||||||
}
|
}
|
||||||
|
@ -156,20 +152,11 @@ const StatusActionBar: React.FC<IStatusActionBar> = ({ status, withDismiss = fal
|
||||||
|
|
||||||
const handleBookmarkClick: React.EventHandler<React.MouseEvent> = (e) => {
|
const handleBookmarkClick: React.EventHandler<React.MouseEvent> = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
dispatch(toggleBookmark(status));
|
||||||
if (status.get('bookmarked')) {
|
|
||||||
dispatch(unbookmark(status));
|
|
||||||
} else {
|
|
||||||
dispatch(bookmark(status));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const modalReblog = () => {
|
const modalReblog = () => {
|
||||||
if (status.get('reblogged')) {
|
dispatch(toggleReblog(status));
|
||||||
dispatch(unreblog(status));
|
|
||||||
} else {
|
|
||||||
dispatch(reblog(status));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReblogClick: React.EventHandler<React.MouseEvent> = e => {
|
const handleReblogClick: React.EventHandler<React.MouseEvent> = e => {
|
||||||
|
@ -241,12 +228,7 @@ const StatusActionBar: React.FC<IStatusActionBar> = ({ status, withDismiss = fal
|
||||||
|
|
||||||
const handlePinClick: React.EventHandler<React.MouseEvent> = (e) => {
|
const handlePinClick: React.EventHandler<React.MouseEvent> = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
dispatch(togglePin(status));
|
||||||
if (status.get('pinned')) {
|
|
||||||
dispatch(unpin(status));
|
|
||||||
} else {
|
|
||||||
dispatch(pin(status));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMentionClick: React.EventHandler<React.MouseEvent> = (e) => {
|
const handleMentionClick: React.EventHandler<React.MouseEvent> = (e) => {
|
||||||
|
@ -307,12 +289,7 @@ const StatusActionBar: React.FC<IStatusActionBar> = ({ status, withDismiss = fal
|
||||||
|
|
||||||
const handleConversationMuteClick: React.EventHandler<React.MouseEvent> = (e) => {
|
const handleConversationMuteClick: React.EventHandler<React.MouseEvent> = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
dispatch(toggleMuteStatus(status));
|
||||||
if (status.get('muted')) {
|
|
||||||
dispatch(unmuteStatus(status.id));
|
|
||||||
} else {
|
|
||||||
dispatch(muteStatus(status.id));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCopy: React.EventHandler<React.MouseEvent> = (e) => {
|
const handleCopy: React.EventHandler<React.MouseEvent> = (e) => {
|
||||||
|
|
Loading…
Reference in a new issue