2021-06-18 17:22:44 +02:00
|
|
|
// @flow
|
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import React, { useRef } from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import useHover from 'effects/use-hover';
|
2021-10-08 05:47:39 +02:00
|
|
|
import * as COLLECTIONS_CONSTS from 'constants/collections';
|
2021-06-18 17:22:44 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
claim: StreamClaim,
|
2021-07-15 22:14:21 +02:00
|
|
|
focusable: boolean,
|
2021-06-18 17:22:44 +02:00
|
|
|
hasClaimInWatchLater: boolean,
|
|
|
|
doToast: ({ message: string }) => void,
|
|
|
|
doCollectionEdit: (string, any) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
function FileWatchLaterLink(props: Props) {
|
2021-07-15 22:14:21 +02:00
|
|
|
const { claim, hasClaimInWatchLater, doToast, doCollectionEdit, focusable = true } = props;
|
2021-06-18 17:22:44 +02:00
|
|
|
const buttonRef = useRef();
|
|
|
|
let isHovering = useHover(buttonRef);
|
|
|
|
|
|
|
|
if (!claim) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleWatchLater(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
doToast({
|
2021-07-18 16:39:43 +02:00
|
|
|
message: hasClaimInWatchLater ? __('Item removed from Watch Later') : __('Item added to Watch Later'),
|
2021-06-18 17:22:44 +02:00
|
|
|
linkText: !hasClaimInWatchLater && __('See All'),
|
|
|
|
linkTarget: !hasClaimInWatchLater && '/list/watchlater',
|
|
|
|
});
|
|
|
|
doCollectionEdit(COLLECTIONS_CONSTS.WATCH_LATER_ID, {
|
|
|
|
claims: [claim],
|
|
|
|
remove: hasClaimInWatchLater,
|
|
|
|
type: 'playlist',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-25 17:44:08 +02:00
|
|
|
// text that will show if you keep cursor over button
|
2021-06-18 17:22:44 +02:00
|
|
|
const title = hasClaimInWatchLater ? __('Remove from Watch Later') : __('Add to Watch Later');
|
2021-08-25 17:44:08 +02:00
|
|
|
|
|
|
|
// label that is shown after hover
|
2021-06-18 17:22:44 +02:00
|
|
|
const label = !hasClaimInWatchLater ? __('Add') : __('Added');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
ref={buttonRef}
|
|
|
|
requiresAuth={IS_WEB}
|
|
|
|
title={title}
|
|
|
|
label={label}
|
|
|
|
className="button--file-action"
|
2021-07-15 22:14:21 +02:00
|
|
|
icon={
|
|
|
|
(hasClaimInWatchLater && (isHovering ? ICONS.REMOVE : ICONS.COMPLETED)) ||
|
|
|
|
(isHovering ? ICONS.COMPLETED : ICONS.TIME)
|
|
|
|
}
|
2021-06-18 17:22:44 +02:00
|
|
|
onClick={(e) => handleWatchLater(e)}
|
2021-07-15 22:14:21 +02:00
|
|
|
tabIndex={focusable ? 0 : -1}
|
2021-06-18 17:22:44 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileWatchLaterLink;
|