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';
|
2021-07-29 16:53:36 +02:00
|
|
|
import {
|
2021-12-31 18:52:26 +01:00
|
|
|
selectClaimForUri,
|
2021-07-29 16:53:36 +02:00
|
|
|
makeSelectClaimForUri,
|
2021-12-31 18:52:26 +01:00
|
|
|
selectClaimIsMine,
|
2021-07-29 16:53:36 +02:00
|
|
|
selectFetchingMyChannels,
|
2021-10-08 05:47:39 +02:00
|
|
|
} from 'redux/selectors/claims';
|
2020-09-30 20:46:17 +02:00
|
|
|
import {
|
2021-10-11 08:02:17 +02:00
|
|
|
selectTopLevelCommentsForUri,
|
2021-07-15 16:43:28 +02:00
|
|
|
makeSelectTopLevelTotalPagesForUri,
|
2020-09-30 20:46:17 +02:00
|
|
|
selectIsFetchingComments,
|
2021-10-01 09:49:37 +02:00
|
|
|
selectIsFetchingCommentsById,
|
2021-07-15 18:13:01 +02:00
|
|
|
selectIsFetchingReacts,
|
2020-09-30 20:46:17 +02:00
|
|
|
makeSelectTotalCommentsCountForUri,
|
2021-10-06 20:40:40 +02:00
|
|
|
selectOthersReacts,
|
|
|
|
selectMyReacts,
|
2021-12-31 18:52:26 +01:00
|
|
|
selectCommentIdsForUri,
|
2021-07-29 16:53:36 +02:00
|
|
|
selectSettingsByChannelId,
|
2021-10-11 08:02:17 +02:00
|
|
|
selectPinnedCommentsForUri,
|
2020-09-30 20:46:17 +02:00
|
|
|
} from 'redux/selectors/comments';
|
2021-07-15 16:43:28 +02:00
|
|
|
import { doCommentReset, doCommentList, doCommentById, doCommentReactList } from 'redux/actions/comments';
|
2021-07-20 08:38:29 +02:00
|
|
|
import { selectActiveChannelClaim } from 'redux/selectors/app';
|
2022-02-09 16:27:11 +01:00
|
|
|
import { getChannelIdFromClaim } from 'util/claim';
|
2020-10-20 19:10:02 +02:00
|
|
|
import CommentsList from './view';
|
2022-10-24 18:36:30 +02:00
|
|
|
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
|
|
|
|
2021-07-15 16:43:28 +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);
|
|
|
|
|
2021-07-20 08:38:29 +02:00
|
|
|
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)
|
|
|
|
: [];
|
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
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,
|
2021-12-31 18:52:26 +01:00
|
|
|
claimIsMine: selectClaimIsMine(state, claim),
|
2021-07-15 16:43:28 +02:00
|
|
|
isFetchingComments: selectIsFetchingComments(state),
|
2021-10-01 09:49:37 +02:00
|
|
|
isFetchingCommentsById: selectIsFetchingCommentsById(state),
|
2021-07-15 18:13:01 +02:00
|
|
|
isFetchingReacts: selectIsFetchingReacts(state),
|
2021-07-15 16:43:28 +02:00
|
|
|
fetchingChannels: selectFetchingMyChannels(state),
|
2021-07-29 16:53:36 +02:00
|
|
|
settingsByChannelId: selectSettingsByChannelId(state),
|
2021-10-06 20:40:40 +02:00
|
|
|
myReactsByCommentId: selectMyReacts(state),
|
|
|
|
othersReactsById: selectOthersReacts(state),
|
2021-07-20 08:38:29 +02:00
|
|
|
activeChannelId: activeChannelClaim && activeChannelClaim.claim_id,
|
2022-10-24 18:36:30 +02:00
|
|
|
customCommentServers: makeSelectClientSetting(SETTINGS.CUSTOM_COMMENTS_SERVERS)(state),
|
|
|
|
commentServer: makeSelectClientSetting(SETTINGS.CUSTOM_COMMENTS_SERVER_URL)(state),
|
2021-07-15 16:43:28 +02:00
|
|
|
};
|
|
|
|
};
|
2019-05-17 20:21:07 +02:00
|
|
|
|
2022-10-24 18:36:30 +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
|
|
|
|
2020-01-30 02:02:21 +01:00
|
|
|
export default connect(select, perform)(CommentsList);
|