2019-05-17 20:21:07 +02:00
|
|
|
// @flow
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
import {
|
|
|
|
COMMENT_PAGE_SIZE_TOP_LEVEL,
|
|
|
|
SORT_BY,
|
|
|
|
LINKED_COMMENT_QUERY_PARAM,
|
|
|
|
THREAD_COMMENT_QUERY_PARAM,
|
|
|
|
} from 'constants/comment';
|
2021-10-04 13:53:41 +02:00
|
|
|
import { ENABLE_COMMENT_REACTIONS } from 'config';
|
|
|
|
import { useIsMobile, useIsMediumScreen } from 'effects/use-screensize';
|
2022-02-02 13:45:16 +01:00
|
|
|
import { getCommentsListTitle } from 'util/comments';
|
2021-10-04 13:53:41 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import * as REACTION_TYPES from 'constants/reactions';
|
2020-08-24 19:35:21 +02:00
|
|
|
import Button from 'component/button';
|
|
|
|
import Card from 'component/common/card';
|
2021-10-04 13:53:41 +02:00
|
|
|
import classnames from 'classnames';
|
2020-08-24 19:35:21 +02:00
|
|
|
import CommentCreate from 'component/commentCreate';
|
2021-10-04 13:53:41 +02:00
|
|
|
import CommentView from 'component/comment';
|
2021-07-15 16:43:28 +02:00
|
|
|
import debounce from 'util/debounce';
|
2021-10-04 13:53:41 +02:00
|
|
|
import Empty from 'component/common/empty';
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import Spinner from 'component/spinner';
|
|
|
|
import usePersistedState from 'effects/use-persisted-state';
|
2022-03-09 19:05:37 +01:00
|
|
|
import useGetUserMemberships from 'effects/use-get-user-memberships';
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2021-07-15 16:43:28 +02:00
|
|
|
|
|
|
|
const DEBOUNCE_SCROLL_HANDLER_MS = 200;
|
|
|
|
|
|
|
|
function scaleToDevicePixelRatio(value) {
|
|
|
|
const devicePixelRatio = window.devicePixelRatio || 1.0;
|
|
|
|
if (devicePixelRatio < 1.0) {
|
|
|
|
return Math.ceil(value / devicePixelRatio);
|
|
|
|
}
|
|
|
|
return Math.ceil(value * devicePixelRatio);
|
|
|
|
}
|
2019-05-17 20:21:07 +02:00
|
|
|
|
2019-06-27 01:59:27 +02:00
|
|
|
type Props = {
|
2021-07-15 16:43:28 +02:00
|
|
|
allCommentIds: any,
|
2021-08-17 18:09:55 +02:00
|
|
|
pinnedComments: Array<Comment>,
|
2021-07-15 16:43:28 +02:00
|
|
|
topLevelComments: Array<Comment>,
|
|
|
|
topLevelTotalPages: number,
|
2019-05-17 20:21:07 +02:00
|
|
|
uri: string,
|
2022-02-09 16:27:11 +01:00
|
|
|
claimId?: string,
|
|
|
|
channelId?: string,
|
2020-01-30 02:02:21 +01:00
|
|
|
claimIsMine: boolean,
|
2020-05-25 20:45:43 +02:00
|
|
|
isFetchingComments: boolean,
|
2021-10-01 09:49:37 +02:00
|
|
|
isFetchingCommentsById: boolean,
|
2021-07-15 18:13:01 +02:00
|
|
|
isFetchingReacts: boolean,
|
2021-07-15 16:43:28 +02:00
|
|
|
linkedCommentId?: string,
|
2020-09-30 20:46:17 +02:00
|
|
|
totalComments: number,
|
2020-10-02 23:17:12 +02:00
|
|
|
fetchingChannels: boolean,
|
2021-07-15 16:43:28 +02:00
|
|
|
myReactsByCommentId: ?{ [string]: Array<string> }, // "CommentId:MyChannelId" -> reaction array (note the ID concatenation)
|
|
|
|
othersReactsById: ?{ [string]: { [REACTION_TYPES.LIKE | REACTION_TYPES.DISLIKE]: number } },
|
2021-02-09 17:05:56 +01:00
|
|
|
activeChannelId: ?string,
|
2021-07-29 16:53:36 +02:00
|
|
|
settingsByChannelId: { [channelId: string]: PerChannelSettings },
|
2021-10-13 14:59:32 +02:00
|
|
|
commentsAreExpanded?: boolean,
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
threadCommentId: ?string,
|
|
|
|
threadComment: ?Comment,
|
|
|
|
notInDrawer?: boolean,
|
|
|
|
threadCommentAncestors: ?Array<string>,
|
|
|
|
linkedCommentAncestors: ?Array<string>,
|
2022-03-02 13:10:52 +01:00
|
|
|
fetchTopLevelComments: (uri: string, parentId: ?string, page: number, pageSize: number, sortBy: number) => void,
|
2022-02-09 16:27:11 +01:00
|
|
|
fetchComment: (commentId: string) => void,
|
|
|
|
fetchReacts: (commentIds: Array<string>) => Promise<any>,
|
|
|
|
resetComments: (claimId: string) => void,
|
2022-03-09 19:05:37 +01:00
|
|
|
claimsByUri: { [string]: any },
|
|
|
|
doFetchUserMemberships: (claimIdCsv: string) => void,
|
2019-05-17 20:21:07 +02:00
|
|
|
};
|
|
|
|
|
2022-02-09 16:27:11 +01:00
|
|
|
export default function CommentList(props: Props) {
|
2020-09-29 16:10:23 +02:00
|
|
|
const {
|
2021-07-15 16:43:28 +02:00
|
|
|
allCommentIds,
|
2020-09-29 16:10:23 +02:00
|
|
|
uri,
|
2021-08-17 18:09:55 +02:00
|
|
|
pinnedComments,
|
2021-07-15 16:43:28 +02:00
|
|
|
topLevelComments,
|
|
|
|
topLevelTotalPages,
|
2022-02-09 16:27:11 +01:00
|
|
|
claimId,
|
|
|
|
channelId,
|
2020-09-29 16:10:23 +02:00
|
|
|
claimIsMine,
|
|
|
|
isFetchingComments,
|
2021-07-15 18:13:01 +02:00
|
|
|
isFetchingReacts,
|
2021-07-15 16:43:28 +02:00
|
|
|
linkedCommentId,
|
2020-09-30 20:46:17 +02:00
|
|
|
totalComments,
|
2020-10-02 23:17:12 +02:00
|
|
|
fetchingChannels,
|
2021-07-15 16:43:28 +02:00
|
|
|
myReactsByCommentId,
|
|
|
|
othersReactsById,
|
2021-02-09 17:05:56 +01:00
|
|
|
activeChannelId,
|
2021-07-29 16:53:36 +02:00
|
|
|
settingsByChannelId,
|
2021-10-13 14:59:32 +02:00
|
|
|
commentsAreExpanded,
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
threadCommentId,
|
|
|
|
threadComment,
|
|
|
|
notInDrawer,
|
|
|
|
threadCommentAncestors,
|
|
|
|
linkedCommentAncestors,
|
2021-10-04 13:53:41 +02:00
|
|
|
fetchTopLevelComments,
|
|
|
|
fetchComment,
|
2022-02-09 16:27:11 +01:00
|
|
|
fetchReacts,
|
2021-10-04 13:53:41 +02:00
|
|
|
resetComments,
|
2022-03-09 19:05:37 +01:00
|
|
|
claimsByUri,
|
|
|
|
doFetchUserMemberships,
|
2020-09-29 16:10:23 +02:00
|
|
|
} = props;
|
2021-07-15 16:43:28 +02:00
|
|
|
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
const threadRedirect = React.useRef(false);
|
|
|
|
|
|
|
|
const {
|
|
|
|
push,
|
|
|
|
location: { pathname, search },
|
|
|
|
} = useHistory();
|
|
|
|
|
2021-10-04 13:53:41 +02:00
|
|
|
const isMobile = useIsMobile();
|
|
|
|
const isMediumScreen = useIsMediumScreen();
|
2022-02-02 13:44:33 +01:00
|
|
|
|
2022-05-19 19:54:45 +02:00
|
|
|
const currentFetchedPage = Math.ceil(topLevelComments.length / COMMENT_PAGE_SIZE_TOP_LEVEL);
|
2020-10-06 21:35:13 +02:00
|
|
|
const spinnerRef = React.useRef();
|
2022-04-07 06:11:53 +02:00
|
|
|
const commentListRef = React.useRef();
|
2021-07-15 16:43:28 +02:00
|
|
|
const DEFAULT_SORT = ENABLE_COMMENT_REACTIONS ? SORT_BY.POPULARITY : SORT_BY.NEWEST;
|
|
|
|
const [sort, setSort] = usePersistedState('comment-sort-by', DEFAULT_SORT);
|
2022-05-19 19:54:45 +02:00
|
|
|
const [page, setPage] = React.useState(currentFetchedPage > 0 ? currentFetchedPage : 1);
|
2022-02-09 16:27:11 +01:00
|
|
|
const [didInitialPageFetch, setInitialPageFetch] = React.useState(false);
|
2022-02-02 13:44:33 +01:00
|
|
|
const hasDefaultExpansion = commentsAreExpanded || !isMediumScreen || isMobile;
|
2021-10-04 21:25:43 +02:00
|
|
|
const [expandedComments, setExpandedComments] = React.useState(hasDefaultExpansion);
|
2022-05-19 19:54:45 +02:00
|
|
|
const [debouncedUri, setDebouncedUri] = React.useState();
|
2022-02-09 16:27:11 +01:00
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
const totalFetchedComments = allCommentIds ? allCommentIds.length : 0;
|
2021-07-29 16:53:36 +02:00
|
|
|
const channelSettings = channelId ? settingsByChannelId[channelId] : undefined;
|
2021-10-04 13:53:41 +02:00
|
|
|
const moreBelow = page < topLevelTotalPages;
|
2022-02-02 13:45:16 +01:00
|
|
|
const title = getCommentsListTitle(totalComments);
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
const threadDepthLevel = isMobile ? 3 : 10;
|
|
|
|
let threadCommentParent;
|
|
|
|
if (threadCommentAncestors) {
|
|
|
|
threadCommentAncestors.some((ancestor, index) => {
|
|
|
|
if (index >= threadDepthLevel - 1) return true;
|
|
|
|
|
|
|
|
threadCommentParent = ancestor;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const threadTopLevelComment = threadCommentAncestors && threadCommentAncestors[threadCommentAncestors.length - 1];
|
2020-10-28 03:07:40 +01:00
|
|
|
|
2020-10-06 21:35:13 +02:00
|
|
|
// Display comments immediately if not fetching reactions
|
|
|
|
// If not, wait to show comments until reactions are fetched
|
2020-10-20 19:10:02 +02:00
|
|
|
const [readyToDisplayComments, setReadyToDisplayComments] = React.useState(
|
2021-07-15 16:43:28 +02:00
|
|
|
Boolean(othersReactsById) || !ENABLE_COMMENT_REACTIONS
|
2020-10-20 19:10:02 +02:00
|
|
|
);
|
2021-07-15 16:43:28 +02:00
|
|
|
|
2022-03-09 19:05:37 +01:00
|
|
|
// get commenter claim ids for checking premium status
|
2022-04-01 17:41:08 +02:00
|
|
|
const commenterClaimIds = topLevelComments.map((comment) => comment.channel_id);
|
2022-03-09 19:05:37 +01:00
|
|
|
|
|
|
|
// update premium status
|
|
|
|
const shouldFetchUserMemberships = true;
|
|
|
|
useGetUserMemberships(
|
|
|
|
shouldFetchUserMemberships,
|
|
|
|
commenterClaimIds,
|
|
|
|
claimsByUri,
|
|
|
|
doFetchUserMemberships,
|
|
|
|
[topLevelComments],
|
2022-04-01 17:41:08 +02:00
|
|
|
true
|
2022-03-09 19:05:37 +01:00
|
|
|
);
|
|
|
|
|
2022-04-01 17:41:08 +02:00
|
|
|
const handleReset = React.useCallback(() => {
|
|
|
|
if (claimId) resetComments(claimId);
|
|
|
|
setPage(1);
|
|
|
|
}, [claimId, resetComments]);
|
|
|
|
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
function refreshComments() {
|
|
|
|
// Invalidate existing comments
|
|
|
|
setPage(0);
|
|
|
|
}
|
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
function changeSort(newSort) {
|
|
|
|
if (sort !== newSort) {
|
|
|
|
setSort(newSort);
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
refreshComments();
|
2020-08-24 19:35:21 +02:00
|
|
|
}
|
2021-07-15 16:43:28 +02:00
|
|
|
}
|
2020-08-24 19:35:21 +02:00
|
|
|
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
// If a linked comment is deep within a thread, redirect to it's own thread page
|
|
|
|
// based on the set depthLevel (mobile/desktop)
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (
|
|
|
|
!threadCommentId &&
|
|
|
|
linkedCommentId &&
|
|
|
|
linkedCommentAncestors &&
|
|
|
|
linkedCommentAncestors.length > threadDepthLevel - 1 &&
|
|
|
|
!threadRedirect.current
|
|
|
|
) {
|
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
urlParams.set(THREAD_COMMENT_QUERY_PARAM, linkedCommentId);
|
|
|
|
|
|
|
|
push({ pathname, search: urlParams.toString() });
|
|
|
|
// to do it only once
|
|
|
|
threadRedirect.current = true;
|
|
|
|
}
|
|
|
|
}, [linkedCommentAncestors, linkedCommentId, pathname, push, search, threadCommentId, threadDepthLevel]);
|
|
|
|
|
2022-05-19 19:54:45 +02:00
|
|
|
// set new page on scroll debounce and avoid setting the page after navigated uris
|
|
|
|
useEffect(() => {
|
|
|
|
if (debouncedUri && debouncedUri === uri) {
|
|
|
|
setPage(page + 1);
|
|
|
|
setDebouncedUri(undefined);
|
|
|
|
}
|
2022-05-23 16:34:32 +02:00
|
|
|
// only for comparing uri with debounced uri
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [debouncedUri, uri]);
|
2022-05-19 19:54:45 +02:00
|
|
|
|
2022-04-01 17:41:08 +02:00
|
|
|
// Force comments reset
|
2019-06-27 01:59:27 +02:00
|
|
|
useEffect(() => {
|
2021-07-15 16:43:28 +02:00
|
|
|
if (page === 0) {
|
2022-04-01 17:41:08 +02:00
|
|
|
handleReset();
|
2021-07-15 16:43:28 +02:00
|
|
|
}
|
2022-04-01 17:41:08 +02:00
|
|
|
}, [handleReset, page]);
|
|
|
|
|
2022-05-19 19:54:45 +02:00
|
|
|
// Set page back to 1 on every claim switch
|
|
|
|
useEffect(() => {
|
|
|
|
return () => setPage(1);
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [uri]);
|
|
|
|
|
|
|
|
// When navigating to a new claim, the page will be 1 due to the above
|
|
|
|
// and if there was already fetched top level comments, the fetched page will be higher
|
|
|
|
// so set the current page as the fetched page to start fetching new pages from there
|
2022-04-01 17:41:08 +02:00
|
|
|
useEffect(() => {
|
2022-05-19 19:54:45 +02:00
|
|
|
if (page < currentFetchedPage) setPage(currentFetchedPage > 0 ? currentFetchedPage : 1);
|
2022-05-23 16:34:32 +02:00
|
|
|
// only on uri change
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [uri]);
|
2019-06-27 01:59:27 +02:00
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
// Fetch top-level comments
|
2020-10-01 20:43:44 +02:00
|
|
|
useEffect(() => {
|
2022-05-19 19:54:45 +02:00
|
|
|
const isInitialFetch = currentFetchedPage === 0;
|
|
|
|
const isNewPage = page !== 1 && page !== currentFetchedPage;
|
|
|
|
// only one or the other should be true, if both are true it means
|
|
|
|
// it will fetch the wrong page initially. needs Number so it's 0 or 1
|
|
|
|
const hasRightFetchPage = Number(isInitialFetch) ^ Number(isNewPage);
|
|
|
|
|
|
|
|
if (page !== 0 && hasRightFetchPage) {
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
if (page === 1) {
|
|
|
|
if (threadCommentId) {
|
|
|
|
fetchComment(threadCommentId);
|
|
|
|
}
|
|
|
|
if (linkedCommentId) {
|
|
|
|
fetchComment(linkedCommentId);
|
|
|
|
}
|
2021-07-15 16:43:28 +02:00
|
|
|
}
|
|
|
|
|
2022-03-02 13:10:52 +01:00
|
|
|
fetchTopLevelComments(uri, undefined, page, COMMENT_PAGE_SIZE_TOP_LEVEL, sort);
|
2021-07-15 16:43:28 +02:00
|
|
|
}
|
2022-05-19 19:54:45 +02:00
|
|
|
}, [currentFetchedPage, fetchComment, fetchTopLevelComments, linkedCommentId, page, sort, threadCommentId, uri]);
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (threadCommentId) {
|
|
|
|
refreshComments();
|
|
|
|
}
|
|
|
|
}, [threadCommentId]);
|
2021-07-15 16:43:28 +02:00
|
|
|
|
|
|
|
// Fetch reacts
|
|
|
|
useEffect(() => {
|
2021-07-15 18:13:01 +02:00
|
|
|
if (totalFetchedComments > 0 && ENABLE_COMMENT_REACTIONS && !fetchingChannels && !isFetchingReacts) {
|
2021-07-15 16:43:28 +02:00
|
|
|
let idsForReactionFetch;
|
|
|
|
|
|
|
|
if (!othersReactsById || !myReactsByCommentId) {
|
|
|
|
idsForReactionFetch = allCommentIds;
|
|
|
|
} else {
|
|
|
|
idsForReactionFetch = allCommentIds.filter((commentId) => {
|
|
|
|
const key = activeChannelId ? `${commentId}:${activeChannelId}` : commentId;
|
|
|
|
return !othersReactsById[key] || (activeChannelId && !myReactsByCommentId[key]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-20 05:14:56 +02:00
|
|
|
if (idsForReactionFetch.length !== 0) {
|
2021-07-15 16:43:28 +02:00
|
|
|
fetchReacts(idsForReactionFetch)
|
|
|
|
.then(() => {
|
|
|
|
setReadyToDisplayComments(true);
|
|
|
|
})
|
|
|
|
.catch(() => setReadyToDisplayComments(true));
|
|
|
|
}
|
2021-06-17 05:11:40 +02:00
|
|
|
}
|
2021-07-15 16:43:28 +02:00
|
|
|
}, [
|
2021-10-04 13:53:41 +02:00
|
|
|
activeChannelId,
|
2021-07-15 16:43:28 +02:00
|
|
|
allCommentIds,
|
|
|
|
fetchReacts,
|
|
|
|
fetchingChannels,
|
2021-07-15 18:13:01 +02:00
|
|
|
isFetchingReacts,
|
2021-10-04 13:53:41 +02:00
|
|
|
myReactsByCommentId,
|
|
|
|
othersReactsById,
|
|
|
|
totalFetchedComments,
|
2021-07-15 16:43:28 +02:00
|
|
|
]);
|
2020-09-29 16:10:23 +02:00
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
// Scroll to linked-comment
|
2020-08-24 19:35:21 +02:00
|
|
|
useEffect(() => {
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
if (linkedCommentId || threadCommentId) {
|
2021-10-16 07:34:06 +02:00
|
|
|
window.pendingLinkedCommentScroll = true;
|
|
|
|
} else {
|
|
|
|
delete window.pendingLinkedCommentScroll;
|
2020-08-24 19:35:21 +02:00
|
|
|
}
|
2021-10-16 07:34:06 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, []);
|
2020-02-05 04:55:00 +01:00
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
// Infinite scroll
|
2020-10-05 23:25:23 +02:00
|
|
|
useEffect(() => {
|
2022-03-02 13:10:52 +01:00
|
|
|
if (topLevelComments.length === 0) return;
|
|
|
|
|
2022-02-09 16:27:11 +01:00
|
|
|
function shouldFetchNextPage(page, topLevelTotalPages, yPrefetchPx = 1000) {
|
2021-10-04 13:53:41 +02:00
|
|
|
if (!spinnerRef || !spinnerRef.current) return false;
|
2021-07-15 16:43:28 +02:00
|
|
|
|
|
|
|
const rect = spinnerRef.current.getBoundingClientRect(); // $FlowFixMe
|
|
|
|
const windowH = window.innerHeight || document.documentElement.clientHeight; // $FlowFixMe
|
|
|
|
const windowW = window.innerWidth || document.documentElement.clientWidth; // $FlowFixMe
|
|
|
|
|
|
|
|
const isApproachingViewport = yPrefetchPx !== 0 && rect.top < windowH + scaleToDevicePixelRatio(yPrefetchPx);
|
2020-10-06 21:35:13 +02:00
|
|
|
|
|
|
|
const isInViewport =
|
2021-07-15 16:43:28 +02:00
|
|
|
rect.width > 0 &&
|
|
|
|
rect.height > 0 &&
|
|
|
|
rect.bottom >= 0 &&
|
|
|
|
rect.right >= 0 &&
|
2020-10-06 21:35:13 +02:00
|
|
|
// $FlowFixMe
|
2021-07-15 16:43:28 +02:00
|
|
|
rect.top <= windowH &&
|
2020-10-06 21:35:13 +02:00
|
|
|
// $FlowFixMe
|
2021-07-15 16:43:28 +02:00
|
|
|
rect.left <= windowW;
|
2021-07-14 05:06:47 +02:00
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
return (isInViewport || isApproachingViewport) && page < topLevelTotalPages;
|
2021-07-15 16:23:26 +02:00
|
|
|
}
|
2020-10-05 23:25:23 +02:00
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
const handleCommentScroll = debounce(() => {
|
2022-02-09 16:27:11 +01:00
|
|
|
if (shouldFetchNextPage(page, topLevelTotalPages)) {
|
2022-05-19 19:54:45 +02:00
|
|
|
setDebouncedUri(uri);
|
2022-02-09 16:27:11 +01:00
|
|
|
setInitialPageFetch(true);
|
2021-07-15 16:43:28 +02:00
|
|
|
}
|
|
|
|
}, DEBOUNCE_SCROLL_HANDLER_MS);
|
2021-07-15 16:23:26 +02:00
|
|
|
|
2022-02-09 16:27:11 +01:00
|
|
|
if (!didInitialPageFetch) {
|
|
|
|
handleCommentScroll();
|
|
|
|
setInitialPageFetch(true);
|
|
|
|
}
|
|
|
|
|
2022-03-02 13:10:52 +01:00
|
|
|
if (hasDefaultExpansion && !isFetchingComments && readyToDisplayComments && moreBelow) {
|
2022-02-09 16:27:11 +01:00
|
|
|
const commentsInDrawer = Boolean(document.querySelector('.MuiDrawer-root .card--enable-overflow'));
|
|
|
|
const scrollingElement = commentsInDrawer ? document.querySelector('.card--enable-overflow') : window;
|
|
|
|
|
|
|
|
if (scrollingElement) {
|
|
|
|
scrollingElement.addEventListener('scroll', handleCommentScroll);
|
|
|
|
|
|
|
|
return () => scrollingElement.removeEventListener('scroll', handleCommentScroll);
|
2021-07-14 05:06:47 +02:00
|
|
|
}
|
2020-10-05 23:25:23 +02:00
|
|
|
}
|
2021-10-14 13:54:07 +02:00
|
|
|
}, [
|
2022-03-02 13:10:52 +01:00
|
|
|
topLevelComments,
|
2021-10-14 13:54:07 +02:00
|
|
|
hasDefaultExpansion,
|
2022-02-09 16:27:11 +01:00
|
|
|
didInitialPageFetch,
|
2021-10-14 13:54:07 +02:00
|
|
|
isFetchingComments,
|
2022-02-09 16:27:11 +01:00
|
|
|
isMobile,
|
2021-10-14 13:54:07 +02:00
|
|
|
moreBelow,
|
|
|
|
page,
|
|
|
|
readyToDisplayComments,
|
|
|
|
topLevelTotalPages,
|
2022-05-19 19:54:45 +02:00
|
|
|
uri,
|
2021-10-14 13:54:07 +02:00
|
|
|
]);
|
|
|
|
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
const commentProps = {
|
|
|
|
isTopLevel: true,
|
|
|
|
uri,
|
|
|
|
claimIsMine,
|
|
|
|
linkedCommentId,
|
|
|
|
threadCommentId,
|
|
|
|
threadDepthLevel,
|
|
|
|
};
|
2022-04-01 17:41:08 +02:00
|
|
|
const actionButtonsProps = {
|
|
|
|
totalComments,
|
|
|
|
sort,
|
|
|
|
changeSort,
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
handleRefresh: refreshComments,
|
2022-04-01 17:41:08 +02:00
|
|
|
};
|
2021-09-20 16:20:28 +02:00
|
|
|
|
2019-06-27 01:59:27 +02:00
|
|
|
return (
|
2020-08-24 19:35:21 +02:00
|
|
|
<Card
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
className="card--enable-overflow comment__list"
|
|
|
|
title={(!isMobile || notInDrawer) && title}
|
2022-02-04 21:59:11 +01:00
|
|
|
titleActions={<CommentActionButtons {...actionButtonsProps} />}
|
2020-08-24 19:35:21 +02:00
|
|
|
actions={
|
|
|
|
<>
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
{isMobile && !notInDrawer && <CommentActionButtons {...actionButtonsProps} />}
|
2022-02-04 21:59:11 +01:00
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
<CommentCreate uri={uri} />
|
2020-10-07 21:14:52 +02:00
|
|
|
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
{threadCommentId && threadComment && (
|
|
|
|
<span className="comment__actions comment__thread-links">
|
|
|
|
<ThreadLinkButton
|
|
|
|
label={__('View all comments')}
|
|
|
|
threadCommentParent={threadTopLevelComment || threadCommentId}
|
|
|
|
threadCommentId={threadCommentId}
|
|
|
|
isViewAll
|
|
|
|
/>
|
|
|
|
|
|
|
|
{threadCommentParent && (
|
|
|
|
<ThreadLinkButton
|
|
|
|
label={__('Show parent comments')}
|
|
|
|
threadCommentParent={threadCommentParent}
|
|
|
|
threadCommentId={threadCommentId}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</span>
|
2020-12-16 19:31:07 +01:00
|
|
|
)}
|
2020-10-07 21:14:52 +02:00
|
|
|
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
{channelSettings &&
|
|
|
|
channelSettings.comments_enabled &&
|
|
|
|
!isFetchingComments &&
|
|
|
|
!totalComments &&
|
|
|
|
!threadCommentId && <Empty padded text={__('That was pretty deep. What do you think?')} />}
|
|
|
|
|
2021-08-03 17:03:08 +02:00
|
|
|
<ul
|
2022-04-07 06:11:53 +02:00
|
|
|
ref={commentListRef}
|
|
|
|
className={classnames('comments', {
|
|
|
|
'comments--contracted': isMediumScreen && !expandedComments && totalComments > 1,
|
2021-08-03 17:03:08 +02:00
|
|
|
})}
|
|
|
|
>
|
2022-02-09 16:27:11 +01:00
|
|
|
{readyToDisplayComments && (
|
|
|
|
<>
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
{pinnedComments && !threadCommentId && <CommentElements comments={pinnedComments} {...commentProps} />}
|
2022-03-02 13:10:52 +01:00
|
|
|
<CommentElements comments={topLevelComments} {...commentProps} />
|
2022-02-09 16:27:11 +01:00
|
|
|
</>
|
|
|
|
)}
|
2020-08-24 19:35:21 +02:00
|
|
|
</ul>
|
2020-10-07 21:14:52 +02:00
|
|
|
|
2021-10-04 21:25:43 +02:00
|
|
|
{!hasDefaultExpansion && (
|
2022-04-07 06:11:53 +02:00
|
|
|
<div className="card__bottom-actions card__bottom-actions--comments">
|
|
|
|
{(!expandedComments || moreBelow) && totalComments > 1 && (
|
2021-07-15 15:25:48 +02:00
|
|
|
<Button
|
2021-08-03 17:03:08 +02:00
|
|
|
button="link"
|
2021-10-04 13:53:41 +02:00
|
|
|
title={!expandedComments ? __('Expand') : __('More')}
|
2021-08-03 17:03:08 +02:00
|
|
|
label={!expandedComments ? __('Expand') : __('More')}
|
2021-10-04 13:53:41 +02:00
|
|
|
onClick={() => (!expandedComments ? setExpandedComments(true) : setPage(page + 1))}
|
2021-07-15 15:25:48 +02:00
|
|
|
/>
|
|
|
|
)}
|
2022-04-07 06:11:53 +02:00
|
|
|
{expandedComments && totalComments > 1 && (
|
2021-07-15 15:25:48 +02:00
|
|
|
<Button
|
2021-08-03 17:03:08 +02:00
|
|
|
button="link"
|
2021-10-04 13:53:41 +02:00
|
|
|
title={__('Collapse')}
|
2021-08-03 17:03:08 +02:00
|
|
|
label={__('Collapse')}
|
2022-04-07 06:11:53 +02:00
|
|
|
onClick={() => {
|
|
|
|
setExpandedComments(false);
|
|
|
|
if (commentListRef.current) {
|
|
|
|
const ADDITIONAL_OFFSET = 200;
|
|
|
|
const refTop = commentListRef.current.getBoundingClientRect().top;
|
|
|
|
window.scrollTo({
|
|
|
|
top: refTop + window.pageYOffset - ADDITIONAL_OFFSET,
|
|
|
|
behavior: 'smooth',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}
|
2021-07-15 15:25:48 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
{(threadCommentId ? !readyToDisplayComments : isFetchingComments || (hasDefaultExpansion && moreBelow)) && (
|
2020-10-06 21:35:13 +02:00
|
|
|
<div className="main--empty" ref={spinnerRef}>
|
2020-10-05 23:25:23 +02:00
|
|
|
<Spinner type="small" />
|
2020-08-24 19:35:21 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
2019-06-27 01:59:27 +02:00
|
|
|
);
|
2019-05-17 20:21:07 +02:00
|
|
|
}
|
|
|
|
|
2022-02-09 16:27:11 +01:00
|
|
|
type CommentProps = {
|
|
|
|
comments: Array<Comment>,
|
|
|
|
};
|
|
|
|
|
|
|
|
const CommentElements = (commentProps: CommentProps) => {
|
|
|
|
const { comments, ...commentsProps } = commentProps;
|
|
|
|
|
|
|
|
return comments.map((comment) => <CommentView key={comment.comment_id} comment={comment} {...commentsProps} />);
|
|
|
|
};
|
2022-02-04 21:59:11 +01:00
|
|
|
|
|
|
|
type ActionButtonsProps = {
|
|
|
|
totalComments: number,
|
|
|
|
sort: string,
|
|
|
|
changeSort: (string) => void,
|
2022-04-01 17:41:08 +02:00
|
|
|
handleRefresh: () => void,
|
2022-02-04 21:59:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const CommentActionButtons = (actionButtonsProps: ActionButtonsProps) => {
|
2022-04-01 17:41:08 +02:00
|
|
|
const { totalComments, sort, changeSort, handleRefresh } = actionButtonsProps;
|
2022-02-04 21:59:11 +01:00
|
|
|
|
|
|
|
const sortButtonProps = { activeSort: sort, changeSort };
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{totalComments > 1 && ENABLE_COMMENT_REACTIONS && (
|
|
|
|
<span className="comment__sort">
|
|
|
|
<SortButton {...sortButtonProps} label={__('Best')} icon={ICONS.BEST} sortOption={SORT_BY.POPULARITY} />
|
|
|
|
<SortButton
|
|
|
|
{...sortButtonProps}
|
|
|
|
label={__('Controversial')}
|
|
|
|
icon={ICONS.CONTROVERSIAL}
|
|
|
|
sortOption={SORT_BY.CONTROVERSY}
|
|
|
|
/>
|
|
|
|
<SortButton {...sortButtonProps} label={__('New')} icon={ICONS.NEW} sortOption={SORT_BY.NEWEST} />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
|
2022-04-01 17:41:08 +02:00
|
|
|
<Button button="alt" icon={ICONS.REFRESH} title={__('Refresh')} onClick={handleRefresh} />
|
2022-02-04 21:59:11 +01:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
type SortButtonProps = {
|
|
|
|
activeSort: string,
|
|
|
|
sortOption: string,
|
|
|
|
changeSort: (string) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
const SortButton = (sortButtonProps: SortButtonProps) => {
|
|
|
|
const { activeSort, sortOption, changeSort, ...buttonProps } = sortButtonProps;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
{...buttonProps}
|
|
|
|
className={classnames(`button-toggle`, { 'button-toggle--active': activeSort === sortOption })}
|
|
|
|
button="alt"
|
|
|
|
iconSize={18}
|
|
|
|
onClick={() => changeSort(sortOption)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
Re-design comment threads (#1489)
* Redesign threadline and fetching state
- threadline goes right below channel avatar, mimicking reddits implementation, has a increase effect on hover and is slimmer, creating more space for comments on screen
- fetching state now replaces show/hide button, also mimicking reddit, and now says that it is loading, instead of a blank spinner, and also improves space a bit
* Redesign comment threads
- Allow for infinite comment chains
- Can go back and forth between the pages
- Can go back to all comments or to the first comment in the chain
- Some other improvements, which include:
- add title on non-drawer comment sections (couldn't see amount of comments)
- fix Expandable component (would begin expanded and collapse after the effect runs, which looked bad and shifted the layout, now each comments greater than the set length begins collapsed)
- used constants for consistency
* Fix replying to last thread comment
* Fix buttons condition (only on fetched comment to avoid deleted case)
* Fix auto-scroll
* Bring back instant feedback for Show More replies
* Improve thread back links
- Now going back to all comments links the top-level comment for easier navigation
- Going back to ~ previous ~ now goes back into the chain instead of topmost level
* Clear timeouts due to unrelated issue
* Fix deep thread linked comment case and more scroll improvements
* More minor changes
* Flow
* Fix commentList tile style
* Fix long channel names overflowing on small screens
* More scroll changes
* Fix threadline
* Revert "Fix long channel names overflowing on small screens"
This reverts commit e4d2dc7da5861ed8136a60f3352e41a690cd4d33.
* Fix replies fetch
* Revert "Fix replies fetch"
This reverts commit ec70054675a604a7a5f3764ba07c36bf7b0f49c8.
* Cleanup and make smooth
* Always use linked comment on threads
* Cleanup
* Higlight thread comment
* Fix comment body styles
2022-05-16 12:22:13 +02:00
|
|
|
|
|
|
|
type ThreadLinkProps = {
|
|
|
|
label: string,
|
|
|
|
isViewAll?: boolean,
|
|
|
|
threadCommentParent: string,
|
|
|
|
threadCommentId: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
const ThreadLinkButton = (props: ThreadLinkProps) => {
|
|
|
|
const { label, isViewAll, threadCommentParent, threadCommentId } = props;
|
|
|
|
|
|
|
|
const {
|
|
|
|
push,
|
|
|
|
location: { pathname, search },
|
|
|
|
} = useHistory();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={label}
|
|
|
|
icon={ICONS.ARROW_LEFT}
|
|
|
|
iconSize={12}
|
|
|
|
onClick={() => {
|
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
|
|
|
|
if (!isViewAll) {
|
|
|
|
urlParams.set(THREAD_COMMENT_QUERY_PARAM, threadCommentParent);
|
|
|
|
// on moving back, link the current thread comment so that it auto-expands into the correct conversation
|
|
|
|
urlParams.set(LINKED_COMMENT_QUERY_PARAM, threadCommentId);
|
|
|
|
} else {
|
|
|
|
urlParams.delete(THREAD_COMMENT_QUERY_PARAM);
|
|
|
|
// links the top-level comment when going back to all comments, for easy locating
|
|
|
|
// in the middle of big comment sections
|
|
|
|
urlParams.set(LINKED_COMMENT_QUERY_PARAM, threadCommentParent);
|
|
|
|
}
|
|
|
|
window.pendingLinkedCommentScroll = true;
|
|
|
|
|
|
|
|
push({ pathname, search: urlParams.toString() });
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|