Browse Source

Add warning for taken username when signing up, Fix scroll on post preview, Add progress-bar in profile view

develop
Apostolos Fanakis 7 years ago
parent
commit
6d0553b83a
  1. 2
      src/components/NavBar.js
  2. 19
      src/components/NewPost.js
  3. 6
      src/components/Post.js
  4. 11
      src/containers/ProfileContainer.js
  5. 50
      src/containers/UsernameFormContainer.js

2
src/components/NavBar.js

@ -35,7 +35,7 @@ class NavBar extends Component {
? <Menu.Item onClick={() => {this.handleItemClick("/profile")}}> ? <Menu.Item onClick={() => {this.handleItemClick("/profile")}}>
Profile Profile
</Menu.Item> </Menu.Item>
:<Menu.Menu position='right'> :<Menu.Menu position='right' style={{backgroundColor: '#00b5ad'}}>
<Menu.Item onClick={() => {this.handleItemClick("/signup")}}> <Menu.Item onClick={() => {this.handleItemClick("/signup")}}>
Sign Up Sign Up
</Menu.Item> </Menu.Item>

19
src/components/NewPost.js

@ -104,20 +104,22 @@ class NewPost extends Component {
</strong></span> </strong></span>
</div> </div>
<div className="post-content"> <div className="post-content">
<Form className="topic-form"> <div style={{display: this.state.previewEnabled ? "block" : "none"}}>
{this.state.previewEnabled <ReactMarkdown source={this.state.postContentInput}
? <ReactMarkdown source={this.state.postContentInput}
className="markdown-preview" /> className="markdown-preview" />
: [ </div>
<Form className="topic-form">
<Form.Input key={"postSubjectInput"} <Form.Input key={"postSubjectInput"}
style={{display: this.state.previewEnabled ? "none" : ""}}
name={"postSubjectInput"} name={"postSubjectInput"}
error={this.state.postSubjectInputEmptySubmit} error={this.state.postSubjectInputEmptySubmit}
type="text" type="text"
value={this.state.postSubjectInput} value={this.state.postSubjectInput}
placeholder="Subject" placeholder="Subject"
id="postSubjectInput" id="postSubjectInput"
onChange={this.handleInputChange} />, onChange={this.handleInputChange} />
<TextArea key={"postContentInput"} <TextArea key={"postContentInput"}
style={{display: this.state.previewEnabled ? "none" : ""}}
name={"postContentInput"} name={"postContentInput"}
className={this.state.postContentInputEmptySubmit ? "form-textarea-required" : ""} className={this.state.postContentInputEmptySubmit ? "form-textarea-required" : ""}
value={this.state.postContentInput} value={this.state.postContentInput}
@ -125,7 +127,6 @@ class NewPost extends Component {
id="postContentInput" id="postContentInput"
onChange={this.handleInputChange} onChange={this.handleInputChange}
rows={4} autoHeight /> rows={4} autoHeight />
]}
<br/><br/> <br/><br/>
<Button.Group> <Button.Group>
<Button key="submit" <Button key="submit"
@ -159,12 +160,6 @@ class NewPost extends Component {
); );
} }
componentDidUpdate(prevProps, prevState){
if (!this.state.previewEnabled && prevState.previewEnabled){
this.newPostOuterRef.current.scrollIntoView(true);
}
}
componentDidMount(){ componentDidMount(){
this.newPostOuterRef.current.scrollIntoView(true); this.newPostOuterRef.current.scrollIntoView(true);
} }

6
src/components/Post.js

@ -125,9 +125,11 @@ class Post extends Component {
<Icon name='chevron down' /> <Icon name='chevron down' />
</Button> </Button>
<Button icon size='mini' <Button icon size='mini'
onClick={() => { this.context.router.push("/topic/" onClick={this.props.blockchainData[0].returnData
? () => { this.context.router.push("/topic/"
+ this.props.blockchainData[0].returnData[4] + "/" + this.props.blockchainData[0].returnData[4] + "/"
+ this.props.postID)}}> + this.props.postID)}
: () => {}}>
<Icon name='linkify' /> <Icon name='linkify' />
</Button> </Button>
</Grid.Column> </Grid.Column>

11
src/containers/ProfileContainer.js

@ -9,12 +9,18 @@ import ProfileInformation from '../components/ProfileInformation';
import TopicList from '../components/TopicList'; import TopicList from '../components/TopicList';
import PostList from '../components/PostList'; import PostList from '../components/PostList';
import LoadingSpinner from '../components/LoadingSpinner'; import LoadingSpinner from '../components/LoadingSpinner';
import { setNavBarTitle } from '../redux/actions/userInterfaceActions'; import {
showProgressBar,
hideProgressBar,
setNavBarTitle
} from '../redux/actions/userInterfaceActions';
class Profile extends Component { class Profile extends Component {
constructor(props, context) { constructor(props, context) {
super(props); super(props);
this.props.store.dispatch(showProgressBar());
this.propsToView = this.propsToView.bind(this); this.propsToView = this.propsToView.bind(this);
this.drizzle = context.drizzle; this.drizzle = context.drizzle;
@ -126,6 +132,9 @@ class Profile extends Component {
componentDidUpdate(){ componentDidUpdate(){
if (this.username){ if (this.username){
this.props.store.dispatch(setNavBarTitle(this.username)); this.props.store.dispatch(setNavBarTitle(this.username));
if (this.topicIDs && this.postIDs){
this.props.store.dispatch(hideProgressBar());
}
} }
} }
} }

50
src/containers/UsernameFormContainer.js

@ -8,6 +8,7 @@ import { createDatabases } from './../util/orbit';
import { updateUsername } from '../redux/actions/transactionsMonitorActions'; import { updateUsername } from '../redux/actions/transactionsMonitorActions';
const contract = "Forum"; const contract = "Forum";
const checkUsernameTakenMethod = "isUserNameTaken";
const signUpMethod = "signUp"; const signUpMethod = "signUp";
class UsernameFormContainer extends Component { class UsernameFormContainer extends Component {
@ -18,11 +19,14 @@ class UsernameFormContainer extends Component {
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
this.completeAction = this.completeAction.bind(this); this.completeAction = this.completeAction.bind(this);
this.contracts = context.drizzle.contracts; this.drizzle = context.drizzle;
this.contracts = this.drizzle.contracts;
this.state = { this.state = {
usernameInput: '', usernameInput: '',
error: false, error: false,
errorHeader: "",
errorMessage: "",
signingUp: false signingUp: false
}; };
} }
@ -33,9 +37,18 @@ class UsernameFormContainer extends Component {
handleSubmit() { handleSubmit() {
if (this.state.usernameInput === ''){ if (this.state.usernameInput === ''){
this.setState({ error: true }); this.setState({
error: true,
errorHeader: "Data Incomplete",
errorMessage: "You need to provide a username"
});
} else { } else {
this.completeAction(); this.checkUsernameTakenDataKey = this.contracts[contract].methods[checkUsernameTakenMethod]
.cacheCall(this.state.usernameInput);
this.setState({
error: false
});
this.checkingUsernameTaken = true;
} }
} }
@ -63,6 +76,28 @@ class UsernameFormContainer extends Component {
} }
} }
componentWillUpdate() {
if (this.checkingUsernameTaken){
let dataFetched = this.drizzle.store.getState()
.contracts[contract][checkUsernameTakenMethod][this.checkUsernameTakenDataKey];
if (dataFetched){
this.checkingUsernameTaken = false;
if (dataFetched.value){
this.setState({
error: true,
errorHeader: "Data disapproved",
errorMessage: "This username is already taken"
});
} else {
this.setState({
error: false
});
this.completeAction();
}
}
}
}
render() { render() {
const hasSignedUp = this.props.user.hasSignedUp; const hasSignedUp = this.props.user.hasSignedUp;
@ -85,14 +120,14 @@ class UsernameFormContainer extends Component {
</Form.Field> </Form.Field>
<Message <Message
error error
header='Data Incomplete' header={this.state.errorHeader}
content='You need to provide a username to sign up for an account.' content={this.state.errorMessage}
/> />
<Button type='submit'>{buttonText}</Button> <Button type='submit'>{buttonText}</Button>
</Form> </Form>
<Dimmer active={this.state.signingUp} page> <Dimmer active={this.state.signingUp || this.checkingUsernameTaken} page>
<Header as='h2' inverted> <Header as='h2' inverted>
<Loader size='large'>Magic elves are processing your noble request.</Loader> <Loader size='large'>Magic elfs are processing your nobel request.</Loader>
</Header> </Header>
</Dimmer> </Dimmer>
</div> </div>
@ -109,7 +144,6 @@ UsernameFormContainer.contextTypes = {
const mapStateToProps = state => { const mapStateToProps = state => {
return { return {
contracts: state.contracts,
user: state.user user: state.user
} }
}; };

Loading…
Cancel
Save