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

55 lines
1.4 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
import { MODALS } from 'lbry-redux';
2018-03-26 23:32:43 +02:00
import * as icons from 'constants/icons';
import Button from 'component/button';
import type { Subscription } from 'types/subscription';
2018-03-26 23:32:43 +02:00
type SubscribtionArgs = {
channelName: string,
uri: string,
};
type Props = {
channelName: ?string,
uri: ?string,
subscriptions: Array<Subscription>,
doChannelSubscribe: ({ channelName: string, uri: string }) => void,
doChannelUnsubscribe: SubscribtionArgs => void,
2018-04-19 18:51:18 +02:00
doNotify: ({ id: string }) => void,
2018-03-26 23:32:43 +02:00
};
export default (props: Props) => {
const {
channelName,
uri,
subscriptions,
doChannelSubscribe,
doChannelUnsubscribe,
2018-04-19 18:51:18 +02:00
doNotify,
2018-03-26 23:32:43 +02:00
} = props;
2017-12-08 21:38:20 +01:00
const isSubscribed =
subscriptions.map(subscription => subscription.channelName).indexOf(channelName) !== -1;
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
return channelName && uri ? (
2018-03-26 23:32:43 +02:00
<Button
icon={isSubscribed ? undefined : icons.HEART}
2018-05-21 22:30:00 +02:00
button={isSubscribed ? 'alt' : 'secondary'}
2018-03-26 23:32:43 +02:00
label={subscriptionLabel}
onClick={() => {
if (!subscriptions.length) {
doNotify({ id: MODALS.FIRST_SUBSCRIPTION });
2018-03-26 23:32:43 +02:00
}
subscriptionHandler({
channelName,
uri,
});
}}
/>
2017-12-09 18:19:28 +01:00
) : null;
};