|
@@ -1,7 +1,7 @@
|
|
|
import React, { FC, useState } from 'react';
|
|
import React, { FC, useState } from 'react';
|
|
|
|
|
|
|
|
import { UncontrolledTooltip, Popover, PopoverBody } from 'reactstrap';
|
|
import { UncontrolledTooltip, Popover, PopoverBody } from 'reactstrap';
|
|
|
-import { withTranslation } from 'react-i18next';
|
|
|
|
|
|
|
+import { useTranslation } from 'react-i18next';
|
|
|
import UserPictureList from './User/UserPictureList';
|
|
import UserPictureList from './User/UserPictureList';
|
|
|
import { withUnstatedContainers } from './UnstatedUtils';
|
|
import { withUnstatedContainers } from './UnstatedUtils';
|
|
|
|
|
|
|
@@ -10,14 +10,17 @@ import { IUser } from '../interfaces/user';
|
|
|
|
|
|
|
|
type LikeButtonsProps = {
|
|
type LikeButtonsProps = {
|
|
|
appContainer: AppContainer,
|
|
appContainer: AppContainer,
|
|
|
|
|
+
|
|
|
|
|
+ hideTotalNumber?: boolean,
|
|
|
sumOfLikers: number,
|
|
sumOfLikers: number,
|
|
|
isLiked: boolean,
|
|
isLiked: boolean,
|
|
|
likers: IUser[],
|
|
likers: IUser[],
|
|
|
onLikeClicked?: ()=>void,
|
|
onLikeClicked?: ()=>void,
|
|
|
- t: (s:string)=>string,
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const LikeButtons: FC<LikeButtonsProps> = (props: LikeButtonsProps) => {
|
|
const LikeButtons: FC<LikeButtonsProps> = (props: LikeButtonsProps) => {
|
|
|
|
|
+ const { t } = useTranslation();
|
|
|
|
|
+
|
|
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
|
|
|
|
|
|
const togglePopover = () => {
|
|
const togglePopover = () => {
|
|
@@ -33,7 +36,7 @@ const LikeButtons: FC<LikeButtonsProps> = (props: LikeButtonsProps) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const {
|
|
const {
|
|
|
- appContainer, isLiked, sumOfLikers, t,
|
|
|
|
|
|
|
+ appContainer, hideTotalNumber, isLiked, sumOfLikers,
|
|
|
} = props;
|
|
} = props;
|
|
|
const { isGuestUser } = appContainer;
|
|
const { isGuestUser } = appContainer;
|
|
|
|
|
|
|
@@ -46,7 +49,7 @@ const LikeButtons: FC<LikeButtonsProps> = (props: LikeButtonsProps) => {
|
|
|
className={`btn btn-like border-0
|
|
className={`btn btn-like border-0
|
|
|
${isLiked ? 'active' : ''} ${isGuestUser ? 'disabled' : ''}`}
|
|
${isLiked ? 'active' : ''} ${isGuestUser ? 'disabled' : ''}`}
|
|
|
>
|
|
>
|
|
|
- <i className="icon-like"></i>
|
|
|
|
|
|
|
+ <i className={`fa ${isLiked ? 'fa-heart' : 'fa-heart-o'}`}></i>
|
|
|
</button>
|
|
</button>
|
|
|
{isGuestUser && (
|
|
{isGuestUser && (
|
|
|
<UncontrolledTooltip placement="top" target="like-button" fade={false}>
|
|
<UncontrolledTooltip placement="top" target="like-button" fade={false}>
|
|
@@ -54,16 +57,20 @@ const LikeButtons: FC<LikeButtonsProps> = (props: LikeButtonsProps) => {
|
|
|
</UncontrolledTooltip>
|
|
</UncontrolledTooltip>
|
|
|
)}
|
|
)}
|
|
|
|
|
|
|
|
- <button type="button" id="po-total-likes" className={`btn btn-like border-0 total-likes ${isLiked ? 'active' : ''}`}>
|
|
|
|
|
- {sumOfLikers}
|
|
|
|
|
- </button>
|
|
|
|
|
- <Popover placement="bottom" isOpen={isPopoverOpen} target="po-total-likes" toggle={togglePopover} trigger="legacy">
|
|
|
|
|
- <PopoverBody className="seen-user-popover">
|
|
|
|
|
- <div className="px-2 text-right user-list-content text-truncate text-muted">
|
|
|
|
|
- {props.likers?.length ? <UserPictureList users={props.likers} /> : t('No users have liked this yet.')}
|
|
|
|
|
- </div>
|
|
|
|
|
- </PopoverBody>
|
|
|
|
|
- </Popover>
|
|
|
|
|
|
|
+ { !hideTotalNumber && (
|
|
|
|
|
+ <>
|
|
|
|
|
+ <button type="button" id="po-total-likes" className={`btn btn-like border-0 total-likes ${isLiked ? 'active' : ''}`}>
|
|
|
|
|
+ {sumOfLikers}
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <Popover placement="bottom" isOpen={isPopoverOpen} target="po-total-likes" toggle={togglePopover} trigger="legacy">
|
|
|
|
|
+ <PopoverBody className="seen-user-popover">
|
|
|
|
|
+ <div className="px-2 text-right user-list-content text-truncate text-muted">
|
|
|
|
|
+ {props.likers?.length ? <UserPictureList users={props.likers} /> : t('No users have liked this yet.')}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </PopoverBody>
|
|
|
|
|
+ </Popover>
|
|
|
|
|
+ </>
|
|
|
|
|
+ ) }
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -74,8 +81,9 @@ const LikeButtons: FC<LikeButtonsProps> = (props: LikeButtonsProps) => {
|
|
|
*/
|
|
*/
|
|
|
const LikeButtonsUnstatedWrapper = withUnstatedContainers(LikeButtons, [AppContainer]);
|
|
const LikeButtonsUnstatedWrapper = withUnstatedContainers(LikeButtons, [AppContainer]);
|
|
|
|
|
|
|
|
|
|
+// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
const LikeButtonsWrapper = (props) => {
|
|
const LikeButtonsWrapper = (props) => {
|
|
|
return <LikeButtonsUnstatedWrapper {...props}></LikeButtonsUnstatedWrapper>;
|
|
return <LikeButtonsUnstatedWrapper {...props}></LikeButtonsUnstatedWrapper>;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-export default withTranslation()(LikeButtonsWrapper);
|
|
|
|
|
|
|
+export default LikeButtonsWrapper;
|