// @flow import * as ICONS from 'constants/icons'; import React, { useRef } from 'react'; import { parseURI } from 'lbry-redux'; import Button from 'component/button'; import useHover from 'effects/use-hover'; import { useIsMobile } from 'effects/use-screensize'; type SubscriptionArgs = { channelName: string, uri: string, notificationsDisabled?: boolean, }; type Props = { permanentUrl: ?string, isSubscribed: boolean, doChannelSubscribe: (SubscriptionArgs) => void, doChannelUnsubscribe: (SubscriptionArgs) => void, showSnackBarOnSubscribe: boolean, doToast: ({ message: string }) => void, shrinkOnMobile: boolean, notificationsDisabled: boolean, user: ?User, uri: string, }; export default function SubscribeButton(props: Props) { const { permanentUrl, doChannelSubscribe, doChannelUnsubscribe, isSubscribed, showSnackBarOnSubscribe, doToast, shrinkOnMobile = false, notificationsDisabled, user, uri, } = props; const buttonRef = useRef(); const isMobile = useIsMobile(); let isHovering = useHover(buttonRef); isHovering = isMobile ? true : isHovering; const { channelName: rawChannelName } = parseURI(uri); const { channelName } = parseURI(permanentUrl); const claimName = '@' + channelName; const subscriptionHandler = isSubscribed ? doChannelUnsubscribe : doChannelSubscribe; const subscriptionLabel = isSubscribed ? __('Following --[button label indicating a channel has been followed]--') : __('Follow'); const unfollowOverride = isSubscribed && isHovering && __('Unfollow'); const label = isMobile && shrinkOnMobile ? '' : unfollowOverride || subscriptionLabel; const titlePrefix = isSubscribed ? __('Unfollow this channel') : __('Follow this channel'); if (isSubscribed && !permanentUrl && rawChannelName) { return (
); } return permanentUrl ? (
) : null; }