Add api for set emoji reactions to toot
This commit is contained in:
parent
f157a509d6
commit
5f7da7bff1
17 changed files with 276 additions and 18 deletions
|
@ -9,6 +9,10 @@ export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
|
|||
export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
|
||||
export const FAVOURITE_FAIL = 'FAVOURITE_FAIL';
|
||||
|
||||
export const EMOJIREACT_REQUEST = 'EMOJIREACT_REQUEST';
|
||||
export const EMOJIREACT_SUCCESS = 'EMOJIREACT_SUCCESS';
|
||||
export const EMOJIREACT_FAIL = 'EMOJIREACT_FAIL';
|
||||
|
||||
export const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST';
|
||||
export const UNREBLOG_SUCCESS = 'UNREBLOG_SUCCESS';
|
||||
export const UNREBLOG_FAIL = 'UNREBLOG_FAIL';
|
||||
|
@ -17,6 +21,10 @@ export const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST';
|
|||
export const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS';
|
||||
export const UNFAVOURITE_FAIL = 'UNFAVOURITE_FAIL';
|
||||
|
||||
export const UNEMOJIREACT_REQUEST = 'UNEMOJIREACT_REQUEST';
|
||||
export const UNEMOJIREACT_SUCCESS = 'UNEMOJIREACT_SUCCESS';
|
||||
export const UNEMOJIREACT_FAIL = 'UNEMOJIREACT_FAIL';
|
||||
|
||||
export const REBLOGS_FETCH_REQUEST = 'REBLOGS_FETCH_REQUEST';
|
||||
export const REBLOGS_FETCH_SUCCESS = 'REBLOGS_FETCH_SUCCESS';
|
||||
export const REBLOGS_FETCH_FAIL = 'REBLOGS_FETCH_FAIL';
|
||||
|
@ -195,6 +203,89 @@ export function unfavouriteFail(status, error) {
|
|||
};
|
||||
}
|
||||
|
||||
export function emojiReact(status, emoji) {
|
||||
return function (dispatch, getState) {
|
||||
dispatch(emojiReactRequest(status, emoji));
|
||||
console.dir(emoji.custom ? (emoji.name + (emoji.domain || '')) : emoji.native);
|
||||
|
||||
api(getState).put(`/api/v1/statuses/${status.get('id')}/emoji_reactions/${emoji.custom ? (emoji.name + (emoji.domain || '')) : emoji.native}`).then(function (response) {
|
||||
dispatch(importFetchedStatus(response.data));
|
||||
dispatch(emojiReactSuccess(status, emoji));
|
||||
}).catch(function (error) {
|
||||
dispatch(emojiReactFail(status, emoji, error));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function unEmojiReact(status, emoji) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(unEmojiReactRequest(status, emoji));
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${status.get('id')}/emoji_unreactions/${emoji.native}`).then(response => {
|
||||
dispatch(importFetchedStatus(response.data));
|
||||
dispatch(unEmojiReactSuccess(status, emoji));
|
||||
}).catch(error => {
|
||||
dispatch(unEmojiReactFail(status, emoji, error));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function emojiReactRequest(status, emoji) {
|
||||
return {
|
||||
type: EMOJIREACT_REQUEST,
|
||||
status: status,
|
||||
emoji: emoji,
|
||||
skipLoading: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function emojiReactSuccess(status, emoji) {
|
||||
return {
|
||||
type: EMOJIREACT_SUCCESS,
|
||||
status: status,
|
||||
emoji: emoji,
|
||||
skipLoading: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function emojiReactFail(status, emoji, error) {
|
||||
return {
|
||||
type: EMOJIREACT_FAIL,
|
||||
status: status,
|
||||
emoji: emoji,
|
||||
error: error,
|
||||
skipLoading: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function unEmojiReactRequest(status, emoji) {
|
||||
return {
|
||||
type: UNEMOJIREACT_REQUEST,
|
||||
status: status,
|
||||
emoji: emoji,
|
||||
skipLoading: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function unEmojiReactSuccess(status, emoji) {
|
||||
return {
|
||||
type: UNEMOJIREACT_SUCCESS,
|
||||
status: status,
|
||||
emoji: emoji,
|
||||
skipLoading: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function unEmojiReactFail(status, emoji, error) {
|
||||
return {
|
||||
type: UNEMOJIREACT_FAIL,
|
||||
status: status,
|
||||
emoji: emoji,
|
||||
error: error,
|
||||
skipLoading: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function bookmark(status) {
|
||||
return function (dispatch, getState) {
|
||||
dispatch(bookmarkRequest(status));
|
||||
|
|
|
@ -73,6 +73,8 @@ class Status extends ImmutablePureComponent {
|
|||
onClick: PropTypes.func,
|
||||
onReply: PropTypes.func,
|
||||
onFavourite: PropTypes.func,
|
||||
onEmojiReact: PropTypes.func,
|
||||
onUnEmojiReact: PropTypes.func,
|
||||
onReblog: PropTypes.func,
|
||||
onDelete: PropTypes.func,
|
||||
onDirect: PropTypes.func,
|
||||
|
|
|
@ -68,6 +68,7 @@ class StatusActionBar extends ImmutablePureComponent {
|
|||
relationship: ImmutablePropTypes.map,
|
||||
onReply: PropTypes.func,
|
||||
onFavourite: PropTypes.func,
|
||||
onEmojiReact: PropTypes.func,
|
||||
onReblog: PropTypes.func,
|
||||
onDelete: PropTypes.func,
|
||||
onDirect: PropTypes.func,
|
||||
|
@ -129,6 +130,16 @@ class StatusActionBar extends ImmutablePureComponent {
|
|||
}
|
||||
};
|
||||
|
||||
handleEmojiPick = (data) => {
|
||||
const { signedIn } = this.context.identity;
|
||||
|
||||
if (signedIn) {
|
||||
this.props.onEmojiReact(this.props.status, data);
|
||||
} else {
|
||||
this.props.onInteractionModal('favourite', this.props.status);
|
||||
}
|
||||
};
|
||||
|
||||
handleReblogClick = e => {
|
||||
const { signedIn } = this.context.identity;
|
||||
|
||||
|
@ -232,16 +243,6 @@ class StatusActionBar extends ImmutablePureComponent {
|
|||
this.props.onFilter();
|
||||
};
|
||||
|
||||
handleEmojiPick = (data) => {
|
||||
/*
|
||||
const { text } = this.props;
|
||||
const position = this.autosuggestTextarea.textarea.selectionStart;
|
||||
const needsSpace = data.custom && position > 0 && !allowedAroundShortCode.includes(text[position - 1]);
|
||||
|
||||
this.props.onPickEmoji(position, data, needsSpace);
|
||||
*/
|
||||
};
|
||||
|
||||
render () {
|
||||
const { status, relationship, intl, withDismiss, withCounters, scrollKey } = this.props;
|
||||
const { signedIn, permissions } = this.context.identity;
|
||||
|
|
|
@ -8,7 +8,7 @@ import classNames from 'classnames';
|
|||
class EmojiReactionButton extends React.PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
name: ImmutablePropTypes.map,
|
||||
name: PropTypes.string,
|
||||
url: PropTypes.string,
|
||||
staticUrl: PropTypes.string,
|
||||
count: PropTypes.number.isRequired,
|
||||
|
@ -22,7 +22,7 @@ class EmojiReactionButton extends React.PureComponent {
|
|||
let emojiHtml = null;
|
||||
if (url) {
|
||||
let customEmojis = {};
|
||||
customEmojis[name] = { url, static_url: staticUrl };
|
||||
customEmojis[`:${name}:`] = { url, static_url: staticUrl };
|
||||
emojiHtml = emojify(`:${name}:`, customEmojis);
|
||||
} else {
|
||||
emojiHtml = emojify(name);
|
||||
|
@ -47,16 +47,16 @@ export default @injectIntl
|
|||
class StatusEmojiReactionsBar extends React.PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
emojiReactions: ImmutablePropTypes.map.isRequired,
|
||||
emojiReactions: ImmutablePropTypes.list.isRequired,
|
||||
statusId: PropTypes.string,
|
||||
};
|
||||
|
||||
render () {
|
||||
const { emojiReactions, statusId } = this.props;
|
||||
|
||||
const emojiButtons = React.Children.map(emojiReactions, (emoji) => (
|
||||
const emojiButtons = Array.from(emojiReactions).map((emoji, index) => (
|
||||
<EmojiReactionButton
|
||||
key={emoji.get('id')}
|
||||
key={index}
|
||||
name={emoji.get('name')}
|
||||
count={emoji.get('count')}
|
||||
me={emoji.get('me')}
|
||||
|
|
|
@ -10,9 +10,11 @@ import {
|
|||
import {
|
||||
reblog,
|
||||
favourite,
|
||||
emojiReact,
|
||||
bookmark,
|
||||
unreblog,
|
||||
unfavourite,
|
||||
unEmojiReact,
|
||||
unbookmark,
|
||||
pin,
|
||||
unpin,
|
||||
|
@ -113,6 +115,14 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
|
|||
}
|
||||
},
|
||||
|
||||
onEmojiReact (status, emoji) {
|
||||
dispatch(emojiReact(status, emoji));
|
||||
},
|
||||
|
||||
onUnEmojiReact (status, emoji) {
|
||||
dispatch(unEmojiReact(status, emoji));
|
||||
},
|
||||
|
||||
onBookmark (status) {
|
||||
if (status.get('bookmarked')) {
|
||||
dispatch(unbookmark(status));
|
||||
|
|
|
@ -61,6 +61,10 @@ const mapDispatchToProps = dispatch => ({
|
|||
}
|
||||
},
|
||||
|
||||
onEmojiReact (status, emoji) {
|
||||
|
||||
},
|
||||
|
||||
onToggleHidden (status) {
|
||||
if (status.get('hidden')) {
|
||||
dispatch(revealStatus(status.get('id')));
|
||||
|
|
|
@ -93,6 +93,10 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
|
|||
}
|
||||
},
|
||||
|
||||
onEmojiReact (status, emoji) {
|
||||
|
||||
},
|
||||
|
||||
onPin (status) {
|
||||
if (status.get('pinned')) {
|
||||
dispatch(unpin(status));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue