File size: 1,657 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { useContext } from 'react';
import { connect } from 'react-redux';
import { RestClientContext } from '../Notifications';
import { keys } from '../helpers/input';
import { getReferenceId } from '../helpers/notes';
import { setLikeStatus } from '../state/notes/thunks/index';
import ActionButton from './action-button';
// eslint-disable-next-line no-shadow
const LikeButton = ( { commentId, isLiked, note, translate, setLikeStatus } ) => {
const restClient = useContext( RestClientContext );
let title;
if ( isLiked ) {
if ( commentId ) {
title = translate( 'Remove like from comment' );
} else {
title = translate( 'Remove like from post' );
}
} else if ( commentId ) {
title = translate( 'Like comment', { context: 'verb: imperative' } );
} else {
title = translate( 'Like post', { context: 'verb: imperative' } );
}
return (
<ActionButton
icon="star"
isActive={ isLiked }
hotkey={ keys.KEY_L }
onToggle={ () =>
setLikeStatus(
note.id,
getReferenceId( note, 'site' ),
getReferenceId( note, 'post' ),
getReferenceId( note, 'comment' ),
! isLiked,
restClient
)
}
text={
isLiked
? translate( 'Liked', { context: 'verb: past-tense' } )
: translate( 'Like', { context: 'verb: imperative' } )
}
title={ title }
/>
);
};
LikeButton.propTypes = {
commentId: PropTypes.number,
isLiked: PropTypes.bool.isRequired,
note: PropTypes.object.isRequired,
translate: PropTypes.func.isRequired,
};
export default connect( null, { setLikeStatus } )( localize( LikeButton ) );
|