mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-24 00:38:49 +01:00
Fix textarea focus not working
This commit is contained in:
parent
ea0352e51a
commit
2def939821
1 changed files with 30 additions and 18 deletions
|
@ -96,28 +96,36 @@ function Compose({
|
||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const oninputTextarea = () => {
|
||||||
|
if (!textareaRef.current) return;
|
||||||
|
textareaRef.current.dispatchEvent(new Event('input'));
|
||||||
|
};
|
||||||
|
const focusTextarea = () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
textareaRef.current?.focus();
|
||||||
|
}, 100);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (replyToStatus) {
|
if (replyToStatus) {
|
||||||
const { spoilerText, visibility, sensitive } = replyToStatus;
|
const { spoilerText, visibility, sensitive } = replyToStatus;
|
||||||
if (spoilerText && spoilerTextRef.current) {
|
if (spoilerText && spoilerTextRef.current) {
|
||||||
spoilerTextRef.current.value = spoilerText;
|
spoilerTextRef.current.value = spoilerText;
|
||||||
spoilerTextRef.current.focus();
|
|
||||||
} else {
|
|
||||||
const mentions = new Set([
|
|
||||||
replyToStatus.account.acct,
|
|
||||||
...replyToStatus.mentions.map((m) => m.acct),
|
|
||||||
]);
|
|
||||||
const allMentions = [...mentions].filter(
|
|
||||||
(m) => m !== currentAccountInfo.acct,
|
|
||||||
);
|
|
||||||
if (allMentions.length > 0) {
|
|
||||||
textareaRef.current.value = `${allMentions
|
|
||||||
.map((m) => `@${m}`)
|
|
||||||
.join(' ')} `;
|
|
||||||
textareaRef.current.dispatchEvent(new Event('input'));
|
|
||||||
}
|
|
||||||
textareaRef.current.focus();
|
|
||||||
}
|
}
|
||||||
|
const mentions = new Set([
|
||||||
|
replyToStatus.account.acct,
|
||||||
|
...replyToStatus.mentions.map((m) => m.acct),
|
||||||
|
]);
|
||||||
|
const allMentions = [...mentions].filter(
|
||||||
|
(m) => m !== currentAccountInfo.acct,
|
||||||
|
);
|
||||||
|
if (allMentions.length > 0) {
|
||||||
|
textareaRef.current.value = `${allMentions
|
||||||
|
.map((m) => `@${m}`)
|
||||||
|
.join(' ')} `;
|
||||||
|
oninputTextarea();
|
||||||
|
}
|
||||||
|
focusTextarea();
|
||||||
setVisibility(visibility);
|
setVisibility(visibility);
|
||||||
setSensitive(sensitive);
|
setSensitive(sensitive);
|
||||||
}
|
}
|
||||||
|
@ -136,7 +144,8 @@ function Compose({
|
||||||
expiresIn: poll?.expiresIn || expiresInFromExpiresAt(poll.expiresAt),
|
expiresIn: poll?.expiresIn || expiresInFromExpiresAt(poll.expiresAt),
|
||||||
};
|
};
|
||||||
textareaRef.current.value = status;
|
textareaRef.current.value = status;
|
||||||
textareaRef.current.dispatchEvent(new Event('input'));
|
oninputTextarea();
|
||||||
|
focusTextarea();
|
||||||
spoilerTextRef.current.value = spoilerText;
|
spoilerTextRef.current.value = spoilerText;
|
||||||
setVisibility(visibility);
|
setVisibility(visibility);
|
||||||
setSensitive(sensitive);
|
setSensitive(sensitive);
|
||||||
|
@ -156,8 +165,9 @@ function Compose({
|
||||||
console.log({ statusSource });
|
console.log({ statusSource });
|
||||||
const { text, spoilerText } = statusSource;
|
const { text, spoilerText } = statusSource;
|
||||||
textareaRef.current.value = text;
|
textareaRef.current.value = text;
|
||||||
textareaRef.current.dispatchEvent(new Event('input'));
|
|
||||||
textareaRef.current.dataset.source = text;
|
textareaRef.current.dataset.source = text;
|
||||||
|
oninputTextarea();
|
||||||
|
focusTextarea();
|
||||||
spoilerTextRef.current.value = spoilerText;
|
spoilerTextRef.current.value = spoilerText;
|
||||||
setVisibility(visibility);
|
setVisibility(visibility);
|
||||||
setSensitive(sensitive);
|
setSensitive(sensitive);
|
||||||
|
@ -170,6 +180,8 @@ function Compose({
|
||||||
setUIState('error');
|
setUIState('error');
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
} else {
|
||||||
|
focusTextarea();
|
||||||
}
|
}
|
||||||
}, [draftStatus, editStatus, replyToStatus]);
|
}, [draftStatus, editStatus, replyToStatus]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue