more redux comments

This commit is contained in:
Jessop Breth 2019-05-20 20:47:23 -04:00 committed by Sean Yesmunt
parent 86e1743388
commit 6cbade699f
7 changed files with 74 additions and 89 deletions

View file

@ -1,13 +1,12 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimForUri, selectMyChannelClaims, doCommentCreate, makeSelectCommentsForUri } from 'lbry-redux'; import { doCommentCreate, makeSelectClaimForUri, selectMyActiveChannelUri, } from 'lbry-redux';
import CommentCreate from './view'; import CommentCreate from './view';
const select = (state, props) => ({ const select = (state, props) => ({
channels: selectMyChannelClaims(state),
comments: makeSelectCommentsForUri(props.uri)(state),
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
channelUri: selectMyActiveChannelUri(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({

View file

@ -1,55 +1,71 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import { FormField } from 'component/common/form'; import { FormField, Form } from 'component/common/form';
import Button from 'component/button'; import Button from 'component/button';
import ChannelSection from 'component/selectChannel'; import ChannelSection from 'component/selectChannel';
import { parseURI } from 'lbry-redux';
// props:
type Props = { type Props = {
comment: string, uri: string,
claimId: string, channelUri: string,
authorChannelId: string, createComment: params => {},
}; };
class CommentCreate extends React.PureComponent<Props> { class CommentCreate extends React.PureComponent<Props> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.state = { this.state = {
channel: 'Anonymous', message: '',
comment: '',
channelId: '',
}; };
// set state or props for comment form
(this: any).handleCommentChange = this.handleCommentChange.bind(this); (this: any).handleCommentChange = this.handleCommentChange.bind(this);
(this: any).handleChannelChange = this.handleChannelChange.bind(this); (this: any).handleChannelChange = this.handleChannelChange.bind(this);
(this: any).handleSubmit = this.handleSubmit.bind(this);
} }
handleCommentChange(event) { handleCommentChange(event) {
this.setState({ comment: event.comment.target.value }); this.setState({ message: event.target.value });
} }
handleChannelChange(channel) { handleChannelChange(channelUri) {
this.setState({ channel: channel }); this.setState({ channelUri: channelUri });
}
handleSubmit() {
const { createComment, claim, channelUri } = this.props;
console.log('claim', claim)
const { claim_id: claimId } = claim;
const { message } = this.state;
let cmt = { message, channelId: parseURI(channelUri).claimId, claimId };
console.log('CMT', cmt);
console.log('PURI', claimId);
console.log('PURI', parseURI(channelUri));
} }
render() { render() {
console.log(this.state); const { channelUri } = this.props;
return ( return (
<section className="card card--section"> <section className="card card--section">
<Form onSubmit={this.handleSubmit}>
<div className="card__content"> <div className="card__content">
<FormField <FormField
type="textarea" type="textarea"
name="content_description" name="content_description"
label={__('Text')} label={__('Text')}
placeholder={__('Your comment')} placeholder={__('Your comment')}
value={this.state.comment} value={this.state.message}
onChange={text => this.handleCommentChange({ comment: text })} onChange={this.handleCommentChange}
/> />
</div> </div>
<div className="card__actions--between"> <div className="card__actions--between">
<div className="card__content"> <div className="card__content">
<ChannelSection channel={this.state.channel} onChannelChange={this.handleChannelChange} /> <ChannelSection channel={channelUri} />
</div> </div>
<Button button="primary" type="submit" label={__('Post')} /> <Button button="primary" type="submit" label={__('Post')} />
</div> </div>
</Form>
</section> </section>
); );
} }

View file

@ -76,49 +76,3 @@ class Comment extends React.PureComponent<CommentProps> {
} }
export default CommentList; export default CommentList;
// export default function CommentsList(props) {
// const { uri } = props;
// const { claimId } = parseURI(uri);
//
// // We have local "state" which is a list of comments
// // And we have "setComments" which is a way to update the local state with new comments
// // useState sets that up and says the initial value for "comments" is 'undefined'
// // const [comments, setComments] = useState(undefined);
// //
// //
// // // useEffect is saying, when the properties that are passed in to this function change,
// // // re-run this function, or re-run this "effect" that will update the local state
// // useEffect(() => {
// // Lbry.comment_list({ claim_id: claimId })
// // .then(result => setComments(result))
// // .catch(error => console.error(error));
// // // Lbry.commentsList(claimID)
// // // .then(comments => setComments(comments))
// // // .catch(error => console.error(error))
// // }, [claimId]);
//
// // If there are no comments set yet, just return null
// if (!comments) {
// return null;
// }
//
// // If we have comments, we want to return a piece of UI
// // The same way we would return an array, we can return an "array" of <li> elements with the comment data inside
// return (
// <ul className="navigation__links">
// {comments.comments.map(comment => {
// return (
// <li>
// <Comment
// commentId={comment.comment_id}
// claimId={comment.claim_id}
// author={comment.author}
// message={comment.message}
// timePosted={comment.time_posted}
// />
// </li>
// );
// })}
// </ul>
// );
// }

View file

@ -331,6 +331,7 @@ class PublishForm extends React.PureComponent<Props> {
const shortUri = buildURI({ contentName: name }); const shortUri = buildURI({ contentName: name });
console.log('URI', uri);
return ( return (
<React.Fragment> <React.Fragment>
{IS_WEB && <UnsupportedOnWeb />} {IS_WEB && <UnsupportedOnWeb />}

View file

@ -4,19 +4,23 @@ import {
selectBalance, selectBalance,
selectMyChannelClaims, selectMyChannelClaims,
selectFetchingMyChannels, selectFetchingMyChannels,
selectMyActiveChannelUri,
doFetchChannelListMine, doFetchChannelListMine,
doCreateChannel, doCreateChannel,
doSetMyActiveChannelUri,
} from 'lbry-redux'; } from 'lbry-redux';
const select = state => ({ const select = state => ({
channels: selectMyChannelClaims(state), channels: selectMyChannelClaims(state),
fetchingChannels: selectFetchingMyChannels(state), fetchingChannels: selectFetchingMyChannels(state),
balance: selectBalance(state), balance: selectBalance(state),
activeChannelUri: selectMyActiveChannelUri(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({
createChannel: (name, amount) => dispatch(doCreateChannel(name, amount)), createChannel: (name, amount) => dispatch(doCreateChannel(name, amount)),
fetchChannelListMine: () => dispatch(doFetchChannelListMine()), fetchChannelListMine: () => dispatch(doFetchChannelListMine()),
setMyActiveChannelUri: activeChannelUri => dispatch(doSetMyActiveChannelUri(activeChannelUri)),
}); });
export default connect( export default connect(

View file

@ -7,13 +7,16 @@ import Button from 'component/button';
import { CHANNEL_NEW, CHANNEL_ANONYMOUS } from 'constants/claim'; import { CHANNEL_NEW, CHANNEL_ANONYMOUS } from 'constants/claim';
type Props = { type Props = {
channelUri: string,
channel: string, // currently selected channel channel: string, // currently selected channel
channels: Array<{ name: string }>, channels: Array<{ name: string }>,
balance: number, balance: number,
onChannelChange: string => void, onChannelChange?: string => void,
createChannel: (string, number) => Promise<any>, createChannel: (string, number) => Promise<any>,
fetchChannelListMine: () => void, fetchChannelListMine: () => void,
fetchingChannels: boolean, fetchingChannels: boolean,
activeChannelUri: string,
setMyActiveChannelUri: string => void,
}; };
type State = { type State = {
@ -53,18 +56,27 @@ class ChannelSection extends React.PureComponent<Props, State> {
} }
} }
handleChannelChange(event: SyntheticInputEvent<*>) { onChannelChangeProxy(channelUri) {
const { onChannelChange } = this.props; const { onChannelChange } = this.props;
const { newChannelBid } = this.state; if (onChannelChange) {
const channel = event.target.value; onChannelChange(channelUri);
}
}
if (channel === CHANNEL_NEW) { handleChannelChange(event: SyntheticInputEvent<*>) {
const { setMyActiveChannelUri } = this.props;
const { newChannelBid } = this.state;
const channelUri = event.target.value;
console.log('HCC', channelUri);
if (channelUri === CHANNEL_NEW) {
this.setState({ addingChannel: true }); this.setState({ addingChannel: true });
onChannelChange(channel); this.onChannelChangeProxy(channelUri);
this.handleNewChannelBidChange(newChannelBid); this.handleNewChannelBidChange(newChannelBid);
} else { } else {
this.setState({ addingChannel: false }); this.setState({ addingChannel: false });
onChannelChange(channel); setMyActiveChannelUri(channelUri);
this.onChannelChangeProxy(channelUri);
} }
} }
@ -104,7 +116,7 @@ class ChannelSection extends React.PureComponent<Props, State> {
} }
handleCreateChannelClick() { handleCreateChannelClick() {
const { balance, createChannel, onChannelChange } = this.props; const { balance, createChannel } = this.props;
const { newChannelBid, newChannelName } = this.state; const { newChannelBid, newChannelName } = this.state;
const channelName = `@${newChannelName}`; const channelName = `@${newChannelName}`;
@ -123,8 +135,7 @@ class ChannelSection extends React.PureComponent<Props, State> {
creatingChannel: false, creatingChannel: false,
addingChannel: false, addingChannel: false,
}); });
this.onChannelChangeProxy(channelName);
onChannelChange(channelName);
}; };
const failure = () => { const failure = () => {
@ -138,7 +149,7 @@ class ChannelSection extends React.PureComponent<Props, State> {
} }
render() { render() {
const channel = this.state.addingChannel ? 'new' : this.props.channel; const channelUri = this.state.addingChannel ? 'new' : this.props.channelUri;
const { fetchingChannels, channels = [] } = this.props; const { fetchingChannels, channels = [] } = this.props;
const { const {
newChannelName, newChannelName,
@ -157,10 +168,10 @@ class ChannelSection extends React.PureComponent<Props, State> {
<BusyIndicator message="Updating channels" /> <BusyIndicator message="Updating channels" />
) : ( ) : (
<fieldset-section> <fieldset-section>
<FormField name="channel" type="select" onChange={this.handleChannelChange} value={channel}> <FormField name="channel" type="select" onChange={this.handleChannelChange} value={channelUri}>
<option value={CHANNEL_ANONYMOUS}>{__('Anonymous')}</option> <option value={CHANNEL_ANONYMOUS}>{__('Anonymous')}</option>
{channels.map(({ name }) => ( {channels.map(({ name, permanent_url: channelUri }) => (
<option key={name} value={name}> <option key={name} value={channelUri}>
{name} {name}
</option> </option>
))} ))}

View file

@ -290,7 +290,7 @@ class FilePage extends React.Component<Props> {
<header className="card__header"> <header className="card__header">
<h2 className="card__header">Comments</h2> <h2 className="card__header">Comments</h2>
</header> </header>
<CommentCreate comment={''} uri={uri} /> <CommentCreate uri={uri} />
<CommentsList uri={uri} /> <CommentsList uri={uri} />
</div> </div>
</div> </div>