mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix replymodal autofocus
This commit is contained in:
@@ -17,12 +17,13 @@ import useAnonMode from '../../hooks/use-anon-mode';
|
|||||||
|
|
||||||
interface ReplyModalProps {
|
interface ReplyModalProps {
|
||||||
closeModal: () => void;
|
closeModal: () => void;
|
||||||
|
showReplyModal: boolean;
|
||||||
parentCid: string;
|
parentCid: string;
|
||||||
postCid: string;
|
postCid: string;
|
||||||
scrollY: number;
|
scrollY: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReplyModal = ({ closeModal, parentCid, postCid, scrollY }: ReplyModalProps) => {
|
const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY }: ReplyModalProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { subplebbitAddress } = useParams() as { subplebbitAddress: string };
|
const { subplebbitAddress } = useParams() as { subplebbitAddress: string };
|
||||||
const { setPublishReplyOptions, publishReply } = usePublishReply({ cid: parentCid, subplebbitAddress });
|
const { setPublishReplyOptions, publishReply } = usePublishReply({ cid: parentCid, subplebbitAddress });
|
||||||
@@ -122,14 +123,15 @@ const ReplyModal = ({ closeModal, parentCid, postCid, scrollY }: ReplyModalProps
|
|||||||
)
|
)
|
||||||
: `The subplebbit might be offline and publishing might fail.`;
|
: `The subplebbit might be offline and publishing might fail.`;
|
||||||
|
|
||||||
const setTextRef = (ref: HTMLTextAreaElement | null) => {
|
useEffect(() => {
|
||||||
if (ref) {
|
if (showReplyModal && !isMobile) {
|
||||||
textRef.current = ref;
|
setTimeout(() => {
|
||||||
// if (!isMobile && !urlRef.current?.value) {
|
if (textRef.current) {
|
||||||
// ref.focus();
|
textRef.current.focus();
|
||||||
// }
|
}
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
};
|
}, [showReplyModal, isMobile]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (textRef.current) {
|
if (textRef.current) {
|
||||||
@@ -196,7 +198,7 @@ const ReplyModal = ({ closeModal, parentCid, postCid, scrollY }: ReplyModalProps
|
|||||||
cols={48}
|
cols={48}
|
||||||
rows={4}
|
rows={4}
|
||||||
wrap='soft'
|
wrap='soft'
|
||||||
ref={setTextRef}
|
ref={textRef}
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
defaultValue={contentPrefix + selectedText}
|
defaultValue={contentPrefix + selectedText}
|
||||||
onInput={handleContentInput}
|
onInput={handleContentInput}
|
||||||
@@ -227,12 +229,15 @@ const ReplyModal = ({ closeModal, parentCid, postCid, scrollY }: ReplyModalProps
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
return isMobile ? (
|
return (
|
||||||
modalContent
|
showReplyModal &&
|
||||||
) : (
|
(isMobile ? (
|
||||||
<Draggable handle='.replyModalHandle' nodeRef={nodeRef}>
|
modalContent
|
||||||
{modalContent}
|
) : (
|
||||||
</Draggable>
|
<Draggable handle='.replyModalHandle' nodeRef={nodeRef}>
|
||||||
|
{modalContent}
|
||||||
|
</Draggable>
|
||||||
|
))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ const Board = () => {
|
|||||||
return (
|
return (
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
{location.pathname.endsWith('/settings') && <SettingsModal />}
|
{location.pathname.endsWith('/settings') && <SettingsModal />}
|
||||||
{showReplyModal && activeCid && threadCid && <ReplyModal closeModal={closeModal} parentCid={activeCid} postCid={threadCid} scrollY={scrollY} />}
|
{activeCid && threadCid && <ReplyModal closeModal={closeModal} parentCid={activeCid} postCid={threadCid} scrollY={scrollY} showReplyModal={showReplyModal} />}
|
||||||
{feed.length !== 0 ? (
|
{feed.length !== 0 ? (
|
||||||
<>
|
<>
|
||||||
{rules && rules.length > 0 && <SubplebbitRules subplebbitAddress={subplebbitAddress} createdAt={createdAt} rules={rules} />}
|
{rules && rules.length > 0 && <SubplebbitRules subplebbitAddress={subplebbitAddress} createdAt={createdAt} rules={rules} />}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ const PostPage = () => {
|
|||||||
return (
|
return (
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
{isInSettigsView && <SettingsModal />}
|
{isInSettigsView && <SettingsModal />}
|
||||||
{showReplyModal && activeCid && threadCid && <ReplyModal closeModal={closeModal} parentCid={activeCid} postCid={threadCid} scrollY={scrollY} />}
|
{activeCid && threadCid && <ReplyModal closeModal={closeModal} parentCid={activeCid} postCid={threadCid} scrollY={scrollY} showReplyModal={showReplyModal} />}
|
||||||
{/* TODO: remove this replyCount error once api supports scrolling replies pages */}
|
{/* TODO: remove this replyCount error once api supports scrolling replies pages */}
|
||||||
{replyCount > 60 && <span className={styles.error}>Error: this thread has too many replies, some of them cannot be displayed right now.</span>}
|
{replyCount > 60 && <span className={styles.error}>Error: this thread has too many replies, some of them cannot be displayed right now.</span>}
|
||||||
{error && <span className={styles.error}>Error: {error.message}</span>}
|
{error && <span className={styles.error}>Error: {error.message}</span>}
|
||||||
|
|||||||
Reference in New Issue
Block a user