do not set comment channel anonymous, (#3787)
set to top channel if not already persisted
This commit is contained in:
parent
15416487e7
commit
e87fabe55a
2 changed files with 19 additions and 2 deletions
|
@ -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 => ({
|
||||
|
|
|
@ -14,16 +14,32 @@ type Props = {
|
|||
claim: StreamClaim,
|
||||
openModal: (id: string, { onCommentAcknowledge: () => void }) => void,
|
||||
createComment: (string, string, string) => void,
|
||||
channels: ?Array<ChannelClaim>,
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue