2021-03-03 19:50:16 +01:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import Button from 'component/button';
|
2021-06-16 04:27:58 +02:00
|
|
|
import { BLOCK_LEVEL } from 'constants/comment';
|
|
|
|
import { parseURI } from 'lbry-redux';
|
2021-03-03 19:50:16 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
2021-06-16 04:27:58 +02:00
|
|
|
blockLevel?: string,
|
|
|
|
creatorUri?: string,
|
2021-03-03 19:50:16 +01:00
|
|
|
isBlocked: boolean,
|
|
|
|
isBlockingOrUnBlocking: boolean,
|
2021-06-16 04:27:58 +02:00
|
|
|
isToggling: boolean,
|
2021-06-11 22:49:18 +02:00
|
|
|
doCommentModUnBlock: (string, boolean) => void,
|
|
|
|
doCommentModBlock: (string, boolean) => void,
|
2021-06-16 04:27:58 +02:00
|
|
|
doCommentModUnBlockAsAdmin: (string, string) => void,
|
|
|
|
doCommentModBlockAsAdmin: (string, string) => void,
|
|
|
|
doCommentModUnBlockAsModerator: (string, string, string) => void,
|
|
|
|
doCommentModBlockAsModerator: (string, string, string) => void,
|
2021-03-03 19:50:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function ChannelBlockButton(props: Props) {
|
2021-06-16 04:27:58 +02:00
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
blockLevel,
|
|
|
|
creatorUri,
|
|
|
|
doCommentModUnBlock,
|
|
|
|
doCommentModBlock,
|
|
|
|
doCommentModUnBlockAsAdmin,
|
|
|
|
doCommentModBlockAsAdmin,
|
|
|
|
doCommentModUnBlockAsModerator,
|
|
|
|
doCommentModBlockAsModerator,
|
|
|
|
isBlocked,
|
|
|
|
isBlockingOrUnBlocking,
|
|
|
|
isToggling,
|
|
|
|
} = props;
|
2021-03-03 19:50:16 +01:00
|
|
|
|
|
|
|
function handleClick() {
|
2021-06-16 04:27:58 +02:00
|
|
|
switch (blockLevel) {
|
|
|
|
default:
|
|
|
|
case BLOCK_LEVEL.SELF:
|
|
|
|
if (isBlocked) {
|
|
|
|
doCommentModUnBlock(uri, false);
|
|
|
|
} else {
|
|
|
|
doCommentModBlock(uri, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_LEVEL.MODERATOR:
|
|
|
|
if (creatorUri) {
|
|
|
|
const { channelClaimId } = parseURI(creatorUri);
|
|
|
|
if (isBlocked) {
|
|
|
|
doCommentModUnBlockAsModerator(uri, channelClaimId, '');
|
|
|
|
} else {
|
|
|
|
doCommentModBlockAsModerator(uri, channelClaimId, '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_LEVEL.ADMIN:
|
|
|
|
if (isBlocked) {
|
|
|
|
doCommentModUnBlockAsAdmin(uri, '');
|
|
|
|
} else {
|
|
|
|
doCommentModBlockAsAdmin(uri, '');
|
|
|
|
}
|
|
|
|
break;
|
2021-03-03 19:50:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-16 04:27:58 +02:00
|
|
|
function getButtonText(blockLevel) {
|
|
|
|
switch (blockLevel) {
|
|
|
|
default:
|
|
|
|
case BLOCK_LEVEL.SELF:
|
|
|
|
case BLOCK_LEVEL.ADMIN:
|
|
|
|
return isBlocked
|
2021-03-03 19:50:16 +01:00
|
|
|
? isBlockingOrUnBlocking
|
|
|
|
? __('Unblocking...')
|
|
|
|
: __('Unblock')
|
|
|
|
: isBlockingOrUnBlocking
|
2021-06-16 04:27:58 +02:00
|
|
|
? __('Blocking...')
|
|
|
|
: __('Block');
|
|
|
|
|
|
|
|
case BLOCK_LEVEL.MODERATOR:
|
|
|
|
if (isToggling) {
|
|
|
|
return isBlocked ? __('Unblocking...') : __('Blocking...');
|
|
|
|
} else {
|
|
|
|
return isBlocked ? __('Unblock') : __('Block');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-01 21:40:13 +02:00
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
button={isBlocked ? 'alt' : 'secondary'}
|
|
|
|
label={getButtonText(blockLevel)}
|
|
|
|
onClick={handleClick}
|
|
|
|
disableOnFatal
|
|
|
|
/>
|
|
|
|
);
|
2021-03-03 19:50:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ChannelBlockButton;
|