lbry-desktop/src/renderer/component/subscribeButton/view.jsx

68 lines
1.6 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import * as MODALS from 'constants/modal_types';
import * as ICONS from 'constants/icons';
import React from 'react';
2018-11-21 22:20:55 +01:00
import { parseURI } from 'lbry-redux';
2018-03-26 23:32:43 +02:00
import Button from 'component/button';
type SubscribtionArgs = {
channelName: string,
uri: string,
};
type Props = {
2018-11-21 22:20:55 +01:00
uri: string,
2018-10-19 22:38:07 +02:00
isSubscribed: boolean,
subscriptions: Array<string>,
2018-03-26 23:32:43 +02:00
doChannelSubscribe: ({ channelName: string, uri: string }) => void,
doChannelUnsubscribe: SubscribtionArgs => void,
doOpenModal: (id: string) => void,
2018-11-21 22:20:55 +01:00
showSnackBarOnSubscribe: boolean,
doToast: ({ message: string }) => void,
buttonStyle: string,
2018-03-26 23:32:43 +02:00
};
export default (props: Props) => {
const {
uri,
doChannelSubscribe,
doChannelUnsubscribe,
doOpenModal,
2018-10-19 22:38:07 +02:00
subscriptions,
isSubscribed,
2018-11-21 22:20:55 +01:00
showSnackBarOnSubscribe,
doToast,
buttonStyle,
2018-03-26 23:32:43 +02:00
} = props;
2017-12-08 21:38:20 +01:00
const subscriptionHandler = isSubscribed ? doChannelUnsubscribe : doChannelSubscribe;
const subscriptionLabel = isSubscribed ? __('Unsubscribe') : __('Subscribe');
2017-12-08 21:38:20 +01:00
2018-11-21 22:20:55 +01:00
const { claimName } = parseURI(uri);
return (
2018-03-26 23:32:43 +02:00
<Button
iconColor="red"
icon={isSubscribed ? undefined : ICONS.HEART}
button={buttonStyle || 'alt'}
2018-03-26 23:32:43 +02:00
label={subscriptionLabel}
onClick={e => {
e.stopPropagation();
if (!subscriptions.length) {
doOpenModal(MODALS.FIRST_SUBSCRIPTION);
2018-03-26 23:32:43 +02:00
}
2018-11-21 22:20:55 +01:00
2018-03-26 23:32:43 +02:00
subscriptionHandler({
2018-11-21 22:20:55 +01:00
channelName: claimName,
2018-03-26 23:32:43 +02:00
uri,
});
2018-11-21 22:20:55 +01:00
if (showSnackBarOnSubscribe) {
doToast({ message: `${__('Successfully subscribed to')} ${claimName}!` });
}
2018-03-26 23:32:43 +02:00
}}
/>
2018-11-21 22:20:55 +01:00
);
};