2019-05-17 20:21:07 +02:00
|
|
|
// @flow
|
2021-12-02 17:49:13 +01:00
|
|
|
|
2021-10-27 20:20:47 +02:00
|
|
|
import 'scss/component/_comment-create.scss';
|
2021-12-02 17:49:13 +01:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
import { buildValidSticker } from 'util/comments';
|
2021-09-30 23:30:32 +02:00
|
|
|
import { FF_MAX_CHARS_IN_COMMENT, FF_MAX_CHARS_IN_LIVESTREAM_COMMENT } from 'constants/form-field';
|
|
|
|
import { FormField, Form } from 'component/common/form';
|
|
|
|
import { getChannelIdFromClaim } from 'util/claim';
|
2021-11-05 20:31:51 +01:00
|
|
|
import { Lbryio } from 'lbryinc';
|
2021-08-18 00:34:16 +02:00
|
|
|
import { SIMPLE_SITE } from 'config';
|
2021-09-30 23:30:32 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2021-04-23 21:59:48 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
2021-08-31 09:05:42 +02:00
|
|
|
import * as KEYCODES from 'constants/keycodes';
|
2021-09-30 23:30:32 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import ChannelThumbnail from 'component/channelThumbnail';
|
2020-03-20 20:09:45 +01:00
|
|
|
import classnames from 'classnames';
|
2021-09-30 23:30:32 +02:00
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
2021-10-27 20:20:47 +02:00
|
|
|
import EmoteSelector from './emote-selector';
|
2021-09-30 23:30:32 +02:00
|
|
|
import Empty from 'component/common/empty';
|
2021-10-28 22:25:34 +02:00
|
|
|
import FilePrice from 'component/filePrice';
|
2021-09-30 23:30:32 +02:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2021-08-04 10:54:20 +02:00
|
|
|
import Icon from 'component/common/icon';
|
2021-10-28 22:25:34 +02:00
|
|
|
import OptimizedImage from 'component/optimizedImage';
|
2021-09-30 23:30:32 +02:00
|
|
|
import React from 'react';
|
2021-02-09 17:05:56 +01:00
|
|
|
import SelectChannel from 'component/selectChannel';
|
2021-10-28 22:25:34 +02:00
|
|
|
import StickerSelector from './sticker-selector';
|
2021-09-30 23:30:32 +02:00
|
|
|
import type { ElementRef } from 'react';
|
|
|
|
import UriIndicator from 'component/uriIndicator';
|
2019-09-27 20:56:15 +02:00
|
|
|
import usePersistedState from 'effects/use-persisted-state';
|
2021-04-23 21:59:48 +02:00
|
|
|
import WalletTipAmountSelector from 'component/walletTipAmountSelector';
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2021-08-18 00:34:16 +02:00
|
|
|
import { getStripeEnvironment } from 'util/stripe';
|
2021-10-28 22:25:34 +02:00
|
|
|
const stripeEnvironment = getStripeEnvironment();
|
2021-07-06 22:28:29 +02:00
|
|
|
|
|
|
|
const TAB_FIAT = 'TabFiat';
|
|
|
|
const TAB_LBC = 'TabLBC';
|
2021-03-10 19:34:21 +01:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
type TipParams = { tipAmount: number, tipChannelName: string, channelClaimId: string };
|
|
|
|
type UserParams = { activeChannelName: ?string, activeChannelId: ?string };
|
|
|
|
|
2019-05-17 20:21:07 +02:00
|
|
|
type Props = {
|
2020-10-20 05:20:38 +02:00
|
|
|
activeChannel: string,
|
2021-02-09 17:05:56 +01:00
|
|
|
activeChannelClaim: ?ChannelClaim,
|
2021-07-28 16:36:24 +02:00
|
|
|
bottom: boolean,
|
2021-11-08 07:27:14 +01:00
|
|
|
hasChannels: boolean,
|
2021-10-28 22:25:34 +02:00
|
|
|
claim: StreamClaim,
|
2021-03-10 19:34:21 +01:00
|
|
|
claimIsMine: boolean,
|
2021-10-28 22:25:34 +02:00
|
|
|
embed?: boolean,
|
|
|
|
isFetchingChannels: boolean,
|
|
|
|
isNested: boolean,
|
|
|
|
isReply: boolean,
|
2021-12-02 17:49:13 +01:00
|
|
|
isLivestream?: boolean,
|
2021-10-28 22:25:34 +02:00
|
|
|
parentId: string,
|
2021-07-29 16:53:36 +02:00
|
|
|
settingsByChannelId: { [channelId: string]: PerChannelSettings },
|
2021-09-30 23:30:32 +02:00
|
|
|
shouldFetchComment: boolean,
|
2021-10-28 22:25:34 +02:00
|
|
|
supportDisabled: boolean,
|
|
|
|
uri: string,
|
|
|
|
createComment: (string, string, string, ?string, ?string, ?string, boolean) => Promise<any>,
|
|
|
|
doFetchCreatorSettings: (channelId: string) => Promise<any>,
|
2021-09-30 23:30:32 +02:00
|
|
|
doToast: ({ message: string }) => void,
|
2021-10-28 22:25:34 +02:00
|
|
|
fetchComment: (commentId: string) => Promise<any>,
|
2021-09-30 23:30:32 +02:00
|
|
|
onCancelReplying?: () => void,
|
2021-10-28 22:25:34 +02:00
|
|
|
onDoneReplying?: () => void,
|
|
|
|
sendCashTip: (TipParams, UserParams, string, ?string, (any) => void) => string,
|
2021-09-30 23:30:32 +02:00
|
|
|
sendTip: ({}, (any) => void, (any) => void) => void,
|
2021-08-27 12:29:58 +02:00
|
|
|
setQuickReply: (any) => void,
|
2021-10-28 22:25:34 +02:00
|
|
|
toast: (string) => void,
|
2019-05-17 20:21:07 +02:00
|
|
|
};
|
|
|
|
|
2019-06-12 16:53:27 +02:00
|
|
|
export function CommentCreate(props: Props) {
|
2020-10-06 21:35:13 +02:00
|
|
|
const {
|
2021-10-28 22:25:34 +02:00
|
|
|
activeChannelClaim,
|
|
|
|
bottom,
|
2021-11-08 07:27:14 +01:00
|
|
|
hasChannels,
|
2021-10-28 22:25:34 +02:00
|
|
|
claim,
|
|
|
|
claimIsMine,
|
|
|
|
embed,
|
2020-10-06 21:35:13 +02:00
|
|
|
isFetchingChannels,
|
2021-10-28 22:25:34 +02:00
|
|
|
isNested,
|
2020-10-07 21:14:52 +02:00
|
|
|
isReply,
|
2021-12-02 17:49:13 +01:00
|
|
|
isLivestream,
|
2021-10-28 22:25:34 +02:00
|
|
|
parentId,
|
2021-07-29 16:53:36 +02:00
|
|
|
settingsByChannelId,
|
2021-09-30 23:30:32 +02:00
|
|
|
shouldFetchComment,
|
2021-10-28 22:25:34 +02:00
|
|
|
supportDisabled,
|
2021-09-30 23:30:32 +02:00
|
|
|
createComment,
|
2021-10-28 22:25:34 +02:00
|
|
|
doFetchCreatorSettings,
|
|
|
|
doToast,
|
|
|
|
fetchComment,
|
2021-09-30 23:30:32 +02:00
|
|
|
onCancelReplying,
|
2021-10-28 22:25:34 +02:00
|
|
|
onDoneReplying,
|
|
|
|
sendCashTip,
|
2021-09-30 23:30:32 +02:00
|
|
|
sendTip,
|
2021-08-27 12:29:58 +02:00
|
|
|
setQuickReply,
|
2020-10-06 21:35:13 +02:00
|
|
|
} = props;
|
2021-10-28 22:25:34 +02:00
|
|
|
|
2021-09-30 23:30:32 +02:00
|
|
|
const formFieldRef: ElementRef<any> = React.useRef();
|
2021-07-29 15:07:23 +02:00
|
|
|
const buttonRef: ElementRef<any> = React.useRef();
|
2021-10-28 22:25:34 +02:00
|
|
|
|
2021-04-03 06:28:54 +02:00
|
|
|
const {
|
|
|
|
push,
|
|
|
|
location: { pathname },
|
|
|
|
} = useHistory();
|
2021-09-30 23:30:32 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
const [isSubmitting, setSubmitting] = React.useState(false);
|
2021-06-10 14:19:17 +02:00
|
|
|
const [commentFailure, setCommentFailure] = React.useState(false);
|
|
|
|
const [successTip, setSuccessTip] = React.useState({ txid: undefined, tipAmount: undefined });
|
2021-04-23 21:59:48 +02:00
|
|
|
const [isSupportComment, setIsSupportComment] = React.useState();
|
2021-10-28 22:25:34 +02:00
|
|
|
const [isReviewingSupportComment, setReviewingSupportComment] = React.useState();
|
|
|
|
const [isReviewingStickerComment, setReviewingStickerComment] = React.useState();
|
|
|
|
const [selectedSticker, setSelectedSticker] = React.useState();
|
2021-04-23 21:59:48 +02:00
|
|
|
const [tipAmount, setTipAmount] = React.useState(1);
|
2021-10-28 22:25:34 +02:00
|
|
|
const [convertedAmount, setConvertedAmount] = React.useState();
|
2020-03-20 20:09:45 +01:00
|
|
|
const [commentValue, setCommentValue] = React.useState('');
|
2020-05-21 10:53:21 +02:00
|
|
|
const [advancedEditor, setAdvancedEditor] = usePersistedState('comment-editor-mode', false);
|
2021-10-28 22:25:34 +02:00
|
|
|
const [stickerSelector, setStickerSelector] = React.useState();
|
2021-11-05 16:45:19 +01:00
|
|
|
const [activeTab, setActiveTab] = React.useState();
|
2021-07-06 22:28:29 +02:00
|
|
|
const [tipError, setTipError] = React.useState();
|
2021-08-27 14:03:29 +02:00
|
|
|
const [deletedComment, setDeletedComment] = React.useState(false);
|
2021-10-27 20:20:47 +02:00
|
|
|
const [showEmotes, setShowEmotes] = React.useState(false);
|
2021-10-28 22:25:34 +02:00
|
|
|
const [disableReviewButton, setDisableReviewButton] = React.useState();
|
2021-11-05 20:31:51 +01:00
|
|
|
const [exchangeRate, setExchangeRate] = React.useState();
|
|
|
|
const [canReceiveFiatTip, setCanReceiveFiatTip] = React.useState(undefined);
|
2021-09-30 23:30:32 +02:00
|
|
|
|
|
|
|
const claimId = claim && claim.claim_id;
|
|
|
|
const charCount = commentValue ? commentValue.length : 0;
|
2021-12-02 17:49:13 +01:00
|
|
|
const disabled = deletedComment || isSubmitting || isFetchingChannels || !commentValue.length;
|
2021-07-29 16:53:36 +02:00
|
|
|
const channelId = getChannelIdFromClaim(claim);
|
|
|
|
const channelSettings = channelId ? settingsByChannelId[channelId] : undefined;
|
2021-08-04 10:54:20 +02:00
|
|
|
const minSuper = (channelSettings && channelSettings.min_tip_amount_super_chat) || 0;
|
|
|
|
const minTip = (channelSettings && channelSettings.min_tip_amount_comment) || 0;
|
|
|
|
const minAmount = minTip || minSuper || 0;
|
|
|
|
const minAmountMet = minAmount === 0 || tipAmount >= minAmount;
|
2021-11-05 20:31:51 +01:00
|
|
|
const stickerPrice = selectedSticker && selectedSticker.price;
|
2021-08-04 10:54:20 +02:00
|
|
|
|
|
|
|
const minAmountRef = React.useRef(minAmount);
|
|
|
|
minAmountRef.current = minAmount;
|
|
|
|
|
|
|
|
// **************************************************************************
|
|
|
|
// Functions
|
|
|
|
// **************************************************************************
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
function handleSelectSticker(sticker: any) {
|
|
|
|
// $FlowFixMe
|
|
|
|
setSelectedSticker(sticker);
|
|
|
|
setReviewingStickerComment(true);
|
|
|
|
setTipAmount(sticker.price || 0);
|
|
|
|
setStickerSelector(false);
|
|
|
|
|
|
|
|
if (sticker.price && sticker.price > 0) {
|
2021-11-05 20:31:51 +01:00
|
|
|
setActiveTab(canReceiveFiatTip ? TAB_FIAT : TAB_LBC);
|
2021-10-28 22:25:34 +02:00
|
|
|
setIsSupportComment(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 02:04:47 +02:00
|
|
|
function altEnterListener(e: SyntheticKeyboardEvent<*>) {
|
2021-12-06 18:28:36 +01:00
|
|
|
// $FlowFixMe
|
|
|
|
const isTyping = e.target.attributes['term'];
|
|
|
|
|
|
|
|
if (((isLivestream && !isTyping) || e.ctrlKey || e.metaKey) && e.keyCode === KEYCODES.ENTER) {
|
2020-09-30 02:04:47 +02:00
|
|
|
e.preventDefault();
|
2021-07-29 15:07:23 +02:00
|
|
|
buttonRef.current.click();
|
2020-09-30 02:04:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
function handleSupportComment() {
|
2021-10-28 22:25:34 +02:00
|
|
|
if (!activeChannelClaim) return;
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2021-08-04 10:54:20 +02:00
|
|
|
if (!channelId) {
|
|
|
|
doToast({
|
|
|
|
message: __('Unable to verify channel settings. Try refreshing the page.'),
|
|
|
|
isError: true,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-11 22:58:55 +02:00
|
|
|
// if comment post didn't work, but tip was already made, try again to create comment
|
2021-06-10 14:19:17 +02:00
|
|
|
if (commentFailure && tipAmount === successTip.tipAmount) {
|
|
|
|
handleCreateComment(successTip.txid);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
setSuccessTip({ txid: undefined, tipAmount: undefined });
|
|
|
|
}
|
|
|
|
|
2021-08-04 10:54:20 +02:00
|
|
|
// !! Beware of stale closure when editing the then-block, including doSubmitTip().
|
|
|
|
doFetchCreatorSettings(channelId).then(() => {
|
|
|
|
const lockedMinAmount = minAmount; // value during closure.
|
|
|
|
const currentMinAmount = minAmountRef.current; // value from latest doFetchCreatorSettings().
|
|
|
|
|
|
|
|
if (lockedMinAmount !== currentMinAmount) {
|
|
|
|
doToast({
|
|
|
|
message: __('The creator just updated the minimum setting. Please revise or double-check your tip amount.'),
|
|
|
|
isError: true,
|
|
|
|
});
|
2021-10-28 22:25:34 +02:00
|
|
|
setReviewingSupportComment(false);
|
2021-08-04 10:54:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
doSubmitTip();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function doSubmitTip() {
|
2021-12-06 15:51:07 +01:00
|
|
|
if (!activeChannelClaim || isSubmitting) return;
|
|
|
|
|
|
|
|
setSubmitting(true);
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
const params = { amount: tipAmount, claim_id: claimId, channel_id: activeChannelClaim.claim_id };
|
2021-07-06 22:28:29 +02:00
|
|
|
const activeChannelName = activeChannelClaim && activeChannelClaim.name;
|
|
|
|
const activeChannelId = activeChannelClaim && activeChannelClaim.claim_id;
|
|
|
|
|
2021-08-11 22:58:55 +02:00
|
|
|
// setup variables for tip API
|
2021-10-28 22:25:34 +02:00
|
|
|
const channelClaimId = claim.signing_channel ? claim.signing_channel.claim_id : claim.claim_id;
|
|
|
|
const tipChannelName = claim.signing_channel ? claim.signing_channel.name : claim.name;
|
2021-08-11 22:58:55 +02:00
|
|
|
|
2021-07-06 22:28:29 +02:00
|
|
|
if (activeTab === TAB_LBC) {
|
|
|
|
// call sendTip and then run the callback from the response
|
|
|
|
// second parameter is callback
|
|
|
|
sendTip(
|
|
|
|
params,
|
|
|
|
(response) => {
|
|
|
|
const { txid } = response;
|
|
|
|
// todo: why the setTimeout?
|
|
|
|
setTimeout(() => {
|
|
|
|
handleCreateComment(txid);
|
|
|
|
}, 1500);
|
2021-08-11 22:58:55 +02:00
|
|
|
|
|
|
|
doToast({
|
2021-11-03 20:47:19 +01:00
|
|
|
message: __("You sent %tipAmount% Credits as a tip to %tipChannelName%, I'm sure they appreciate it!", {
|
|
|
|
tipAmount: tipAmount, // force show decimal places
|
|
|
|
tipChannelName,
|
|
|
|
}),
|
2021-08-11 22:58:55 +02:00
|
|
|
});
|
|
|
|
|
2021-07-06 22:28:29 +02:00
|
|
|
setSuccessTip({ txid, tipAmount });
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
// reset the frontend so people can send a new comment
|
2021-10-28 22:25:34 +02:00
|
|
|
setSubmitting(false);
|
2021-07-06 22:28:29 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
2021-10-28 22:25:34 +02:00
|
|
|
const tipParams: TipParams = { tipAmount: Math.round(tipAmount * 100) / 100, tipChannelName, channelClaimId };
|
|
|
|
const userParams: UserParams = { activeChannelName, activeChannelId };
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
sendCashTip(tipParams, userParams, claim.claim_id, stripeEnvironment, (customerTipResponse) => {
|
|
|
|
const { payment_intent_id } = customerTipResponse;
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
handleCreateComment(null, payment_intent_id, stripeEnvironment);
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
setCommentValue('');
|
|
|
|
setReviewingSupportComment(false);
|
|
|
|
setIsSupportComment(false);
|
|
|
|
setCommentFailure(false);
|
|
|
|
setSubmitting(false);
|
|
|
|
});
|
2021-07-06 22:28:29 +02:00
|
|
|
}
|
2021-04-23 21:59:48 +02:00
|
|
|
}
|
|
|
|
|
2021-07-06 22:28:29 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {string} [txid] Optional transaction id generated by
|
|
|
|
* @param {string} [payment_intent_id] Optional payment_intent_id from Stripe payment
|
|
|
|
* @param {string} [environment] Optional environment for Stripe (test|live)
|
|
|
|
*/
|
|
|
|
function handleCreateComment(txid, payment_intent_id, environment) {
|
2021-12-06 15:51:07 +01:00
|
|
|
if (isSubmitting) return;
|
|
|
|
|
2021-10-27 20:20:47 +02:00
|
|
|
setShowEmotes(false);
|
2021-10-28 22:25:34 +02:00
|
|
|
setSubmitting(true);
|
2021-12-06 15:51:07 +01:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
const stickerValue = selectedSticker && buildValidSticker(selectedSticker.name);
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
createComment(stickerValue || commentValue, claimId, parentId, txid, payment_intent_id, environment, !!stickerValue)
|
2021-04-23 21:59:48 +02:00
|
|
|
.then((res) => {
|
2021-10-28 22:25:34 +02:00
|
|
|
setSubmitting(false);
|
2021-08-27 12:29:58 +02:00
|
|
|
if (setQuickReply) setQuickReply(res);
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2020-09-30 02:11:48 +02:00
|
|
|
if (res && res.signature) {
|
2021-11-05 20:31:51 +01:00
|
|
|
if (!stickerValue) setCommentValue('');
|
2021-10-28 22:25:34 +02:00
|
|
|
setReviewingSupportComment(false);
|
2021-04-23 21:59:48 +02:00
|
|
|
setIsSupportComment(false);
|
2021-06-10 14:19:17 +02:00
|
|
|
setCommentFailure(false);
|
2020-10-07 21:14:52 +02:00
|
|
|
|
2020-09-30 02:11:48 +02:00
|
|
|
if (onDoneReplying) {
|
|
|
|
onDoneReplying();
|
|
|
|
}
|
|
|
|
}
|
2021-04-23 21:59:48 +02:00
|
|
|
})
|
2021-07-29 15:07:23 +02:00
|
|
|
.catch(() => {
|
2021-10-28 22:25:34 +02:00
|
|
|
setSubmitting(false);
|
2021-06-10 14:19:17 +02:00
|
|
|
setCommentFailure(true);
|
2021-08-04 10:54:20 +02:00
|
|
|
|
|
|
|
if (channelId) {
|
|
|
|
// It could be that the creator added a minimum tip setting.
|
|
|
|
// Manually update for now until a websocket msg is available.
|
|
|
|
doFetchCreatorSettings(channelId);
|
|
|
|
}
|
2020-09-30 02:11:48 +02:00
|
|
|
});
|
2019-05-17 20:21:07 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 10:54:20 +02:00
|
|
|
// **************************************************************************
|
|
|
|
// Effects
|
|
|
|
// **************************************************************************
|
|
|
|
|
|
|
|
// Fetch channel constraints if not already.
|
2021-07-29 16:53:36 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (!channelSettings && channelId) {
|
|
|
|
doFetchCreatorSettings(channelId);
|
|
|
|
}
|
2021-10-14 10:09:28 +02:00
|
|
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
2021-09-30 23:30:32 +02:00
|
|
|
|
|
|
|
// Notifications: Fetch top-level comments to identify if it has been deleted and can reply to it
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (shouldFetchComment && fetchComment) {
|
|
|
|
fetchComment(parentId).then((result) => {
|
|
|
|
setDeletedComment(String(result).includes('Error'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [fetchComment, shouldFetchComment, parentId]);
|
|
|
|
|
2021-11-05 20:31:51 +01:00
|
|
|
// Stickers: Get LBC-USD exchange rate if hasn't yet and selected a paid sticker
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (stickerPrice && !exchangeRate) Lbryio.getExchangeRates().then(({ LBC_USD }) => setExchangeRate(LBC_USD));
|
|
|
|
}, [exchangeRate, stickerPrice]);
|
|
|
|
|
|
|
|
// Stickers: Check if creator has a tip account saved (on selector so that if a paid sticker is selected,
|
|
|
|
// it defaults to LBC tip instead of USD)
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (!stripeEnvironment || !stickerSelector || canReceiveFiatTip !== undefined) return;
|
|
|
|
|
|
|
|
const channelClaimId = claim.signing_channel ? claim.signing_channel.claim_id : claim.claim_id;
|
|
|
|
const tipChannelName = claim.signing_channel ? claim.signing_channel.name : claim.name;
|
|
|
|
|
|
|
|
Lbryio.call(
|
|
|
|
'account',
|
|
|
|
'check',
|
|
|
|
{
|
|
|
|
channel_claim_id: channelClaimId,
|
|
|
|
channel_name: tipChannelName,
|
|
|
|
environment: stripeEnvironment,
|
|
|
|
},
|
|
|
|
'post'
|
|
|
|
)
|
|
|
|
.then((accountCheckResponse) => {
|
|
|
|
if (accountCheckResponse === true && canReceiveFiatTip !== true) {
|
|
|
|
setCanReceiveFiatTip(true);
|
|
|
|
} else {
|
|
|
|
setCanReceiveFiatTip(false);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
}, [canReceiveFiatTip, claim.claim_id, claim.name, claim.signing_channel, stickerSelector]);
|
|
|
|
|
2021-08-04 10:54:20 +02:00
|
|
|
// **************************************************************************
|
|
|
|
// Render
|
|
|
|
// **************************************************************************
|
|
|
|
|
2021-11-05 20:31:51 +01:00
|
|
|
const getActionButton = (title: string, label?: string, icon: string, handleClick: () => void) => (
|
|
|
|
<Button title={title} label={label} button="alt" icon={icon} onClick={handleClick} />
|
2021-10-28 22:25:34 +02:00
|
|
|
);
|
|
|
|
|
2021-07-29 16:53:36 +02:00
|
|
|
if (channelSettings && !channelSettings.comments_enabled) {
|
2021-06-03 07:57:50 +02:00
|
|
|
return <Empty padded text={__('This channel has disabled comments on their page.')} />;
|
|
|
|
}
|
|
|
|
|
2021-08-17 04:48:03 +02:00
|
|
|
if (!isFetchingChannels && !hasChannels) {
|
2020-08-25 21:54:06 +02:00
|
|
|
return (
|
2021-04-03 06:28:54 +02:00
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
onClick={() => {
|
2021-07-28 16:36:24 +02:00
|
|
|
if (embed) {
|
|
|
|
window.open(`https://odysee.com/$/${PAGES.AUTH}?redirect=/$/${PAGES.LIVESTREAM}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-03 06:28:54 +02:00
|
|
|
const pathPlusRedirect = `/$/${PAGES.CHANNEL_NEW}?redirect=${pathname}`;
|
2021-12-02 17:49:13 +01:00
|
|
|
if (isLivestream) {
|
2021-04-03 06:28:54 +02:00
|
|
|
window.open(pathPlusRedirect);
|
|
|
|
} else {
|
|
|
|
push(pathPlusRedirect);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2021-08-18 00:34:16 +02:00
|
|
|
<FormField type="textarea" name={'comment_signup_prompt'} placeholder={__('Say something about this...')} />
|
2021-04-23 21:59:48 +02:00
|
|
|
<div className="section__actions--no-margin">
|
2021-10-28 22:25:34 +02:00
|
|
|
<Button disabled button="primary" label={__('Post --[button to submit something]--')} requiresAuth />
|
2020-10-06 21:35:13 +02:00
|
|
|
</div>
|
2020-08-25 21:54:06 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
return (
|
|
|
|
<Form
|
2021-11-05 20:31:51 +01:00
|
|
|
onSubmit={() => {}}
|
2021-10-28 22:25:34 +02:00
|
|
|
className={classnames('commentCreate', {
|
|
|
|
'commentCreate--reply': isReply,
|
|
|
|
'commentCreate--nestedReply': isNested,
|
|
|
|
'commentCreate--bottom': bottom,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{/* Input Box/Preview Box */}
|
|
|
|
{stickerSelector ? (
|
|
|
|
<StickerSelector onSelect={(sticker) => handleSelectSticker(sticker)} claimIsMine={claimIsMine} />
|
|
|
|
) : isReviewingStickerComment && activeChannelClaim && selectedSticker ? (
|
|
|
|
<div className="commentCreate__stickerPreview">
|
|
|
|
<div className="commentCreate__stickerPreviewInfo">
|
|
|
|
<ChannelThumbnail xsmall uri={activeChannelClaim.canonical_url} />
|
|
|
|
<UriIndicator uri={activeChannelClaim.canonical_url} link />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="commentCreate__stickerPreviewImage">
|
2021-11-05 20:31:51 +01:00
|
|
|
<OptimizedImage src={selectedSticker && selectedSticker.url} waitLoad loading="lazy" />
|
2021-10-28 22:25:34 +02:00
|
|
|
</div>
|
|
|
|
|
2021-11-05 20:31:51 +01:00
|
|
|
{selectedSticker.price && exchangeRate && (
|
|
|
|
<FilePrice
|
|
|
|
customPrices={{ priceFiat: selectedSticker.price, priceLBC: selectedSticker.price / exchangeRate }}
|
|
|
|
isFiat
|
|
|
|
/>
|
|
|
|
)}
|
2021-10-28 22:25:34 +02:00
|
|
|
</div>
|
|
|
|
) : isReviewingSupportComment && activeChannelClaim ? (
|
|
|
|
<div className="commentCreate__supportCommentPreview">
|
2021-07-17 18:19:44 +02:00
|
|
|
<CreditAmount
|
|
|
|
amount={tipAmount}
|
2021-10-28 22:25:34 +02:00
|
|
|
className="commentCreate__supportCommentPreviewAmount"
|
|
|
|
isFiat={activeTab === TAB_FIAT}
|
2021-07-17 18:19:44 +02:00
|
|
|
size={activeTab === TAB_LBC ? 18 : 2}
|
|
|
|
/>
|
2021-04-23 21:59:48 +02:00
|
|
|
|
|
|
|
<ChannelThumbnail xsmall uri={activeChannelClaim.canonical_url} />
|
2021-10-28 22:25:34 +02:00
|
|
|
<div className="commentCreate__supportCommentBody">
|
|
|
|
<UriIndicator uri={activeChannelClaim.canonical_url} link />
|
2021-04-23 21:59:48 +02:00
|
|
|
<div>{commentValue}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-28 22:25:34 +02:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{showEmotes && (
|
|
|
|
<EmoteSelector
|
|
|
|
commentValue={commentValue}
|
|
|
|
setCommentValue={setCommentValue}
|
|
|
|
closeSelector={() => setShowEmotes(false)}
|
|
|
|
/>
|
|
|
|
)}
|
2021-12-06 18:28:36 +01:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
<FormField
|
2021-12-02 17:49:13 +01:00
|
|
|
autoFocus={isReply}
|
|
|
|
charCount={charCount}
|
2021-12-06 18:28:36 +01:00
|
|
|
className={isReply ? 'create__reply' : 'create__comment'}
|
2021-10-28 22:25:34 +02:00
|
|
|
disabled={isFetchingChannels}
|
2021-12-02 17:49:13 +01:00
|
|
|
isLivestream={isLivestream}
|
2021-10-28 22:25:34 +02:00
|
|
|
label={
|
2021-12-02 17:49:13 +01:00
|
|
|
<div className="commentCreate__labelWrapper">
|
|
|
|
<span className="commentCreate__label">
|
|
|
|
{(isReply ? __('Replying as') : isLivestream ? __('Chat as') : __('Comment as')) + ' '}
|
|
|
|
</span>
|
2021-10-28 22:25:34 +02:00
|
|
|
<SelectChannel tiny />
|
2021-12-02 17:49:13 +01:00
|
|
|
</div>
|
2021-10-28 22:25:34 +02:00
|
|
|
}
|
2021-12-06 18:28:36 +01:00
|
|
|
name={isReply ? 'create__reply' : 'create__comment'}
|
2021-12-02 17:49:13 +01:00
|
|
|
onBlur={() => window.removeEventListener('keydown', altEnterListener)}
|
|
|
|
onChange={(e) => setCommentValue(SIMPLE_SITE || !advancedEditor || isReply ? e.target.value : e)}
|
|
|
|
onFocus={() => window.addEventListener('keydown', altEnterListener)}
|
|
|
|
openEmoteMenu={() => setShowEmotes(!showEmotes)}
|
|
|
|
placeholder={__('Say something about this...')}
|
|
|
|
quickActionHandler={!SIMPLE_SITE ? () => setAdvancedEditor(!advancedEditor) : undefined}
|
2021-10-28 22:25:34 +02:00
|
|
|
quickActionLabel={
|
|
|
|
!SIMPLE_SITE && (isReply ? undefined : advancedEditor ? __('Simple Editor') : __('Advanced Editor'))
|
|
|
|
}
|
2021-12-02 17:49:13 +01:00
|
|
|
ref={formFieldRef}
|
|
|
|
textAreaMaxLength={isLivestream ? FF_MAX_CHARS_IN_LIVESTREAM_COMMENT : FF_MAX_CHARS_IN_COMMENT}
|
|
|
|
type={!SIMPLE_SITE && advancedEditor && !isReply ? 'markdown' : 'textarea'}
|
2021-10-28 22:25:34 +02:00
|
|
|
value={commentValue}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
2021-11-05 20:31:51 +01:00
|
|
|
{(isSupportComment || (isReviewingStickerComment && stickerPrice)) && (
|
2021-10-28 22:25:34 +02:00
|
|
|
<WalletTipAmountSelector
|
|
|
|
activeTab={activeTab}
|
|
|
|
amount={tipAmount}
|
|
|
|
claim={claim}
|
|
|
|
convertedAmount={convertedAmount}
|
2021-11-05 20:31:51 +01:00
|
|
|
customTipAmount={stickerPrice}
|
|
|
|
exchangeRate={exchangeRate}
|
2021-10-28 22:25:34 +02:00
|
|
|
fiatConversion={selectedSticker && !!selectedSticker.price}
|
|
|
|
onChange={(amount) => setTipAmount(amount)}
|
|
|
|
setConvertedAmount={setConvertedAmount}
|
|
|
|
setDisableSubmitButton={setDisableReviewButton}
|
|
|
|
setTipError={setTipError}
|
|
|
|
tipError={tipError}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{/* Bottom Action Buttons */}
|
|
|
|
<div className="section__actions section__actions--no-margin">
|
|
|
|
{/* Submit Button */}
|
|
|
|
{isReviewingSupportComment ? (
|
2021-04-23 21:59:48 +02:00
|
|
|
<Button
|
|
|
|
autoFocus
|
|
|
|
button="primary"
|
2021-08-04 10:54:20 +02:00
|
|
|
disabled={disabled || !minAmountMet}
|
2021-07-15 16:43:28 +02:00
|
|
|
label={
|
|
|
|
isSubmitting
|
|
|
|
? __('Sending...')
|
|
|
|
: commentFailure && tipAmount === successTip.tipAmount
|
|
|
|
? __('Re-submit')
|
|
|
|
: __('Send')
|
|
|
|
}
|
2021-04-23 21:59:48 +02:00
|
|
|
onClick={handleSupportComment}
|
|
|
|
/>
|
2021-10-28 22:25:34 +02:00
|
|
|
) : isReviewingStickerComment && selectedSticker ? (
|
2021-08-11 04:03:47 +02:00
|
|
|
<Button
|
2021-10-28 22:25:34 +02:00
|
|
|
button="primary"
|
|
|
|
label={__('Send')}
|
2021-11-05 20:31:51 +01:00
|
|
|
disabled={isSupportComment && (tipError || disableReviewButton)}
|
2021-10-28 22:25:34 +02:00
|
|
|
onClick={() => {
|
|
|
|
if (isSupportComment) {
|
|
|
|
handleSupportComment();
|
|
|
|
} else {
|
|
|
|
handleCreateComment();
|
|
|
|
}
|
|
|
|
setSelectedSticker(null);
|
|
|
|
setReviewingStickerComment(false);
|
|
|
|
setStickerSelector(false);
|
|
|
|
setIsSupportComment(false);
|
|
|
|
}}
|
2021-08-11 04:03:47 +02:00
|
|
|
/>
|
2021-10-28 22:25:34 +02:00
|
|
|
) : isSupportComment ? (
|
|
|
|
<Button
|
|
|
|
disabled={disabled || tipError || disableReviewButton || !minAmountMet}
|
|
|
|
type="button"
|
|
|
|
button="primary"
|
|
|
|
icon={activeTab === TAB_LBC ? ICONS.LBC : ICONS.FINANCE}
|
|
|
|
label={__('Review')}
|
|
|
|
onClick={() => setReviewingSupportComment(true)}
|
|
|
|
requiresAuth
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
(!minTip || claimIsMine) && (
|
2021-03-10 19:34:21 +01:00
|
|
|
<Button
|
2021-10-28 22:25:34 +02:00
|
|
|
ref={buttonRef}
|
2021-04-23 21:59:48 +02:00
|
|
|
button="primary"
|
2021-10-28 22:25:34 +02:00
|
|
|
disabled={disabled || stickerSelector}
|
|
|
|
type="submit"
|
|
|
|
label={
|
|
|
|
isReply
|
|
|
|
? isSubmitting
|
|
|
|
? __('Replying...')
|
|
|
|
: __('Reply')
|
|
|
|
: isSubmitting
|
|
|
|
? __('Commenting...')
|
|
|
|
: __('Comment --[button to submit something]--')
|
|
|
|
}
|
|
|
|
requiresAuth
|
|
|
|
onClick={() => activeChannelClaim && commentValue.length && handleCreateComment()}
|
2021-03-10 19:34:21 +01:00
|
|
|
/>
|
2021-10-28 22:25:34 +02:00
|
|
|
)
|
|
|
|
)}
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
{/** Stickers/Support Buttons **/}
|
|
|
|
{!supportDisabled && !stickerSelector && (
|
2021-04-23 21:59:48 +02:00
|
|
|
<>
|
2021-11-05 20:31:51 +01:00
|
|
|
{getActionButton(
|
|
|
|
__('Stickers'),
|
|
|
|
isReviewingStickerComment ? __('Different Sticker') : undefined,
|
|
|
|
ICONS.STICKER,
|
|
|
|
() => {
|
|
|
|
if (isReviewingStickerComment) setReviewingStickerComment(false);
|
2021-10-28 22:25:34 +02:00
|
|
|
setIsSupportComment(false);
|
|
|
|
setStickerSelector(true);
|
2021-11-05 20:31:51 +01:00
|
|
|
}
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!claimIsMine && (
|
|
|
|
<>
|
|
|
|
{(!isSupportComment || activeTab !== TAB_LBC) &&
|
2021-11-26 01:23:17 +01:00
|
|
|
getActionButton(
|
|
|
|
__('Credits'),
|
|
|
|
isSupportComment ? __('Switch to Credits') : undefined,
|
|
|
|
ICONS.LBC,
|
|
|
|
() => {
|
|
|
|
setIsSupportComment(true);
|
|
|
|
setActiveTab(TAB_LBC);
|
|
|
|
}
|
|
|
|
)}
|
2021-11-05 20:31:51 +01:00
|
|
|
|
|
|
|
{stripeEnvironment &&
|
|
|
|
(!isSupportComment || activeTab !== TAB_FIAT) &&
|
|
|
|
getActionButton(
|
|
|
|
__('Cash'),
|
|
|
|
isSupportComment ? __('Switch to Cash') : undefined,
|
|
|
|
ICONS.FINANCE,
|
|
|
|
() => {
|
|
|
|
setIsSupportComment(true);
|
|
|
|
setActiveTab(TAB_FIAT);
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
</>
|
2021-04-23 21:59:48 +02:00
|
|
|
)}
|
|
|
|
</>
|
2020-03-20 20:09:45 +01:00
|
|
|
)}
|
2021-10-28 22:25:34 +02:00
|
|
|
|
|
|
|
{/* Cancel Button */}
|
|
|
|
{(isSupportComment ||
|
|
|
|
isReviewingSupportComment ||
|
|
|
|
stickerSelector ||
|
|
|
|
isReviewingStickerComment ||
|
|
|
|
(isReply && !minTip)) && (
|
|
|
|
<Button
|
|
|
|
disabled={isSupportComment && isSubmitting}
|
|
|
|
button="link"
|
|
|
|
label={__('Cancel')}
|
|
|
|
onClick={() => {
|
|
|
|
if (isSupportComment || isReviewingSupportComment) {
|
|
|
|
if (!isReviewingSupportComment) setIsSupportComment(false);
|
|
|
|
setReviewingSupportComment(false);
|
2021-11-05 20:31:51 +01:00
|
|
|
if (stickerPrice) {
|
2021-10-28 22:25:34 +02:00
|
|
|
setReviewingStickerComment(false);
|
|
|
|
setStickerSelector(false);
|
|
|
|
setSelectedSticker(null);
|
|
|
|
}
|
|
|
|
} else if (stickerSelector || isReviewingStickerComment) {
|
|
|
|
setReviewingStickerComment(false);
|
|
|
|
setStickerSelector(false);
|
2021-12-08 15:17:22 +01:00
|
|
|
setSelectedSticker(null);
|
2021-10-28 22:25:34 +02:00
|
|
|
} else if (isReply && !minTip && onCancelReplying) {
|
|
|
|
onCancelReplying();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{/* Help Text */}
|
2021-08-27 14:03:29 +02:00
|
|
|
{deletedComment && <div className="error__text">{__('This comment has been deleted.')}</div>}
|
2021-10-28 22:25:34 +02:00
|
|
|
{!!minAmount && (
|
|
|
|
<div className="help--notice commentCreate__minAmountNotice">
|
|
|
|
<I18nMessage tokens={{ lbc: <CreditAmount noFormat amount={minAmount} /> }}>
|
|
|
|
{minTip ? 'Comment min: %lbc%' : minSuper ? 'HyperChat min: %lbc%' : ''}
|
|
|
|
</I18nMessage>
|
|
|
|
<Icon
|
|
|
|
customTooltipText={
|
|
|
|
minTip
|
|
|
|
? __('This channel requires a minimum tip for each comment.')
|
|
|
|
: minSuper
|
|
|
|
? __('This channel requires a minimum amount for HyperChats to be visible.')
|
|
|
|
: ''
|
|
|
|
}
|
|
|
|
className="icon--help"
|
|
|
|
icon={ICONS.HELP}
|
|
|
|
tooltip
|
|
|
|
size={16}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-01-23 21:41:14 +01:00
|
|
|
</div>
|
2019-11-14 21:02:15 +01:00
|
|
|
</Form>
|
2019-06-12 16:53:27 +02:00
|
|
|
);
|
2019-05-17 20:21:07 +02:00
|
|
|
}
|