shift enter to comment
This commit is contained in:
parent
746f0db1f1
commit
3913c03163
2 changed files with 36 additions and 1 deletions
|
@ -1315,7 +1315,14 @@
|
||||||
"Change to tile layout": "Change to tile layout",
|
"Change to tile layout": "Change to tile layout",
|
||||||
"Create a channel": "Create a channel",
|
"Create a channel": "Create a channel",
|
||||||
"Credit Details": "Credit Details",
|
"Credit Details": "Credit Details",
|
||||||
|
<<<<<<< HEAD
|
||||||
"LBRY Credits": "LBRY Credits",
|
"LBRY Credits": "LBRY Credits",
|
||||||
"Sync my YouTube channel": "Sync my YouTube channel",
|
"Sync my YouTube channel": "Sync my YouTube channel",
|
||||||
|
=======
|
||||||
|
"Sign In": "Sign In",
|
||||||
|
"Change to tile layout": "Change to tile layout",
|
||||||
|
"%total_comments% comments": "%total_comments% comments",
|
||||||
|
"Show more": "Show more",
|
||||||
|
>>>>>>> shift enter to comment
|
||||||
"--end--": "--end--"
|
"--end--": "--end--"
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import ChannelSelection from 'component/selectChannel';
|
||||||
import usePersistedState from 'effects/use-persisted-state';
|
import usePersistedState from 'effects/use-persisted-state';
|
||||||
import { FF_MAX_CHARS_IN_COMMENT } from 'constants/form-field';
|
import { FF_MAX_CHARS_IN_COMMENT } from 'constants/form-field';
|
||||||
import { useHistory } from 'react-router';
|
import { useHistory } from 'react-router';
|
||||||
|
import type { ElementRef } from 'react';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
uri: string,
|
uri: string,
|
||||||
|
@ -24,6 +25,7 @@ type Props = {
|
||||||
|
|
||||||
export function CommentCreate(props: Props) {
|
export function CommentCreate(props: Props) {
|
||||||
const { createComment, claim, channels, topLevelId, onDoneReplying, onCancelReplying, isNested } = props;
|
const { createComment, claim, channels, topLevelId, onDoneReplying, onCancelReplying, isNested } = props;
|
||||||
|
const buttonref: ElementRef<any> = React.useRef();
|
||||||
const { push } = useHistory();
|
const { push } = useHistory();
|
||||||
const { claim_id: claimId } = claim;
|
const { claim_id: claimId } = claim;
|
||||||
const isReply = !!topLevelId;
|
const isReply = !!topLevelId;
|
||||||
|
@ -32,6 +34,7 @@ export function CommentCreate(props: Props) {
|
||||||
const [charCount, setCharCount] = useState(commentValue.length);
|
const [charCount, setCharCount] = useState(commentValue.length);
|
||||||
const [advancedEditor, setAdvancedEditor] = usePersistedState('comment-editor-mode', false);
|
const [advancedEditor, setAdvancedEditor] = usePersistedState('comment-editor-mode', false);
|
||||||
const hasChannels = channels && channels.length;
|
const hasChannels = channels && channels.length;
|
||||||
|
const disabled = channel === CHANNEL_NEW || !commentValue.length;
|
||||||
|
|
||||||
const topChannel =
|
const topChannel =
|
||||||
channels &&
|
channels &&
|
||||||
|
@ -59,6 +62,28 @@ export function CommentCreate(props: Props) {
|
||||||
setCommentValue(commentValue);
|
setCommentValue(commentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleCommentAck() {
|
||||||
|
setCommentAck(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function altEnterListener(e: SyntheticKeyboardEvent<*>) {
|
||||||
|
if (e.shiftKey && e.keyCode === 13) {
|
||||||
|
e.preventDefault();
|
||||||
|
buttonref.current.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTextareaFocus() {
|
||||||
|
window.addEventListener('keydown', altEnterListener);
|
||||||
|
if (!commentAck) {
|
||||||
|
openModal(MODALS.COMMENT_ACKNOWEDGEMENT, { onCommentAcknowledge: handleCommentAck });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTextareaBlur() {
|
||||||
|
window.removeEventListener('keydown', altEnterListener);
|
||||||
|
}
|
||||||
|
|
||||||
function handleSubmit() {
|
function handleSubmit() {
|
||||||
if (channel !== CHANNEL_NEW && commentValue.length) {
|
if (channel !== CHANNEL_NEW && commentValue.length) {
|
||||||
createComment(commentValue, claimId, channel, topLevelId).then(res => {
|
createComment(commentValue, claimId, channel, topLevelId).then(res => {
|
||||||
|
@ -108,6 +133,8 @@ export function CommentCreate(props: Props) {
|
||||||
!SIMPLE_SITE && (isReply ? undefined : advancedEditor ? __('Simple Editor') : __('Advanced Editor'))
|
!SIMPLE_SITE && (isReply ? undefined : advancedEditor ? __('Simple Editor') : __('Advanced Editor'))
|
||||||
}
|
}
|
||||||
quickActionHandler={!SIMPLE_SITE && toggleEditorMode}
|
quickActionHandler={!SIMPLE_SITE && toggleEditorMode}
|
||||||
|
onFocus={onTextareaFocus}
|
||||||
|
onBlur={onTextareaBlur}
|
||||||
placeholder={__('Say something about this...')}
|
placeholder={__('Say something about this...')}
|
||||||
value={commentValue}
|
value={commentValue}
|
||||||
charCount={charCount}
|
charCount={charCount}
|
||||||
|
@ -117,8 +144,9 @@ export function CommentCreate(props: Props) {
|
||||||
/>
|
/>
|
||||||
<div className="section__actions section__actions--no-margin">
|
<div className="section__actions section__actions--no-margin">
|
||||||
<Button
|
<Button
|
||||||
|
ref={buttonref}
|
||||||
button="primary"
|
button="primary"
|
||||||
disabled={channel === CHANNEL_NEW || !commentValue.length}
|
disabled={disabled}
|
||||||
type="submit"
|
type="submit"
|
||||||
label={isReply ? __('Reply') : __('Post')}
|
label={isReply ? __('Reply') : __('Post')}
|
||||||
requiresAuth={IS_WEB}
|
requiresAuth={IS_WEB}
|
||||||
|
|
Loading…
Add table
Reference in a new issue