2019-05-17 20:21:07 +02:00
|
|
|
// @flow
|
2022-01-24 17:07:09 +01:00
|
|
|
|
|
|
|
import 'scss/component/_comment-create.scss';
|
|
|
|
|
|
|
|
import { buildValidSticker } from 'util/comments';
|
2021-10-19 06:49:51 +02:00
|
|
|
import { FF_MAX_CHARS_IN_COMMENT } from 'constants/form-field';
|
2021-09-30 23:30:32 +02:00
|
|
|
import { FormField, Form } from 'component/common/form';
|
|
|
|
import { getChannelIdFromClaim } from 'util/claim';
|
|
|
|
import { Lbryio } from 'lbryinc';
|
|
|
|
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';
|
2022-01-24 17:07:09 +01:00
|
|
|
import EmoteSelector from './emote-selector';
|
2021-09-30 23:30:32 +02:00
|
|
|
import Empty from 'component/common/empty';
|
2022-01-24 17:07:09 +01: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';
|
2022-01-24 17:07:09 +01: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';
|
2022-01-24 17:07:09 +01: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';
|
2022-08-09 19:33:36 +02:00
|
|
|
import { COMMENT_SERVER_API, COMMENT_SERVER_NAME } from 'config';
|
2021-08-18 00:34:16 +02:00
|
|
|
import { getStripeEnvironment } from 'util/stripe';
|
2022-08-09 19:33:36 +02:00
|
|
|
import Comments from 'comments';
|
2022-01-24 17:07:09 +01:00
|
|
|
const stripeEnvironment = getStripeEnvironment();
|
2021-07-06 22:28:29 +02:00
|
|
|
|
|
|
|
const TAB_FIAT = 'TabFiat';
|
|
|
|
const TAB_LBC = 'TabLBC';
|
2022-01-24 17:07:09 +01:00
|
|
|
|
|
|
|
// for sendCashTip REMOVE
|
|
|
|
// type TipParams = { tipAmount: number, tipChannelName: string, channelClaimId: string };
|
|
|
|
// type UserParams = { activeChannelName: ?string, activeChannelId: ?string };
|
2021-03-10 19:34:21 +01:00
|
|
|
|
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,
|
2022-01-24 17:07:09 +01:00
|
|
|
hasChannels: boolean,
|
|
|
|
claim: StreamClaim,
|
2021-03-10 19:34:21 +01:00
|
|
|
claimIsMine: boolean,
|
2022-01-24 17:07:09 +01:00
|
|
|
isFetchingChannels: boolean,
|
|
|
|
isNested: boolean,
|
|
|
|
isReply: boolean,
|
|
|
|
parentId: string,
|
2021-07-29 16:53:36 +02:00
|
|
|
settingsByChannelId: { [channelId: string]: PerChannelSettings },
|
2021-09-30 23:30:32 +02:00
|
|
|
shouldFetchComment: boolean,
|
2022-01-24 17:07:09 +01: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,
|
2022-01-24 17:07:09 +01:00
|
|
|
fetchComment: (commentId: string) => Promise<any>,
|
2021-09-30 23:30:32 +02:00
|
|
|
onCancelReplying?: () => void,
|
2022-01-24 17:07:09 +01:00
|
|
|
onDoneReplying?: () => void,
|
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,
|
2022-01-24 17:07:09 +01:00
|
|
|
toast: (string) => void,
|
2022-08-09 19:33:36 +02:00
|
|
|
customCommentServers: Array<CommentServerDetails>,
|
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 {
|
2022-01-24 17:07:09 +01:00
|
|
|
activeChannelClaim,
|
|
|
|
bottom,
|
2022-01-04 16:01:01 +01:00
|
|
|
hasChannels,
|
2022-01-24 17:07:09 +01:00
|
|
|
claim,
|
|
|
|
claimIsMine,
|
2020-10-06 21:35:13 +02:00
|
|
|
isFetchingChannels,
|
2022-01-24 17:07:09 +01:00
|
|
|
isNested,
|
2020-10-07 21:14:52 +02:00
|
|
|
isReply,
|
|
|
|
parentId,
|
2021-07-29 16:53:36 +02:00
|
|
|
settingsByChannelId,
|
2021-09-30 23:30:32 +02:00
|
|
|
shouldFetchComment,
|
2022-01-24 17:07:09 +01:00
|
|
|
supportDisabled,
|
2021-09-30 23:30:32 +02:00
|
|
|
createComment,
|
2022-01-24 17:07:09 +01:00
|
|
|
doFetchCreatorSettings,
|
|
|
|
doToast,
|
|
|
|
fetchComment,
|
2021-09-30 23:30:32 +02:00
|
|
|
onCancelReplying,
|
2022-01-24 17:07:09 +01:00
|
|
|
onDoneReplying,
|
2021-09-30 23:30:32 +02:00
|
|
|
sendTip,
|
2021-08-27 12:29:58 +02:00
|
|
|
setQuickReply,
|
2022-08-09 19:33:36 +02:00
|
|
|
customCommentServers,
|
2020-10-06 21:35:13 +02:00
|
|
|
} = props;
|
2022-01-24 17:07:09 +01:00
|
|
|
|
2022-08-09 19:33:36 +02:00
|
|
|
const defaultServer = { name: COMMENT_SERVER_NAME, url: COMMENT_SERVER_API };
|
|
|
|
const allServers = [defaultServer, ...customCommentServers];
|
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();
|
2022-01-24 17:07:09 +01:00
|
|
|
|
2021-04-03 06:28:54 +02:00
|
|
|
const {
|
|
|
|
push,
|
|
|
|
location: { pathname },
|
|
|
|
} = useHistory();
|
2021-09-30 23:30:32 +02:00
|
|
|
|
2022-08-09 19:33:36 +02:00
|
|
|
const [commentServer, setCommentServer] = React.useState(defaultServer.url);
|
2022-01-24 17:07:09 +01: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();
|
2022-01-24 17:07:09 +01: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);
|
2022-01-24 17:07:09 +01: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);
|
2022-01-24 17:07:09 +01:00
|
|
|
const [stickerSelector, setStickerSelector] = React.useState();
|
|
|
|
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);
|
2022-01-24 17:07:09 +01:00
|
|
|
const [showEmotes, setShowEmotes] = React.useState(false);
|
|
|
|
const [disableReviewButton, setDisableReviewButton] = React.useState();
|
|
|
|
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;
|
2022-01-24 17:07:09 +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;
|
2022-01-24 17:07:09 +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
|
|
|
|
2022-01-24 17:07:09 +01:00
|
|
|
function handleSelectSticker(sticker: any) {
|
|
|
|
// $FlowFixMe
|
|
|
|
setSelectedSticker(sticker);
|
|
|
|
setReviewingStickerComment(true);
|
|
|
|
setTipAmount(sticker.price || 0);
|
|
|
|
setStickerSelector(false);
|
|
|
|
|
|
|
|
if (sticker.price && sticker.price > 0) {
|
|
|
|
setActiveTab(TAB_LBC);
|
|
|
|
setIsSupportComment(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 16:53:27 +02:00
|
|
|
function handleCommentChange(event) {
|
2020-06-03 17:37:57 +02:00
|
|
|
let commentValue;
|
|
|
|
if (isReply) {
|
2021-12-23 17:31:20 +01:00
|
|
|
commentValue = advancedEditor ? event : event.target.value;
|
2020-06-03 17:37:57 +02:00
|
|
|
} else {
|
2021-10-19 01:37:58 +02:00
|
|
|
commentValue = advancedEditor ? event : event.target.value;
|
2020-06-03 17:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setCommentValue(commentValue);
|
2019-05-17 20:21:07 +02:00
|
|
|
}
|
|
|
|
|
2020-09-30 02:04:47 +02:00
|
|
|
function altEnterListener(e: SyntheticKeyboardEvent<*>) {
|
2021-10-19 06:49:51 +02:00
|
|
|
if ((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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTextareaFocus() {
|
|
|
|
window.addEventListener('keydown', altEnterListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTextareaBlur() {
|
|
|
|
window.removeEventListener('keydown', altEnterListener);
|
|
|
|
}
|
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
function handleSupportComment() {
|
2022-01-24 17:07:09 +01: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,
|
|
|
|
});
|
2022-01-24 17:07:09 +01:00
|
|
|
setReviewingSupportComment(false);
|
2021-08-04 10:54:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
doSubmitTip();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function doSubmitTip() {
|
2022-01-24 17:07:09 +01:00
|
|
|
if (!activeChannelClaim || isSubmitting) return;
|
2021-08-04 10:54:20 +02:00
|
|
|
|
2022-01-24 17:07:09 +01:00
|
|
|
setSubmitting(true);
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2022-01-24 17:07:09 +01:00
|
|
|
const params = { amount: tipAmount, claim_id: claimId, channel_id: activeChannelClaim.claim_id };
|
|
|
|
// FIAT ONLY - REMOVE
|
|
|
|
// const activeChannelName = activeChannelClaim && activeChannelClaim.name;
|
|
|
|
// const activeChannelId = activeChannelClaim && activeChannelClaim.claim_id;
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2021-08-11 22:58:55 +02:00
|
|
|
// setup variables for tip API
|
2022-01-24 17:07:09 +01: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-04-23 21:59:48 +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({
|
2022-01-24 17:07:09 +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
|
2022-01-24 17:07:09 +01:00
|
|
|
setSubmitting(false);
|
2021-07-06 22:28:29 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
2022-01-24 17:07:09 +01:00
|
|
|
// No cash tips - REMOVE
|
|
|
|
// const tipParams: TipParams = { tipAmount: Math.round(tipAmount * 100) / 100, tipChannelName, channelClaimId };
|
|
|
|
// const userParams: UserParams = { activeChannelName, activeChannelId };
|
|
|
|
// sendCashTip(tipParams, userParams, claim.claim_id, stripeEnvironment, (customerTipResponse) => {
|
|
|
|
// const { payment_intent_id } = customerTipResponse;
|
|
|
|
//
|
|
|
|
// handleCreateComment(null, payment_intent_id, stripeEnvironment);
|
|
|
|
//
|
|
|
|
// 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) {
|
2022-01-24 17:07:09 +01:00
|
|
|
if (isSubmitting) return;
|
|
|
|
|
|
|
|
setShowEmotes(false);
|
|
|
|
setSubmitting(true);
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2022-01-24 17:07:09 +01:00
|
|
|
const stickerValue = selectedSticker && buildValidSticker(selectedSticker.name);
|
|
|
|
|
|
|
|
createComment(stickerValue || commentValue, claimId, parentId, txid, payment_intent_id, environment, !!stickerValue)
|
2021-04-23 21:59:48 +02:00
|
|
|
.then((res) => {
|
2022-01-24 17:07:09 +01: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) {
|
2022-01-24 17:07:09 +01:00
|
|
|
if (!stickerValue) setCommentValue('');
|
|
|
|
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(() => {
|
2022-01-24 17:07:09 +01: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]);
|
|
|
|
|
2022-01-24 17:07:09 +01:00
|
|
|
// Stickers: Get LBC-USD exchange rate if hasn't yet and selected a paid sticker
|
2021-09-30 23:30:32 +02:00
|
|
|
React.useEffect(() => {
|
2022-01-24 17:07:09 +01:00
|
|
|
if (stickerPrice && !exchangeRate) Lbryio.getExchangeRates().then(({ LBC_USD }) => setExchangeRate(LBC_USD));
|
|
|
|
}, [exchangeRate, stickerPrice]);
|
2021-09-30 23:30:32 +02:00
|
|
|
|
2022-01-24 17:07:09 +01:00
|
|
|
// 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]);
|
|
|
|
|
|
|
|
// LIVESTREAM ONLY - REMOVE
|
|
|
|
// Handle keyboard shortcut comment creation
|
|
|
|
// React.useEffect(() => {
|
|
|
|
// function altEnterListener(e: SyntheticKeyboardEvent<*>) {
|
|
|
|
// const inputRef = formFieldRef && formFieldRef.current && formFieldRef.current.input;
|
|
|
|
//
|
|
|
|
// if (inputRef && inputRef.current === document.activeElement) {
|
|
|
|
// // $FlowFixMe
|
|
|
|
// const isTyping = e.target.attributes['term'];
|
|
|
|
//
|
|
|
|
// if (((isLivestream && !isTyping) || e.ctrlKey || e.metaKey) && e.keyCode === KEYCODES.ENTER) {
|
|
|
|
// e.preventDefault();
|
|
|
|
// buttonRef.current.click();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// window.addEventListener('keydown', altEnterListener);
|
|
|
|
//
|
|
|
|
// // removes the listener so it doesn't cause problems elsewhere in the app
|
|
|
|
// return () => {
|
|
|
|
// window.removeEventListener('keydown', altEnterListener);
|
|
|
|
// };
|
|
|
|
// }, [isLivestream]);
|
2021-07-29 16:53:36 +02:00
|
|
|
|
2021-08-04 10:54:20 +02:00
|
|
|
// **************************************************************************
|
|
|
|
// Render
|
|
|
|
// **************************************************************************
|
|
|
|
|
2022-01-24 17:07:09 +01:00
|
|
|
const getActionButton = (title: string, label?: string, icon: string, handleClick: () => void) => (
|
|
|
|
<Button title={title} label={label} button="alt" icon={icon} onClick={handleClick} />
|
|
|
|
);
|
|
|
|
|
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={() => {
|
|
|
|
const pathPlusRedirect = `/$/${PAGES.CHANNEL_NEW}?redirect=${pathname}`;
|
2021-10-19 06:49:51 +02:00
|
|
|
push(pathPlusRedirect);
|
2021-04-03 06:28:54 +02:00
|
|
|
}}
|
|
|
|
>
|
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">
|
2022-01-07 20:02:33 +01:00
|
|
|
<Button disabled button="primary" label={__('Post --[button to submit something]--')} />
|
2020-10-06 21:35:13 +02:00
|
|
|
</div>
|
2020-08-25 21:54:06 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-24 17:07:09 +01:00
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
onSubmit={() => {}}
|
|
|
|
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">
|
|
|
|
<OptimizedImage src={selectedSticker && selectedSticker.url} waitLoad loading="lazy" />
|
|
|
|
</div>
|
|
|
|
{/* figure out lbc sticker prices */}
|
|
|
|
{selectedSticker.price && exchangeRate && (
|
|
|
|
<FilePrice
|
|
|
|
customPrices={{ priceFiat: selectedSticker.price, priceLBC: selectedSticker.price / exchangeRate }}
|
|
|
|
isFiat
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
) : isReviewingSupportComment && activeChannelClaim ? (
|
|
|
|
<div className="commentCreate__supportCommentPreview">
|
2021-07-17 18:19:44 +02:00
|
|
|
<CreditAmount
|
|
|
|
amount={tipAmount}
|
2022-01-24 17:07:09 +01: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} />
|
2022-01-24 17:07:09 +01:00
|
|
|
<div className="commentCreate__supportCommentBody">
|
|
|
|
<UriIndicator uri={activeChannelClaim.canonical_url} link />
|
2021-04-23 21:59:48 +02:00
|
|
|
<div>{commentValue}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-01-24 17:07:09 +01:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{showEmotes && (
|
|
|
|
<EmoteSelector
|
|
|
|
commentValue={commentValue}
|
|
|
|
setCommentValue={setCommentValue}
|
|
|
|
closeSelector={() => setShowEmotes(false)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<FormField
|
|
|
|
autoFocus={isReply}
|
|
|
|
charCount={charCount}
|
|
|
|
className={isReply ? 'content_reply' : 'content_comment'}
|
|
|
|
disabled={isFetchingChannels}
|
|
|
|
label={
|
|
|
|
<div className="commentCreate__labelWrapper">
|
|
|
|
<span className="commentCreate__label">{(isReply ? __('Replying as') : __('Comment as')) + ' '}</span>
|
|
|
|
<SelectChannel tiny />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
name={isReply ? 'content_reply' : 'content_description'}
|
|
|
|
quickActionLabel={isReply ? undefined : advancedEditor ? __('Simple Editor') : __('Advanced Editor')}
|
|
|
|
ref={formFieldRef}
|
|
|
|
onChange={handleCommentChange}
|
|
|
|
openEmoteMenu={() => setShowEmotes(!showEmotes)}
|
|
|
|
quickActionHandler={() => setAdvancedEditor(!advancedEditor)}
|
|
|
|
onFocus={onTextareaFocus}
|
|
|
|
onBlur={onTextareaBlur}
|
|
|
|
placeholder={__('Say something about this...')}
|
|
|
|
value={commentValue}
|
|
|
|
type={advancedEditor ? 'markdown' : 'textarea'}
|
|
|
|
textAreaMaxLength={FF_MAX_CHARS_IN_COMMENT}
|
|
|
|
/>
|
2022-08-09 19:33:36 +02:00
|
|
|
|
2022-07-22 01:01:40 +02:00
|
|
|
<FormField
|
2022-08-09 19:33:36 +02:00
|
|
|
label="server"
|
|
|
|
type="select-tiny"
|
|
|
|
onChange={function (x) {
|
|
|
|
const selectedServer = x.target.value;
|
|
|
|
setCommentServer(selectedServer);
|
|
|
|
if (selectedServer === defaultServer.url) {
|
|
|
|
Comments.setServerUrl(undefined);
|
|
|
|
} else {
|
|
|
|
Comments.setServerUrl(selectedServer);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
value={commentServer}
|
|
|
|
>
|
|
|
|
{allServers.map(function (server) {
|
|
|
|
return (
|
|
|
|
<option key={server.url} value={server.url}>
|
|
|
|
{server.name}
|
|
|
|
</option>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</FormField>
|
2022-01-24 17:07:09 +01:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{(isSupportComment || (isReviewingStickerComment && stickerPrice)) && (
|
|
|
|
<WalletTipAmountSelector
|
|
|
|
activeTab={activeTab}
|
|
|
|
amount={tipAmount}
|
|
|
|
claim={claim}
|
|
|
|
convertedAmount={convertedAmount}
|
|
|
|
customTipAmount={stickerPrice}
|
|
|
|
exchangeRate={exchangeRate}
|
|
|
|
fiatConversion={selectedSticker && !!selectedSticker.price} // REMOVE / figure out
|
|
|
|
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}
|
|
|
|
/>
|
2022-01-24 17:07:09 +01:00
|
|
|
) : isReviewingStickerComment && selectedSticker ? (
|
2021-08-11 04:03:47 +02:00
|
|
|
<Button
|
2022-01-24 17:07:09 +01:00
|
|
|
button="primary"
|
|
|
|
label={__('Send')}
|
|
|
|
disabled={isSupportComment && (tipError || disableReviewButton)}
|
|
|
|
onClick={() => {
|
|
|
|
if (isSupportComment) {
|
|
|
|
handleSupportComment();
|
|
|
|
} else {
|
|
|
|
handleCreateComment();
|
|
|
|
}
|
|
|
|
setSelectedSticker(null);
|
|
|
|
setReviewingStickerComment(false);
|
|
|
|
setStickerSelector(false);
|
|
|
|
setIsSupportComment(false);
|
|
|
|
}}
|
2021-08-11 04:03:47 +02:00
|
|
|
/>
|
2022-01-24 17:07:09 +01:00
|
|
|
) : isSupportComment ? (
|
|
|
|
<Button
|
|
|
|
disabled={disabled || tipError || disableReviewButton || !minAmountMet}
|
|
|
|
type="button"
|
|
|
|
button="primary"
|
|
|
|
icon={activeTab === TAB_LBC ? ICONS.LBC : ICONS.FINANCE} // only LBC
|
|
|
|
label={__('Review')}
|
|
|
|
onClick={() => setReviewingSupportComment(true)}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
(!minTip || claimIsMine) && (
|
2021-03-10 19:34:21 +01:00
|
|
|
<Button
|
2022-01-24 17:07:09 +01:00
|
|
|
ref={buttonRef}
|
2021-04-23 21:59:48 +02:00
|
|
|
button="primary"
|
2022-01-24 17:07:09 +01:00
|
|
|
disabled={disabled || stickerSelector}
|
|
|
|
type="submit"
|
|
|
|
label={
|
|
|
|
isReply
|
|
|
|
? isSubmitting
|
|
|
|
? __('Replying...')
|
|
|
|
: __('Reply')
|
|
|
|
: isSubmitting
|
|
|
|
? __('Commenting...')
|
|
|
|
: __('Comment --[button to submit something]--')
|
|
|
|
}
|
|
|
|
onClick={() => activeChannelClaim && commentValue.length && handleCreateComment()}
|
2021-03-10 19:34:21 +01:00
|
|
|
/>
|
2022-01-24 17:07:09 +01:00
|
|
|
)
|
|
|
|
)}
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2022-01-24 17:07:09 +01:00
|
|
|
{/** Stickers/Support Buttons **/}
|
|
|
|
{!supportDisabled && !stickerSelector && (
|
2021-04-23 21:59:48 +02:00
|
|
|
<>
|
2022-01-24 17:07:09 +01:00
|
|
|
{getActionButton(
|
|
|
|
__('Stickers'),
|
|
|
|
isReviewingStickerComment ? __('Different Sticker') : undefined,
|
|
|
|
ICONS.STICKER,
|
|
|
|
() => {
|
|
|
|
if (isReviewingStickerComment) setReviewingStickerComment(false);
|
|
|
|
setIsSupportComment(false);
|
|
|
|
setStickerSelector(true);
|
|
|
|
}
|
2021-08-04 10:54:20 +02:00
|
|
|
)}
|
2022-01-24 17:07:09 +01:00
|
|
|
{/* below buttons are unnecessary - REMOVE */}
|
|
|
|
{!claimIsMine && (
|
2021-08-27 12:29:58 +02:00
|
|
|
<>
|
2022-01-24 17:07:09 +01:00
|
|
|
{(!isSupportComment || activeTab !== TAB_LBC) &&
|
|
|
|
getActionButton(
|
|
|
|
__('Credits'),
|
|
|
|
isSupportComment ? __('Switch to Credits') : undefined,
|
|
|
|
ICONS.LBC,
|
|
|
|
() => {
|
|
|
|
setIsSupportComment(true);
|
|
|
|
setActiveTab(TAB_LBC);
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
|
|
|
|
{stripeEnvironment &&
|
|
|
|
(!isSupportComment || activeTab !== TAB_FIAT) &&
|
|
|
|
getActionButton(
|
|
|
|
__('Cash'),
|
|
|
|
isSupportComment ? __('Switch to Cash') : undefined,
|
|
|
|
ICONS.FINANCE,
|
|
|
|
() => {
|
|
|
|
setIsSupportComment(true);
|
|
|
|
setActiveTab(TAB_FIAT);
|
|
|
|
}
|
|
|
|
)}
|
2021-08-27 12:29:58 +02:00
|
|
|
</>
|
2021-04-23 21:59:48 +02:00
|
|
|
)}
|
|
|
|
</>
|
2020-03-20 20:09:45 +01:00
|
|
|
)}
|
2022-01-24 17:07:09 +01: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);
|
|
|
|
if (stickerPrice) {
|
|
|
|
setReviewingStickerComment(false);
|
|
|
|
setStickerSelector(false);
|
|
|
|
setSelectedSticker(null);
|
|
|
|
}
|
|
|
|
} else if (stickerSelector || isReviewingStickerComment) {
|
|
|
|
setReviewingStickerComment(false);
|
|
|
|
setStickerSelector(false);
|
|
|
|
setSelectedSticker(null);
|
|
|
|
} 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>}
|
2022-01-24 17:07:09 +01: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
|
|
|
}
|