2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2018-05-05 21:04:47 +02:00
|
|
|
import { MODALS } from 'lbry-redux';
|
2018-03-26 23:32:43 +02:00
|
|
|
import * as icons from 'constants/icons';
|
|
|
|
import Button from 'component/button';
|
2018-05-07 06:50:55 +02:00
|
|
|
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 =
|
2017-12-21 22:08:54 +01:00
|
|
|
subscriptions.map(subscription => subscription.channelName).indexOf(channelName) !== -1;
|
2017-12-08 21:38:20 +01:00
|
|
|
|
2017-12-21 22:08:54 +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
|
2018-05-23 05:48:22 +02:00
|
|
|
iconColor="red"
|
2018-03-26 23:32:43 +02:00
|
|
|
icon={isSubscribed ? undefined : icons.HEART}
|
2018-05-23 05:48:22 +02:00
|
|
|
button="alt"
|
2018-03-26 23:32:43 +02:00
|
|
|
label={subscriptionLabel}
|
2018-08-27 20:45:50 +02:00
|
|
|
onClick={e => {
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
if (!subscriptions.length) {
|
2018-05-05 21:04:47 +02:00
|
|
|
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;
|
2017-12-21 22:08:54 +01:00
|
|
|
};
|