-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mikołaj Burdzy <[email protected]>
- Loading branch information
Showing
8 changed files
with
205 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,51 @@ | ||
import generic_user from '../resources/icons8-male-user-50.png' | ||
import '../App.scss' | ||
import { Link } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
import { login, logout } from './actions'; | ||
|
||
function User({isLoggedIn}) { | ||
if (isLoggedIn) { | ||
return ( | ||
<a href="account.html"> | ||
<img src={generic_user} alt="user=icon"/> | ||
</a> | ||
) | ||
} | ||
else { | ||
return ( | ||
<div className="login"> | ||
<div className="col-6"> | ||
<a href="login.html"><button className="btn">Login</button></a> | ||
</div> | ||
<div className="col-6"> | ||
<a href="register.html"><button class="btn">Register</button></a> | ||
</div> | ||
</div> | ||
) | ||
} | ||
} | ||
function User({ isAuthenticated, user, login, logout }) { | ||
return ( | ||
<div> | ||
{isAuthenticated ? ( | ||
<button onClick={logout}>Logout</button> | ||
) : ( | ||
<button onClick={() => login({ username: 'exampleUser' })}> | ||
Login | ||
</button> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default User | ||
// function User({isLoggedIn}) { | ||
// if (isLoggedIn) { | ||
// return ( | ||
// <Link to="account.html"> | ||
// <img src={generic_user} alt="user=icon"/> | ||
// </Link> | ||
// ) | ||
// } | ||
// else { | ||
// return ( | ||
// <div className="login"> | ||
// <div className="col-6"> | ||
// <Link to="login.html"><button className="btn">Login</button></Link> | ||
// </div> | ||
// <div className="col-6"> | ||
// <Link to="register.html"><button class="btn">Register</button></Link> | ||
// </div> | ||
// </div> | ||
// ) | ||
// } | ||
// } | ||
|
||
|
||
const mapStateToProps = (state) => ({ | ||
isAuthenticated: state.isAuthenticated, | ||
user: state.user, | ||
}); | ||
|
||
const mapDispatchToProps = {login,logout,}; | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(User); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// actions.js | ||
export const login = (user) => ({ | ||
type: 'LOGIN', | ||
payload: user, | ||
}); | ||
|
||
export const logout = () => ({ | ||
type: 'LOGOUT', | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// store.js | ||
import { createStore } from 'redux'; | ||
|
||
const initialState = { | ||
isAuthenticated: false, | ||
user: null, | ||
}; | ||
|
||
const authReducer = (state = initialState, action) => { | ||
switch (action.type) { | ||
case 'LOGIN': | ||
return { | ||
...state, | ||
isAuthenticated: true, | ||
user: action.payload, | ||
}; | ||
case 'LOGOUT': | ||
return { | ||
...state, | ||
isAuthenticated: false, | ||
user: null, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
const store = createStore(authReducer); | ||
|
||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters