Fix recent comments
This commit is contained in:
parent
1a87fb6239
commit
3a511d0647
4 changed files with 22 additions and 46 deletions
|
@ -52,7 +52,6 @@ type Props = {
|
||||||
supportDisabled: boolean,
|
supportDisabled: boolean,
|
||||||
uri: string,
|
uri: string,
|
||||||
disableInput?: boolean,
|
disableInput?: boolean,
|
||||||
onSlimInputClick?: () => void,
|
|
||||||
createComment: (string, string, string, ?string, ?string, ?string, boolean) => Promise<any>,
|
createComment: (string, string, string, ?string, ?string, ?string, boolean) => Promise<any>,
|
||||||
doFetchCreatorSettings: (channelId: string) => Promise<any>,
|
doFetchCreatorSettings: (channelId: string) => Promise<any>,
|
||||||
doToast: ({ message: string }) => void,
|
doToast: ({ message: string }) => void,
|
||||||
|
@ -84,7 +83,6 @@ export function CommentCreate(props: Props) {
|
||||||
supportDisabled,
|
supportDisabled,
|
||||||
uri,
|
uri,
|
||||||
disableInput,
|
disableInput,
|
||||||
onSlimInputClick,
|
|
||||||
createComment,
|
createComment,
|
||||||
doFetchCreatorSettings,
|
doFetchCreatorSettings,
|
||||||
doToast,
|
doToast,
|
||||||
|
@ -527,7 +525,6 @@ export function CommentCreate(props: Props) {
|
||||||
}}
|
}}
|
||||||
handleSubmit={handleCreateComment}
|
handleSubmit={handleCreateComment}
|
||||||
slimInput={isMobile}
|
slimInput={isMobile}
|
||||||
onSlimInputClick={onSlimInputClick}
|
|
||||||
commentSelectorsProps={commentSelectorsProps}
|
commentSelectorsProps={commentSelectorsProps}
|
||||||
submitButtonRef={buttonRef}
|
submitButtonRef={buttonRef}
|
||||||
setShowSelectors={setShowSelectors}
|
setShowSelectors={setShowSelectors}
|
||||||
|
|
|
@ -49,7 +49,6 @@ type Props = {
|
||||||
showSelectors?: boolean,
|
showSelectors?: boolean,
|
||||||
submitButtonRef?: any,
|
submitButtonRef?: any,
|
||||||
tipModalOpen?: boolean,
|
tipModalOpen?: boolean,
|
||||||
onSlimInputClick?: () => void,
|
|
||||||
onChange?: (any) => any,
|
onChange?: (any) => any,
|
||||||
setShowSelectors?: (boolean) => void,
|
setShowSelectors?: (boolean) => void,
|
||||||
quickActionHandler?: (any) => any,
|
quickActionHandler?: (any) => any,
|
||||||
|
@ -118,7 +117,6 @@ export class FormField extends React.PureComponent<Props, State> {
|
||||||
showSelectors,
|
showSelectors,
|
||||||
submitButtonRef,
|
submitButtonRef,
|
||||||
tipModalOpen,
|
tipModalOpen,
|
||||||
onSlimInputClick,
|
|
||||||
quickActionHandler,
|
quickActionHandler,
|
||||||
setShowSelectors,
|
setShowSelectors,
|
||||||
render,
|
render,
|
||||||
|
@ -275,7 +273,6 @@ export class FormField extends React.PureComponent<Props, State> {
|
||||||
showSelectors={Boolean(showSelectors)}
|
showSelectors={Boolean(showSelectors)}
|
||||||
slimInput={slimInput}
|
slimInput={slimInput}
|
||||||
tipModalOpen={tipModalOpen}
|
tipModalOpen={tipModalOpen}
|
||||||
onSlimInputClick={onSlimInputClick}
|
|
||||||
>
|
>
|
||||||
{(!slimInput || this.state.drawerOpen) && (label || quickAction) && (
|
{(!slimInput || this.state.drawerOpen) && (label || quickAction) && (
|
||||||
<div className="form-field__two-column">
|
<div className="form-field__two-column">
|
||||||
|
@ -364,7 +361,6 @@ type TextareaWrapperProps = {
|
||||||
showSelectors?: boolean,
|
showSelectors?: boolean,
|
||||||
commentSelectorsProps?: any,
|
commentSelectorsProps?: any,
|
||||||
tipModalOpen?: boolean,
|
tipModalOpen?: boolean,
|
||||||
onSlimInputClick?: () => void,
|
|
||||||
toggleDrawer: () => void,
|
toggleDrawer: () => void,
|
||||||
closeSelector?: () => void,
|
closeSelector?: () => void,
|
||||||
};
|
};
|
||||||
|
@ -377,7 +373,6 @@ function TextareaWrapper(wrapperProps: TextareaWrapperProps) {
|
||||||
commentSelectorsProps,
|
commentSelectorsProps,
|
||||||
showSelectors,
|
showSelectors,
|
||||||
tipModalOpen,
|
tipModalOpen,
|
||||||
onSlimInputClick,
|
|
||||||
toggleDrawer,
|
toggleDrawer,
|
||||||
closeSelector,
|
closeSelector,
|
||||||
} = wrapperProps;
|
} = wrapperProps;
|
||||||
|
@ -385,18 +380,11 @@ function TextareaWrapper(wrapperProps: TextareaWrapperProps) {
|
||||||
function handleCloseAll() {
|
function handleCloseAll() {
|
||||||
toggleDrawer();
|
toggleDrawer();
|
||||||
if (closeSelector) closeSelector();
|
if (closeSelector) closeSelector();
|
||||||
if (onSlimInputClick) onSlimInputClick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return slimInput ? (
|
return slimInput ? (
|
||||||
!isDrawerOpen ? (
|
!isDrawerOpen ? (
|
||||||
<div
|
<div role="button" onClick={toggleDrawer}>
|
||||||
role="button"
|
|
||||||
onClick={() => {
|
|
||||||
toggleDrawer();
|
|
||||||
if (onSlimInputClick) onSlimInputClick();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
@ -73,9 +73,6 @@ export default function LivestreamChatLayout(props: Props) {
|
||||||
const discussionElement = isMobile ? mobileElement : webElement;
|
const discussionElement = isMobile ? mobileElement : webElement;
|
||||||
const allCommentsElem = document.querySelectorAll('.livestream__comment');
|
const allCommentsElem = document.querySelectorAll('.livestream__comment');
|
||||||
const lastCommentElem = allCommentsElem && allCommentsElem[allCommentsElem.length - 1];
|
const lastCommentElem = allCommentsElem && allCommentsElem[allCommentsElem.length - 1];
|
||||||
const minScrollPos =
|
|
||||||
discussionElement && lastCommentElem && discussionElement.scrollHeight - lastCommentElem.offsetHeight * 2;
|
|
||||||
const minOffset = discussionElement && minScrollPos && discussionElement.scrollHeight - minScrollPos;
|
|
||||||
|
|
||||||
const [viewMode, setViewMode] = React.useState(VIEW_MODES.CHAT);
|
const [viewMode, setViewMode] = React.useState(VIEW_MODES.CHAT);
|
||||||
const [scrollPos, setScrollPos] = React.useState(0);
|
const [scrollPos, setScrollPos] = React.useState(0);
|
||||||
|
@ -85,16 +82,18 @@ export default function LivestreamChatLayout(props: Props) {
|
||||||
const [chatHidden, setChatHidden] = React.useState(false);
|
const [chatHidden, setChatHidden] = React.useState(false);
|
||||||
const [didInitialScroll, setDidInitialScroll] = React.useState(false);
|
const [didInitialScroll, setDidInitialScroll] = React.useState(false);
|
||||||
const [bottomScrollTop, setBottomScrollTop] = React.useState(0);
|
const [bottomScrollTop, setBottomScrollTop] = React.useState(0);
|
||||||
const [inputDrawerOpen, setInputDrawerOpen] = React.useState(false);
|
const [minScrollHeight, setMinScrollHeight] = React.useState(0);
|
||||||
|
|
||||||
const recentScrollPos = isMobile ? (bottomScrollTop > 0 && minOffset ? bottomScrollTop - minOffset : 0) : 0;
|
|
||||||
const claimId = claim && claim.claim_id;
|
const claimId = claim && claim.claim_id;
|
||||||
const commentsToDisplay = viewMode === VIEW_MODES.CHAT ? commentsByChronologicalOrder : superChatsByAmount;
|
const commentsToDisplay = viewMode === VIEW_MODES.CHAT ? commentsByChronologicalOrder : superChatsByAmount;
|
||||||
const commentsLength = commentsToDisplay && commentsToDisplay.length;
|
const commentsLength = commentsToDisplay && commentsToDisplay.length;
|
||||||
const pinnedComment = pinnedComments.length > 0 ? pinnedComments[0] : null;
|
const pinnedComment = pinnedComments.length > 0 ? pinnedComments[0] : null;
|
||||||
const { superChatsChannelUrls, superChatsFiatAmount, superChatsLBCAmount } = getTipValues(superChatsByAmount);
|
const { superChatsChannelUrls, superChatsFiatAmount, superChatsLBCAmount } = getTipValues(superChatsByAmount);
|
||||||
const hasRecentComments = Boolean(
|
const hasRecentComments = Boolean(
|
||||||
scrollPos && (!isMobile || recentScrollPos) && scrollPos < recentScrollPos && viewMode === VIEW_MODES.CHAT
|
(scrollPos || scrollPos === 0) &&
|
||||||
|
(!isMobile || minScrollHeight) &&
|
||||||
|
scrollPos < minScrollHeight &&
|
||||||
|
viewMode === VIEW_MODES.CHAT
|
||||||
);
|
);
|
||||||
|
|
||||||
const restoreScrollPos = React.useCallback(() => {
|
const restoreScrollPos = React.useCallback(() => {
|
||||||
|
@ -150,9 +149,18 @@ export default function LivestreamChatLayout(props: Props) {
|
||||||
function handleScroll() {
|
function handleScroll() {
|
||||||
if (discussionElement) {
|
if (discussionElement) {
|
||||||
const scrollTop = discussionElement.scrollTop;
|
const scrollTop = discussionElement.scrollTop;
|
||||||
|
|
||||||
if (!scrollPos || scrollTop !== scrollPos) {
|
if (!scrollPos || scrollTop !== scrollPos) {
|
||||||
setScrollPos(scrollTop);
|
setScrollPos(scrollTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isMobile) {
|
||||||
|
const pos = lastCommentElem && bottomScrollTop - lastCommentElem.getBoundingClientRect().height;
|
||||||
|
|
||||||
|
if (!minScrollHeight || minScrollHeight !== pos) {
|
||||||
|
setMinScrollHeight(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,19 +168,19 @@ export default function LivestreamChatLayout(props: Props) {
|
||||||
discussionElement.addEventListener('scroll', handleScroll);
|
discussionElement.addEventListener('scroll', handleScroll);
|
||||||
return () => discussionElement.removeEventListener('scroll', handleScroll);
|
return () => discussionElement.removeEventListener('scroll', handleScroll);
|
||||||
}
|
}
|
||||||
}, [discussionElement, scrollPos, viewMode]);
|
}, [bottomScrollTop, discussionElement, isMobile, lastCommentElem, minScrollHeight, scrollPos]);
|
||||||
|
|
||||||
// Retain scrollPos=0 when receiving new messages.
|
// Retain scrollPos=0 when receiving new messages.
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (discussionElement && commentsLength > 0) {
|
if (discussionElement && commentsLength > 0) {
|
||||||
// Only update comment scroll if the user hasn't scrolled up to view old comments
|
// Only update comment scroll if the user hasn't scrolled up to view old comments
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
if (scrollPos && (!isMobile || recentScrollPos) && scrollPos >= recentScrollPos) {
|
if (scrollPos && (!isMobile || minScrollHeight) && scrollPos >= minScrollHeight) {
|
||||||
// +ve scrollPos: not scrolled (Usually, there'll be a few pixels beyond 0).
|
// +ve scrollPos: not scrolled (Usually, there'll be a few pixels beyond 0).
|
||||||
// -ve scrollPos: user scrolled.
|
// -ve scrollPos: user scrolled.
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
// Use a timer here to ensure we reset after the new comment has been rendered.
|
// Use a timer here to ensure we reset after the new comment has been rendered.
|
||||||
discussionElement.scrollTop = !isMobile ? 0 : discussionElement.scrollHeight + 999;
|
restoreScrollPos();
|
||||||
}, COMMENT_SCROLL_TIMEOUT);
|
}, COMMENT_SCROLL_TIMEOUT);
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}
|
}
|
||||||
|
@ -252,7 +260,7 @@ export default function LivestreamChatLayout(props: Props) {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
console.log(hasRecentComments);
|
||||||
return (
|
return (
|
||||||
<div className={classnames('card livestream__chat', { 'livestream__chat--popout': isPopoutWindow })}>
|
<div className={classnames('card livestream__chat', { 'livestream__chat--popout': isPopoutWindow })}>
|
||||||
{!hideHeader && (
|
{!hideHeader && (
|
||||||
|
@ -345,7 +353,7 @@ export default function LivestreamChatLayout(props: Props) {
|
||||||
uri={uri}
|
uri={uri}
|
||||||
commentsToDisplay={commentsToDisplay}
|
commentsToDisplay={commentsToDisplay}
|
||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
restoreScrollPos={!hasRecentComments && !inputDrawerOpen && restoreScrollPos}
|
restoreScrollPos={!hasRecentComments && restoreScrollPos}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -360,17 +368,7 @@ export default function LivestreamChatLayout(props: Props) {
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<div className="livestream__comment-create">
|
<div className="livestream__comment-create">
|
||||||
<CommentCreate
|
<CommentCreate isLivestream bottom embed={embed} uri={uri} onDoneReplying={restoreScrollPos} />
|
||||||
isLivestream
|
|
||||||
bottom
|
|
||||||
embed={embed}
|
|
||||||
uri={uri}
|
|
||||||
onDoneReplying={restoreScrollPos}
|
|
||||||
onSlimInputClick={() => {
|
|
||||||
restoreScrollPos();
|
|
||||||
setInputDrawerOpen(!inputDrawerOpen);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -147,18 +147,11 @@ $recent-msg-button__height: 2rem;
|
||||||
font-size: var(--font-xsmall);
|
font-size: var(--font-xsmall);
|
||||||
padding: var(--spacing-xxs) var(--spacing-s);
|
padding: var(--spacing-xxs) var(--spacing-s);
|
||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
|
bottom: var(--spacing-xxs);
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: $breakpoint-small) {
|
|
||||||
margin-bottom: var(--spacing-xs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: $breakpoint-small) {
|
|
||||||
bottom: var(--spacing-xxs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.livestream__comment-create {
|
.livestream__comment-create {
|
||||||
|
|
Loading…
Reference in a new issue