Comments: expand replies for LC chain before mount instead of after

## Issue
40 Linked comments doesn't scroll for deep replies

## Notes
Don't need an effect for this, plus it was causing the parent to not pick it up for auto-scrolling.
This commit is contained in:
infinite-persistence 2021-10-09 15:38:38 +08:00
parent fc657d98d2
commit 9d48d9924d
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -117,12 +117,18 @@ function Comment(props: Props) {
location: { pathname, search },
} = useHistory();
const isInLinkedCommentChain =
linkedCommentId &&
linkedCommentAncestors[linkedCommentId] &&
linkedCommentAncestors[linkedCommentId].includes(commentId);
const showRepliesOnMount = isInLinkedCommentChain || AUTO_EXPAND_ALL_REPLIES;
const [isReplying, setReplying] = React.useState(false);
const [isEditing, setEditing] = useState(false);
const [editedMessage, setCommentValue] = useState(message);
const [charCount, setCharCount] = useState(editedMessage.length);
const [showReplies, setShowReplies] = useState(false);
const [page, setPage] = useState(0);
const [showReplies, setShowReplies] = useState(showRepliesOnMount);
const [page, setPage] = useState(showRepliesOnMount ? 1 : 0);
const [advancedEditor] = usePersistedState('comment-editor-mode', false);
const [displayDeadComment, setDisplayDeadComment] = React.useState(false);
const hasChannels = myChannels && myChannels.length > 0;
@ -140,19 +146,6 @@ function Comment(props: Props) {
}
} catch (e) {}
// Auto-expand (limited to linked-comments for now, but can be for all)
useEffect(() => {
const isInLinkedCommentChain =
linkedCommentId &&
linkedCommentAncestors[linkedCommentId] &&
linkedCommentAncestors[linkedCommentId].includes(commentId);
if (isInLinkedCommentChain || AUTO_EXPAND_ALL_REPLIES) {
setShowReplies(true);
setPage(1);
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if (isEditing) {
setCharCount(editedMessage.length);