mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Needing more control over the opening and closing of text box so moved some things around
- Note this may look a bit more complicated but I need more control over opening/closing - Will look to refactor this and make it simpler soon enough refs https://github.com/TryGhost/Team/issues/1703
This commit is contained in:
parent
30cd5c278e
commit
5466ca2608
1 changed files with 21 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, {useContext, useEffect, useRef} from 'react';
|
import React, {useContext, useEffect, useRef, useState} from 'react';
|
||||||
import {Transition} from '@headlessui/react';
|
import {Transition} from '@headlessui/react';
|
||||||
import AppContext from '../AppContext';
|
import AppContext from '../AppContext';
|
||||||
import Avatar from './Avatar';
|
import Avatar from './Avatar';
|
||||||
|
@ -7,6 +7,7 @@ import {getEditorConfig} from '../utils/editor';
|
||||||
|
|
||||||
const Form = (props) => {
|
const Form = (props) => {
|
||||||
const {member, postId, dispatchAction, onAction, avatarSaturation} = useContext(AppContext);
|
const {member, postId, dispatchAction, onAction, avatarSaturation} = useContext(AppContext);
|
||||||
|
const [isFormOpen, setFormOpen] = useState(props.isReply || props.isEdit ? true : false);
|
||||||
const formEl = useRef(null);
|
const formEl = useRef(null);
|
||||||
|
|
||||||
let config;
|
let config;
|
||||||
|
@ -85,6 +86,12 @@ const Form = (props) => {
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editor.on('blur', (editorObj) => {
|
||||||
|
if (editor?.isEmpty) {
|
||||||
|
setFormOpen(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Focus editor + jump to end
|
// Focus editor + jump to end
|
||||||
if (!props.isEdit) {
|
if (!props.isEdit) {
|
||||||
return;
|
return;
|
||||||
|
@ -101,7 +108,7 @@ const Form = (props) => {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.run();
|
.run();
|
||||||
}, [editor, props.isEdit, props.isReply]);
|
}, [editor, props.isEdit, props.isReply, formEl]);
|
||||||
|
|
||||||
const submitForm = async (event) => {
|
const submitForm = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -151,6 +158,7 @@ const Form = (props) => {
|
||||||
|
|
||||||
// Clear message and blur on success
|
// Clear message and blur on success
|
||||||
editor.chain().clearContent().blur().run();
|
editor.chain().clearContent().blur().run();
|
||||||
|
setFormOpen(false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -162,15 +170,20 @@ const Form = (props) => {
|
||||||
|
|
||||||
const {comment, commentsCount} = props;
|
const {comment, commentsCount} = props;
|
||||||
const memberName = (props.isEdit ? comment.member.name : member.name);
|
const memberName = (props.isEdit ? comment.member.name : member.name);
|
||||||
const isFocused = editor?.isFocused || !editor?.isEmpty;
|
|
||||||
|
|
||||||
const focusEditor = (event) => {
|
const focusEditor = (event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
if (memberName) {
|
if (memberName) {
|
||||||
|
setFormOpen(true);
|
||||||
editor.commands.focus();
|
editor.commands.focus();
|
||||||
} else {
|
} else {
|
||||||
dispatchAction('openPopup', {
|
dispatchAction('openPopup', {
|
||||||
type: 'addNameDialog',
|
type: 'addNameDialog',
|
||||||
callback: () => editor.commands.focus()
|
callback: () => {
|
||||||
|
setFormOpen(true);
|
||||||
|
editor.commands.focus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -192,7 +205,7 @@ const Form = (props) => {
|
||||||
bg-white dark:bg-[rgba(255,255,255,0.08)]
|
bg-white dark:bg-[rgba(255,255,255,0.08)]
|
||||||
rounded-md shadow-formlg dark:shadow-transparent hover:shadow-formxl
|
rounded-md shadow-formlg dark:shadow-transparent hover:shadow-formxl
|
||||||
${!commentsCount && !props.isEdit && !props.isReply && '-mt-0 -mr-0 -ml-0'}
|
${!commentsCount && !props.isEdit && !props.isReply && '-mt-0 -mr-0 -ml-0'}
|
||||||
${isFocused ? 'cursor-default' : 'cursor-pointer'}`
|
${isFormOpen ? 'cursor-default' : 'cursor-pointer'}`
|
||||||
}>
|
}>
|
||||||
<div className="w-full relative">
|
<div className="w-full relative">
|
||||||
<div className="pr-3 font-sans leading-normal dark:text-neutral-300">
|
<div className="pr-3 font-sans leading-normal dark:text-neutral-300">
|
||||||
|
@ -206,7 +219,7 @@ const Form = (props) => {
|
||||||
focus:outline-0
|
focus:outline-0
|
||||||
placeholder:text-neutral-300 dark:placeholder:text-[rgba(255,255,255,0.3)]
|
placeholder:text-neutral-300 dark:placeholder:text-[rgba(255,255,255,0.3)]
|
||||||
resize-none
|
resize-none
|
||||||
${isFocused ? 'cursor-textmin-h-[144px] pt-[44px] pb-[68px]' : 'cursor-pointer overflow-hidden min-h-[48px] hover:border-slate-300'}
|
${isFormOpen ? 'cursor-textmin-h-[144px] pt-[44px] pb-[68px]' : 'cursor-pointer overflow-hidden min-h-[48px] hover:border-slate-300'}
|
||||||
${props.isEdit && 'cursor-text'}
|
${props.isEdit && 'cursor-text'}
|
||||||
${!memberName && 'pointer-events-none'}
|
${!memberName && 'pointer-events-none'}
|
||||||
`}
|
`}
|
||||||
|
@ -239,7 +252,7 @@ const Form = (props) => {
|
||||||
<div className="flex mb-1 justify-start items-center absolute top-0 left-0">
|
<div className="flex mb-1 justify-start items-center absolute top-0 left-0">
|
||||||
<Avatar comment={comment} saturation={avatarSaturation} className="pointer-events-none" />
|
<Avatar comment={comment} saturation={avatarSaturation} className="pointer-events-none" />
|
||||||
<Transition
|
<Transition
|
||||||
show={isFocused}
|
show={isFormOpen}
|
||||||
enter="transition duration-500 delay-100 ease-in-out"
|
enter="transition duration-500 delay-100 ease-in-out"
|
||||||
enterFrom="opacity-0 -translate-x-2"
|
enterFrom="opacity-0 -translate-x-2"
|
||||||
enterTo="opacity-100 translate-x-0"
|
enterTo="opacity-100 translate-x-0"
|
||||||
|
@ -247,7 +260,7 @@ const Form = (props) => {
|
||||||
leaveFrom="opacity-100"
|
leaveFrom="opacity-100"
|
||||||
leaveTo="opacity-0"
|
leaveTo="opacity-0"
|
||||||
>
|
>
|
||||||
<div className="ml-3">
|
<div className="ml-3 pointer-events-none">
|
||||||
<h4 className="text-lg font-sans font-semibold mb-1 tracking-tight dark:text-neutral-300">{memberName ? memberName : 'Anonymous'}</h4>
|
<h4 className="text-lg font-sans font-semibold mb-1 tracking-tight dark:text-neutral-300">{memberName ? memberName : 'Anonymous'}</h4>
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
Loading…
Add table
Reference in a new issue