lbry-desktop/ui/component/commentsList/index.js

78 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2019-05-17 20:21:07 +02:00
import { connect } from 'react-redux';
2021-10-11 08:02:17 +02:00
import { doResolveUris } from 'redux/actions/claims';
import {
selectClaimForUri,
makeSelectClaimForUri,
selectClaimIsMine,
selectFetchingMyChannels,
} from 'redux/selectors/claims';
2020-09-30 20:46:17 +02:00
import {
2021-10-11 08:02:17 +02:00
selectTopLevelCommentsForUri,
makeSelectTopLevelTotalPagesForUri,
2020-09-30 20:46:17 +02:00
selectIsFetchingComments,
selectIsFetchingCommentsById,
selectIsFetchingReacts,
2020-09-30 20:46:17 +02:00
makeSelectTotalCommentsCountForUri,
selectOthersReacts,
selectMyReacts,
selectCommentIdsForUri,
selectSettingsByChannelId,
2021-10-11 08:02:17 +02:00
selectPinnedCommentsForUri,
2020-09-30 20:46:17 +02:00
} from 'redux/selectors/comments';
import { doCommentReset, doCommentList, doCommentById, doCommentReactList } from 'redux/actions/comments';
import { selectActiveChannelClaim } from 'redux/selectors/app';
2022-02-09 16:27:11 +01:00
import { getChannelIdFromClaim } from 'util/claim';
import CommentsList from './view';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import * as SETTINGS from 'constants/settings';
import { doSetClientSetting } from 'redux/actions/settings';
2019-05-17 20:21:07 +02:00
const select = (state, props) => {
2022-02-09 16:27:11 +01:00
const { uri } = props;
const claim = selectClaimForUri(state, uri);
const channelId = getChannelIdFromClaim(claim);
const activeChannelClaim = selectActiveChannelClaim(state);
2022-02-09 16:27:11 +01:00
const topLevelComments = selectTopLevelCommentsForUri(state, uri);
2021-10-11 08:02:17 +02:00
const resolvedComments =
topLevelComments && topLevelComments.length > 0
? topLevelComments.filter(({ channel_url }) => makeSelectClaimForUri(channel_url)(state) !== undefined)
: [];
return {
2021-10-11 08:02:17 +02:00
topLevelComments,
resolvedComments,
2022-02-09 16:27:11 +01:00
allCommentIds: selectCommentIdsForUri(state, uri),
pinnedComments: selectPinnedCommentsForUri(state, uri),
topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(uri)(state),
totalComments: makeSelectTotalCommentsCountForUri(uri)(state),
claimId: claim && claim.claim_id,
channelId,
claimIsMine: selectClaimIsMine(state, claim),
isFetchingComments: selectIsFetchingComments(state),
isFetchingCommentsById: selectIsFetchingCommentsById(state),
isFetchingReacts: selectIsFetchingReacts(state),
fetchingChannels: selectFetchingMyChannels(state),
settingsByChannelId: selectSettingsByChannelId(state),
myReactsByCommentId: selectMyReacts(state),
othersReactsById: selectOthersReacts(state),
activeChannelId: activeChannelClaim && activeChannelClaim.claim_id,
customCommentServers: makeSelectClientSetting(SETTINGS.CUSTOM_COMMENTS_SERVERS)(state),
commentServer: makeSelectClientSetting(SETTINGS.CUSTOM_COMMENTS_SERVER_URL)(state),
};
};
2019-05-17 20:21:07 +02:00
const perform = (dispatch, ownProps) => ({
fetchTopLevelComments: (uri, parentId, page, pageSize, sortBy) =>
dispatch(doCommentList(uri, parentId, page, pageSize, sortBy)),
fetchComment: (commentId) => dispatch(doCommentById(commentId)),
fetchReacts: (commentIds) => dispatch(doCommentReactList(commentIds)),
resetComments: (claimId) => dispatch(doCommentReset(claimId)),
doResolveUris: (uris, returnCachedClaims) => dispatch(doResolveUris(uris, returnCachedClaims)),
setCommentServer: (url) => dispatch(doSetClientSetting(SETTINGS.CUSTOM_COMMENTS_SERVER_URL, url, true)),
});
2019-06-27 01:59:27 +02:00
export default connect(select, perform)(CommentsList);