diff --git a/ui/component/commentCreate/index.js b/ui/component/commentCreate/index.js index 80793559b..821baa77a 100644 --- a/ui/component/commentCreate/index.js +++ b/ui/component/commentCreate/index.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import { doCommentCreate, makeSelectClaimForUri } from 'lbry-redux'; +import { doCommentCreate, makeSelectClaimForUri, selectMyChannelClaims } from 'lbry-redux'; import { doOpenModal } from 'redux/actions/app'; import { CommentCreate } from './view'; import { selectUserVerifiedEmail } from 'lbryinc'; @@ -7,6 +7,7 @@ import { selectUserVerifiedEmail } from 'lbryinc'; const select = (state, props) => ({ commentingEnabled: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true, claim: makeSelectClaimForUri(props.uri)(state), + channels: selectMyChannelClaims(state), }); const perform = dispatch => ({ diff --git a/ui/component/commentCreate/view.jsx b/ui/component/commentCreate/view.jsx index 742f6036f..70c49029e 100644 --- a/ui/component/commentCreate/view.jsx +++ b/ui/component/commentCreate/view.jsx @@ -14,16 +14,32 @@ type Props = { claim: StreamClaim, openModal: (id: string, { onCommentAcknowledge: () => void }) => void, createComment: (string, string, string) => void, + channels: ?Array, }; export function CommentCreate(props: Props) { - const { commentingEnabled, createComment, claim, openModal } = props; + const { commentingEnabled, createComment, claim, openModal, channels } = props; const { claim_id: claimId } = claim; const [commentValue, setCommentValue] = usePersistedState(`comment-${claimId}`, ''); const [commentAck, setCommentAck] = usePersistedState('comment-acknowledge', false); const [channel, setChannel] = usePersistedState('comment-channel', ''); const [charCount, setCharCount] = useState(commentValue.length); + const topChannel = + channels && + channels.reduce((top, channel) => { + const topClaimCount = (top && top.meta && top.meta.claims_in_channel) || 0; + const currentClaimCount = (channel && channel.meta && channel.meta.claims_in_channel) || 0; + return topClaimCount >= currentClaimCount ? top : channel; + }); + + useEffect(() => { + // set default channel + if ((channel === '' || channel === 'anonymous') && topChannel) { + handleChannelChange(topChannel.name); + } + }, [channel, topChannel]); + function handleCommentChange(event) { setCommentValue(event.target.value); }