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:
parent
fc657d98d2
commit
9d48d9924d
1 changed files with 8 additions and 15 deletions
|
@ -117,12 +117,18 @@ function Comment(props: Props) {
|
||||||
location: { pathname, search },
|
location: { pathname, search },
|
||||||
} = useHistory();
|
} = useHistory();
|
||||||
|
|
||||||
|
const isInLinkedCommentChain =
|
||||||
|
linkedCommentId &&
|
||||||
|
linkedCommentAncestors[linkedCommentId] &&
|
||||||
|
linkedCommentAncestors[linkedCommentId].includes(commentId);
|
||||||
|
const showRepliesOnMount = isInLinkedCommentChain || AUTO_EXPAND_ALL_REPLIES;
|
||||||
|
|
||||||
const [isReplying, setReplying] = React.useState(false);
|
const [isReplying, setReplying] = React.useState(false);
|
||||||
const [isEditing, setEditing] = useState(false);
|
const [isEditing, setEditing] = useState(false);
|
||||||
const [editedMessage, setCommentValue] = useState(message);
|
const [editedMessage, setCommentValue] = useState(message);
|
||||||
const [charCount, setCharCount] = useState(editedMessage.length);
|
const [charCount, setCharCount] = useState(editedMessage.length);
|
||||||
const [showReplies, setShowReplies] = useState(false);
|
const [showReplies, setShowReplies] = useState(showRepliesOnMount);
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(showRepliesOnMount ? 1 : 0);
|
||||||
const [advancedEditor] = usePersistedState('comment-editor-mode', false);
|
const [advancedEditor] = usePersistedState('comment-editor-mode', false);
|
||||||
const [displayDeadComment, setDisplayDeadComment] = React.useState(false);
|
const [displayDeadComment, setDisplayDeadComment] = React.useState(false);
|
||||||
const hasChannels = myChannels && myChannels.length > 0;
|
const hasChannels = myChannels && myChannels.length > 0;
|
||||||
|
@ -140,19 +146,6 @@ function Comment(props: Props) {
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} 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(() => {
|
useEffect(() => {
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
setCharCount(editedMessage.length);
|
setCharCount(editedMessage.length);
|
||||||
|
|
Loading…
Reference in a new issue