Browse Source

Add separate route for SignUpContainer, Redirect / to /home, Add guest capabilities

develop
Apostolos Fanakis 7 years ago
parent
commit
d0207739db
  1. 14
      src/assets/css/App.css
  2. 7
      src/assets/css/navbar.css
  3. 2
      src/assets/css/start-topic-container.css
  4. 1
      src/components/FloatingButton.js
  5. 2
      src/components/NavBar.js
  6. 9
      src/components/NewPost.js
  7. 2
      src/components/NewTopicPreview.js
  8. 2
      src/components/NotFoundView.js
  9. 1
      src/components/Topic.js
  10. 33
      src/containers/BoardContainer.js
  11. 22
      src/containers/HomeContainer.js
  12. 14
      src/containers/LoadingContainer.js
  13. 25
      src/containers/PrivateRouteContainer.js
  14. 9
      src/containers/ProfileContainer.js
  15. 15
      src/containers/SignUpContainer.js
  16. 8
      src/containers/StartTopicContainer.js
  17. 2
      src/containers/TopicContainer.js
  18. 10
      src/containers/UsernameFormContainer.js
  19. 18
      src/index.js
  20. 1
      src/layouts/CoreLayout/CoreLayout.js

14
src/assets/css/App.css

@ -41,6 +41,7 @@ strong {
top: 0; top: 0;
left: 0; left: 0;
} }
.main-panel { .main-panel {
width: 60%; width: 60%;
height: 100%; height: 100%;
@ -105,10 +106,6 @@ strong {
margin: 0px; margin: 0px;
} }
.margin-left-small {
margin-left: 7px;
}
hr { hr {
color: #0c1a2b; color: #0c1a2b;
margin: 0px; margin: 0px;
@ -118,10 +115,6 @@ hr {
outline:none !important outline:none !important
} }
.centerDiv {
margin: 0 auto;
}
a { a {
color:inherit; color:inherit;
text-decoration: none; text-decoration: none;
@ -175,11 +168,6 @@ a {
height: 100%; height: 100%;
} }
.full-width {
max-width: 100% !important;
width: 100% !important;
}
.vis { /* For UX developing */ .vis { /* For UX developing */
border: 1px solid red; border: 1px solid red;
} }

7
src/assets/css/navbar.css

@ -1,7 +0,0 @@
/* NAVBAR */
.nav-link:hover {
background: rgba(255,255,255,.08) !important;
color: #fff !important;
cursor: pointer !important;
}

2
src/assets/css/start-topic-container.css

@ -5,6 +5,6 @@
margin: 20px 0px; margin: 20px 0px;
} }
.markdownPreview { .markdown-preview {
padding: 0px 20px; padding: 0px 20px;
} }

1
src/components/FloatingButton.js

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import { Link } from 'react-router';
import { Button, Icon } from 'semantic-ui-react' import { Button, Icon } from 'semantic-ui-react'
const FloatingButton = (props) => { const FloatingButton = (props) => {

2
src/components/NavBar.js

@ -36,7 +36,7 @@ class NavBar extends Component {
Profile Profile
</Menu.Item> </Menu.Item>
:<Menu.Menu position='right'> :<Menu.Menu position='right'>
<Menu.Item onClick={() => {this.handleItemClick("/signUp")}}> <Menu.Item onClick={() => {this.handleItemClick("/signup")}}>
Sign Up Sign Up
</Menu.Item> </Menu.Item>
</Menu.Menu> </Menu.Menu>

9
src/components/NewPost.js

@ -132,7 +132,7 @@ class NewPost extends Component {
<Form className="topic-form"> <Form className="topic-form">
{this.state.previewEnabled {this.state.previewEnabled
? <ReactMarkdown source={this.state.postContentInput} ? <ReactMarkdown source={this.state.postContentInput}
className="markdownPreview" /> className="markdown-preview" />
: [ : [
<Form.Input key={"postSubjectInput"} <Form.Input key={"postSubjectInput"}
name={"postSubjectInput"} name={"postSubjectInput"}
@ -154,7 +154,6 @@ class NewPost extends Component {
<br/><br/> <br/><br/>
<Button.Group> <Button.Group>
<Button key="submit" <Button key="submit"
className="btn waves-effect waves-teal white black-text"
type="button" type="button"
onClick={this.validateAndPost} onClick={this.validateAndPost}
color='teal' color='teal'
@ -164,14 +163,12 @@ class NewPost extends Component {
<Icon name='reply' /> <Icon name='reply' />
</Button.Content> </Button.Content>
</Button> </Button>
<Button className="waves-effect waves-orange btn white black-text margin-left-small" <Button type="button"
type="button"
onClick={this.handlePreviewToggle} onClick={this.handlePreviewToggle}
color='yellow'> color='yellow'>
{this.state.previewEnabled ? "Edit" : "Preview"} {this.state.previewEnabled ? "Edit" : "Preview"}
</Button> </Button>
<Button className="btn red margin-left-small" <Button type="button"
type="button"
onClick={this.props.onCancelClick} onClick={this.props.onCancelClick}
color='red'> color='red'>
Cancel Cancel

2
src/components/NewTopicPreview.js

@ -1,7 +1,7 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { drizzleConnect } from 'drizzle-react'; import { drizzleConnect } from 'drizzle-react';
import { Grid, Divider, Button, Icon, Label } from 'semantic-ui-react' import { Grid, Divider } from 'semantic-ui-react'
import TimeAgo from 'react-timeago'; import TimeAgo from 'react-timeago';
import UserAvatar from 'react-user-avatar'; import UserAvatar from 'react-user-avatar';

2
src/components/NotFoundView.js

@ -2,7 +2,7 @@ import React from 'react';
const NotFoundView = (props) => { const NotFoundView = (props) => {
return ( return (
<div className="center"> <div style={{textAlign: "center"}}>
<img src={require('../resources/PageNotFound.jpg')} alt="Page not found!"/> <img src={require('../resources/PageNotFound.jpg')} alt="Page not found!"/>
</div> </div>
); );

1
src/components/Topic.js

@ -1,5 +1,4 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Link } from 'react-router';
import { drizzleConnect } from 'drizzle-react'; import { drizzleConnect } from 'drizzle-react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';

33
src/containers/BoardContainer.js

@ -1,7 +1,9 @@
import { drizzleConnect } from 'drizzle-react';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { drizzleConnect } from 'drizzle-react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Header } from 'semantic-ui-react';
import WithBlockchainData from '../components/WithBlockchainData'; import WithBlockchainData from '../components/WithBlockchainData';
import TopicList from '../components/TopicList'; import TopicList from '../components/TopicList';
import FloatingButton from '../components/FloatingButton'; import FloatingButton from '../components/FloatingButton';
@ -24,16 +26,43 @@ class Board extends Component {
boardContents = ( boardContents = (
<LoadingSpinner/> <LoadingSpinner/>
); );
} else { } else if (this.props.blockchainData[0].returnData !== '0'){
this.topicIDs = []; this.topicIDs = [];
for (var i = 0; i < this.props.blockchainData[0].returnData; i++) { for (var i = 0; i < this.props.blockchainData[0].returnData; i++) {
this.topicIDs.push(i); this.topicIDs.push(i);
} }
boardContents = ([ boardContents = ([
<TopicList topicIDs={this.topicIDs} key="topicList"/>, <TopicList topicIDs={this.topicIDs} key="topicList"/>,
this.props.user.hasSignedUp &&
<FloatingButton onClick={this.handleCreateTopicClick} <FloatingButton onClick={this.handleCreateTopicClick}
key="createTopicButton"/> key="createTopicButton"/>
]); ]);
} else {
if (!this.props.user.hasSignedUp){
boardContents = (
<div className="vertical-center-in-parent">
<Header color='teal' textAlign='center' as='h2'>
There are no topics yet!
</Header>
<Header color='teal' textAlign='center' as='h4'>
Sign up to be the first post.
</Header>
</div>
);
} else {
boardContents = (
<div className="vertical-center-in-parent">
<Header color='teal' textAlign='center' as='h2'>
There are no topics yet!
</Header>
<Header color='teal' textAlign='center' as='h4'>
Click the add button at the bottom of the page to be the first to post.
</Header>
<FloatingButton onClick={this.handleCreateTopicClick}
key="createTopicButton"/>
</div>
);
}
} }
return ( return (

22
src/containers/HomeContainer.js

@ -1,16 +1,26 @@
import { drizzleConnect } from 'drizzle-react'; import { drizzleConnect } from 'drizzle-react';
import React, { Component } from 'react'; import React, { Component } from 'react';
import SignUpContainer from './SignUpContainer';
import BoardContainer from './BoardContainer'; import BoardContainer from './BoardContainer';
class Home extends Component { class Home extends Component {
render() { render() {
//This must change to routes and redirects //We can add a modal to tell the user to sign up
const view = this.props.user.hasSignedUp
? (<BoardContainer/>) //This may become multiple boards /*var modal = this.props.user.hasSignedUp && (
: (<SignUpContainer/>); <Modal dimmer='blurring' open={this.state.open}>
<Modal.Header>Select a Photo</Modal.Header>
<Modal.Content image>
<Image wrapped size='medium' src='/assets/images/avatar/large/rachel.png' />
<Modal.Description>
<Header>Default Profile Image</Header>
<p>We've found the following gravatar image associated with your e-mail address.</p>
<p>Is it okay to use this photo?</p>
</Modal.Description>
</Modal.Content>
</Modal>);*/
return (view); return (<BoardContainer/>);
} }
} }

14
src/containers/LoadingContainer.js

@ -1,13 +1,9 @@
import { drizzleConnect } from 'drizzle-react' import { drizzleConnect } from 'drizzle-react';
import React, { Children, Component } from 'react' import React, { Children, Component } from 'react';
import PropTypes from 'prop-types' import PropTypes from 'prop-types';
import ipfs_logo from './../resources/ipfs_logo.png'; import ipfs_logo from './../resources/ipfs_logo.png';
/*
* Create component.
*/
class LoadingContainer extends Component { class LoadingContainer extends Component {
render() { render() {
if (this.props.web3.status === 'failed') if (this.props.web3.status === 'failed')
@ -80,10 +76,6 @@ LoadingContainer.contextTypes = {
drizzle: PropTypes.object drizzle: PropTypes.object
}; };
/*
* Export connected component.
*/
const mapStateToProps = state => { const mapStateToProps = state => {
return { return {
accounts: state.accounts, accounts: state.accounts,

25
src/containers/PrivateRouteContainer.js

@ -1,25 +0,0 @@
import React from 'react';
import { drizzleConnect } from 'drizzle-react';
import { Route } from "react-router";
import { Redirect } from "react-router-dom";
const PrivateRoute = (props) => {
return (
props.user.hasSignedUp
? <Route path={props.path} component={props.component} />
: <Redirect
from={props.path}
to="/login"
/>
);
};
const mapStateToProps = state => {
return {
user: state.user
}
};
const PrivateRouteContainer = drizzleConnect(PrivateRoute, mapStateToProps);
export default PrivateRouteContainer;

9
src/containers/ProfileContainer.js

@ -1,6 +1,5 @@
import { drizzleConnect } from 'drizzle-react'; import { drizzleConnect } from 'drizzle-react';
import React, { Component } from 'react'; import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Tab } from 'semantic-ui-react' import { Tab } from 'semantic-ui-react'
@ -25,6 +24,11 @@ class Profile extends Component {
} }
render() { render() {
if (!this.props.user.hasSignedUp) {
this.context.router.push("/signup");
return(null);
}
this.propsToView(); this.propsToView();
var infoTab = var infoTab =
(<WithBlockchainData (<WithBlockchainData
@ -116,7 +120,8 @@ class Profile extends Component {
} }
Profile.contextTypes = { Profile.contextTypes = {
drizzle: PropTypes.object drizzle: PropTypes.object,
router: PropTypes.object
}; };
const mapStateToProps = state => { const mapStateToProps = state => {

15
src/containers/SignUpContainer.js

@ -2,10 +2,21 @@ import { drizzleConnect } from 'drizzle-react';
import React, { Component } from 'react'; import React, { Component } from 'react';
import UsernameFormContainer from './UsernameFormContainer'; import UsernameFormContainer from './UsernameFormContainer';
import { Header } from 'semantic-ui-react';
class SignUp extends Component { class SignUp extends Component {
render() { render() {
return ( return (
<div className="sign-up-container"> this.props.user.hasSignedUp
?(<div className="vertical-center-in-parent">
<Header color='teal' textAlign='center' as='h2'>
There is already an account for this addresss.
</Header>
<Header color='teal' textAlign='center' as='h4'>
If you want to create another account please change your address.
</Header>
</div>)
:(<div className="sign-up-container">
<div> <div>
<h1>Sign Up</h1> <h1>Sign Up</h1>
<p className="no-margin"> <p className="no-margin">
@ -13,7 +24,7 @@ class SignUp extends Component {
</p> </p>
<UsernameFormContainer/> <UsernameFormContainer/>
</div> </div>
</div> </div>)
); );
} }
} }

8
src/containers/StartTopicContainer.js

@ -89,6 +89,11 @@ class StartTopic extends Component {
} }
render() { render() {
if (!this.props.user.hasSignedUp) {
this.context.router.push("/signup");
return(null);
}
var previewEditText = this.state.previewEnabled ? "Edit" : "Preview"; var previewEditText = this.state.previewEnabled ? "Edit" : "Preview";
return ( return (
<div> <div>
@ -296,7 +301,8 @@ class StartTopic extends Component {
} }
StartTopic.contextTypes = { StartTopic.contextTypes = {
drizzle: PropTypes.object drizzle: PropTypes.object,
router: PropTypes.object
}; };
const mapStateToProps = state => { const mapStateToProps = state => {

2
src/containers/TopicContainer.js

@ -75,7 +75,7 @@ class Topic extends Component {
onPostCreated={() => {this.postCreated()}} onPostCreated={() => {this.postCreated()}}
/> />
} }
{!this.state.posting && {this.props.user.hasSignedUp && !this.state.posting &&
<FloatingButton onClick={this.handleClick}/> <FloatingButton onClick={this.handleClick}/>
} }
</div>) </div>)

10
src/containers/UsernameFormContainer.js

@ -1,9 +1,9 @@
import React, { Component } from 'react' import React, { Component } from 'react';
import { drizzleConnect } from 'drizzle-react' import { drizzleConnect } from 'drizzle-react';
import PropTypes from 'prop-types' import PropTypes from 'prop-types';
import { Button, Message, Form, Dimmer, Loader, Header } from 'semantic-ui-react' import { Button, Message, Form, Dimmer, Loader, Header } from 'semantic-ui-react';
import { createDatabases } from './../util/orbit' import { createDatabases } from './../util/orbit';
const contract = "Forum"; const contract = "Forum";
const signUpMethod = "signUp"; const signUpMethod = "signUp";

18
src/index.js

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { render } from 'react-dom'; import { render } from 'react-dom';
import { Router, IndexRoute, browserHistory } from 'react-router'; import { Router, IndexRedirect, browserHistory } from 'react-router';
import { Route } from 'react-router-dom'; import { Route } from 'react-router-dom';
import { syncHistoryWithStore } from 'react-router-redux'; import { syncHistoryWithStore } from 'react-router-redux';
import { DrizzleProvider } from 'drizzle-react'; import { DrizzleProvider } from 'drizzle-react';
@ -10,8 +10,7 @@ import CoreLayout from './layouts/CoreLayout/CoreLayout';
// Containers // Containers
import LoadingContainer from './containers/LoadingContainer'; import LoadingContainer from './containers/LoadingContainer';
import PrivateRouteContainer from './containers/PrivateRouteContainer'; import SignUpContainer from './containers/SignUpContainer';
import HomeContainer from './containers/HomeContainer'; import HomeContainer from './containers/HomeContainer';
import TopicContainer from './containers/TopicContainer'; import TopicContainer from './containers/TopicContainer';
import StartTopicContainer from './containers/StartTopicContainer'; import StartTopicContainer from './containers/StartTopicContainer';
@ -31,7 +30,11 @@ render((
<LoadingContainer> <LoadingContainer>
<Router history={history}> <Router history={history}>
<Route path="/" component={CoreLayout}> <Route path="/" component={CoreLayout}>
<IndexRoute component={HomeContainer} /> <IndexRedirect to="/home" />
<Route path="/home"
component={HomeContainer} />
<Route path="/signup"
component={SignUpContainer} />
<Route path="/topic/:topicId(/:postId)" <Route path="/topic/:topicId(/:postId)"
component={TopicContainer} /> component={TopicContainer} />
<Route path='/profile(/:address)(/:username)' <Route path='/profile(/:address)(/:username)'
@ -47,10 +50,3 @@ render((
), ),
document.getElementById('root') document.getElementById('root')
); );
/*<PrivateRouteContainer path="/topic/:topicId(/:topicSubject)(/:postId)"
component={TopicContainer} />
<PrivateRouteContainer path='/profile(/:address)(/:username)'
component={ProfileContainer} />
<PrivateRouteContainer path='/startTopic'
component={StartTopicContainer} />*/

1
src/layouts/CoreLayout/CoreLayout.js

@ -6,7 +6,6 @@ import '../../assets/fonts/fontawesome-free-5.0.13/fontawesome-all.js';
import '../../assets/css/App.css'; import '../../assets/css/App.css';
import '../../assets/css/loading-container.css'; import '../../assets/css/loading-container.css';
import '../../assets/css/sign-up-container.css'; import '../../assets/css/sign-up-container.css';
import '../../assets/css/navbar.css';
import '../../assets/css/board-container.css'; import '../../assets/css/board-container.css';
import '../../assets/css/start-topic-container.css'; import '../../assets/css/start-topic-container.css';

Loading…
Cancel
Save