Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.App {
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}

.App-title {
font-size: 1.5em;
}

.App-intro {
font-size: large;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
31 changes: 31 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import {In} from './components/sign-in/sign-in';
import Up from './components/sign-up/sign-up';
import User from './components/user/user';
import ReactDOM from 'react-dom';
import {
Link,
BrowserRouter,
Route,
Switch,
withRouter,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like you don't use it, so we make remove it


} from "react-router-dom";

class App extends Component {
render() {

return (
<div>

<Route path = "/home" component={In}/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add , and exact prop to each Route could be more safer decision

<Route path = "/sign-up" component={Up}/>
<Route path = "/user" component={User}/>
</div>
);
}
}

export default App;
9 changes: 9 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
6 changes: 6 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const incrementCounter = (payload) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need an increment counter?

return {
type: 'INCREMENT',
payload,
};
};
31 changes: 31 additions & 0 deletions src/components/sign-in/sign-in.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
#first {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's always better to use classNames over id. Using ids is a pitfall for bugs

height: 100px;
width: 100%;
border: 4px solid black;
}
#signIn {
float: right;
margin: 20px;
padding: 20px;
}
#logo {
float: right;
margin: 20px;
padding: 20px;
}
#up {
width: 50%;
border: 4px solid black;
margin-top: 100px;
padding: 20px;
}
#signUp {
float: right;
margin: 20px;
padding: 20px;
}
132 changes: 132 additions & 0 deletions src/components/sign-in/sign-in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import React, {Component} from 'react';
import {
Link,
BrowserRouter,
Route,
Switch,
withRouter,
browserHistory
} from "react-router-dom";
import {connect} from 'react-redux';
import './sign-in.css'
import {incrementCounter} from '../../actions';


let url3 = 'https://flatearth-api.herokuapp.com/api/v1/auth/login'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url3 is bad name, it could be something like

const authURL = ...

but from architecture point of view it's still no good to give component knowledge about URL, fetching resources, headers, etc. It should be another file, store in folder service with file auth-api

and auth-api should have something like this

// auth-api.js
const URLprefix = 'https://flatearth-api.herokuapp.com/api/v1/auth/'

const authAPI = {
 login(user) {
  const {
   user,
   password
  } = user;
  const loginURL = `${urlPrefix}/login`;

  return fetch(loginURL, {}).then(data => data.json()) // with required headers, meta information, etc  
 }
}

So you just importing such file and you component working with single method.
That knowledge about splitting application for different layers makes huge different from "common" developer and good developer

let url = 'https://flatearth-api.herokuapp.com/api/v1/auth/secret/'

var user1 = {
user:"",
password:""
}


class Inn extends Component{
state = {
userS: '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you have usersS it's pretty weird.

It adds 1 more "layer" to understanding your code.

When I say "1 more layer". I mean - I have to understand what is behind of such suffix, what do you thinking about when add such suffix...

I think we need to remove it

passwordS: '',
status: []
};

inputChangeUser = (event)=> {
this.setState({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's much easier to handle multiple inputs via such pattern
https://reactjs.org/docs/forms.html#handling-multiple-inputs

please update it

userS: event.target.value,
});
}
inputChangePassword = (event)=> {
this.setState({
passwordS: event.target.value,
});
}
addToUser =()=>{
const {emailS,userS,passwordS} = this.state;

user1.user = userS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand you made it just for optimization and mutation the same object. It does not really make any big impact on final app performance, but it makes code much harder to understand.

In production apps in having an additional class for creating such an object, because of it easier to understand "mental model of application"

user1.password = passwordS
fetch( url3 , {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(user1)
}).then(user => {
return user.json()
}).then(status => {
this.setState({status})

fetch( url , {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${status.message.token}`
},

}).then(user => {
return user.json()
}).then(secret => {
this.setState({secret})
const {incrementCounter}=this.props;
//incrementCounter(status.message.token)
incrementCounter( secret.message)
});

});

}

render(){
const {userS,passwordS,status} = this.state;


return(
<div>
<div id="first">
<center>
<div id="signUp"><Link to ='/sign-up' exact>Sign-Up</Link></div>
<div id="logo"><img src="" alt="logo" /></div>
</center>
</div>
<center>
<div id="second">
<center>
<h3>well come flat earch</h3>
<hr />

<b>Username <input type="text"
value={userS}
onChange={this.inputChangeUser}
/></b><br />
<b>Password <input type="text"
value={passwordS}
onChange={this.inputChangePassword}
/></b>
<div id="sigIn">
<Link to ='/user' exact><button onClick={this.addToUser}>Войти</button></Link>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exact attribute(prop) at Link component is wrong place it's do nothing

<p><input type="checkbox" />запомнить</p>
</div>

</center>
</div>
</center>
</div>
)
}
}


const mapStateToProps = (state) => {
console.log(state)
return {
counter: state.counter,
redux: 'is a power'
};
};

const mapDispatchToProps = {
incrementCounter,

};

export const In = connect(mapStateToProps, mapDispatchToProps)(Inn);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name "In" - not really saying a lot about that component.
It must be renamed



31 changes: 31 additions & 0 deletions src/components/sign-up/sign-up.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
#second {
width: 50%;
border: 4px solid black;
margin-top: 100px;
}
#signIn {
float: right;
margin: 20px;
padding: 20px;
}
#logo {
float: right;
margin: 20px;
padding: 20px;
}
#up {
width: 50%;
border: 4px solid black;
margin-top: 100px;
padding: 20px;
}
#signUp {
float: right;
margin: 20px;
padding: 20px;
}
104 changes: 104 additions & 0 deletions src/components/sign-up/sign-up.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, {Component} from 'react';
import {
Link,
BrowserRouter,
Route,
Switch,
withRouter,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove blank line

} from "react-router-dom";
import './sign-up.css'

var user1 = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to use var there no real scenarios where you need it. var - is outdated way to define variable in JavaScript

email:"",
user:"",
password:""
}
let url2 = 'https://flatearth-api.herokuapp.com/api/v1/auth/signup'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same about placing the URL link and API service/layer

class Up extends Component{
constructor(props){
super(props);
this.state = {
emailS: '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same question why do you need 's' suffix at the end

userS: '',
passwordS: '',
};
}


inputChangeEmail = (event)=> {
this.setState({
emailS: event.target.value,
});
}
inputChangeUser = (event)=> {
this.setState({
userS: event.target.value,
});
}
inputChangePassword = (event)=> {
this.setState({
passwordS: event.target.value,
});
}

addToUser =()=>{
const {emailS,userS,passwordS} = this.state;

user1.email = emailS
user1.user = userS
user1.password = passwordS
fetch( url2 , {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(user1)
}).then(user => {
return user.json()
}).then(us => {
console.log(us);
});
console.log(user1);
}




render(){
const {emailS,userS,passwordS} = this.state;


return(
<div>
<div id="first">
<center>
<div id="signIn"><Link to ='/home' exact>Sign-In</Link></div>
<div id="logo"><img src alt="logo" /></div>
</center>
</div>
<center>
<div id="up">
<b>email</b><br />
<input type="text"
value={emailS}
onChange={this.inputChangeEmail}
/><br />
<b>name</b><br />
<input type="text"
value={userS}
onChange={this.inputChangeUser}
/><br />
<b>password</b><br />
<input type="text"
value={passwordS}
onChange={this.inputChangePassword}
/><br />
<button onClick={this.addToUser}>зарегистрировать</button>
</div>
</center>
</div>
)
}
}
export default Up;
Loading