-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converted App.js from class based component to functional component #158
Open
arunmishra2000
wants to merge
2
commits into
jmprathab:master
Choose a base branch
from
arunmishra2000:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
import { Switch, Route, Redirect } from "react-router-dom"; | ||
import { connect } from "react-redux"; | ||
|
||
|
@@ -17,12 +17,15 @@ import HousePage from "./pages/house/house.component"; | |
import UserPage from "./pages/users/users.component"; | ||
import NavigationBar from "./components/navigation-bar/NavigationBar"; | ||
import Sidebar from "./components/sidebar/Sidebar"; | ||
import NotFoundPage from './pages/not-found/not-found.component'; | ||
import NotFoundPage from "./pages/not-found/not-found.component"; | ||
|
||
import { setCurrentUser } from "./redux/user/user.actions"; | ||
import SignIn from "./pages/sign-in-and-sign-up/SignIn"; | ||
import SignUp from "./pages/sign-in-and-sign-up/SignUp"; | ||
import { CSSTransition, TransitionGroup as ReactTransitionGroup } from "react-transition-group"; | ||
import { | ||
CSSTransition, | ||
TransitionGroup as ReactTransitionGroup, | ||
} from "react-transition-group"; | ||
import HomepageLoggedIn from "./pages/homepage/HomepageLoggedIn"; | ||
|
||
const MainContainer = styled.div` | ||
|
@@ -61,37 +64,27 @@ const Transition = styled(CSSTransition)` | |
} | ||
|
||
&.page-fade-enter.page-fade-enter-active { | ||
opacity: 1; | ||
transition: opacity 300ms ease-in; | ||
opacity: 1; | ||
transition: opacity 300ms ease-in; | ||
} | ||
|
||
&.page-fade-exit { | ||
display: none; | ||
display: none; | ||
} | ||
`; | ||
|
||
class App extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
const App = (props) => { | ||
const [overlay, setOverlay] = useState(false); | ||
|
||
this.loadUserInfo(); | ||
|
||
this.onMenuToggle = this.onMenuToggle.bind(this); | ||
|
||
this.state = { | ||
overlay: false, | ||
}; | ||
} | ||
|
||
loadUserInfo() { | ||
const loadUserInfo = () => { | ||
// Get user details from localStorage and save to react store | ||
try { | ||
var info = localStorage.getItem("userInfo"); | ||
let info = localStorage.getItem("userInfo"); | ||
if (info) { | ||
let userInfo = JSON.parse(info); | ||
console.log("Loaded UserId from storage : " + userInfo.userId); | ||
console.log("Loaded token from storage : " + userInfo.token); | ||
this.props.setCurrentUser({ | ||
props.setCurrentUser({ | ||
userId: userInfo.userId, | ||
token: userInfo.token, | ||
}); | ||
|
@@ -101,59 +94,100 @@ class App extends React.Component { | |
} catch { | ||
console.log("Cannot find info from localStorage"); | ||
} | ||
} | ||
|
||
onMenuToggle() { | ||
const overlay = this.state.overlay; | ||
this.setState({ | ||
overlay: !overlay, | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<MainContainer> | ||
<NavigationBar onMenuToggle={this.onMenuToggle} menuToggled={this.state.overlay} /> | ||
<PageContainer> | ||
<Sidebar overlay={this.state.overlay} /> | ||
{this.state.overlay && <Overlay onClick={this.onMenuToggle} />} | ||
<Page> | ||
<Route render={({ location }) => { | ||
return <TransitionGroup> | ||
<Transition | ||
key={location.key} | ||
timeout={300} | ||
classNames="page-fade" | ||
> | ||
<div> | ||
<Switch location={location}> | ||
<Route exact path="/" component={this.props.currentUser ? HomepageLoggedIn : HomePage} /> | ||
|
||
<Route exact path="/signin" component={() => <Redirect to="/login" />} /> | ||
<Route exact path="/login" component={() => <SignInAndSignUpPage inputBox={<SignIn />} />} /> | ||
<Route exact path="/signup" component={() => <SignInAndSignUpPage inputBox={<SignUp />} />} /> | ||
|
||
<Route exact path="/communities" component={CommunitiesPage} /> | ||
<Route exact path="/community/new" component={CreateCommunityPage} /> | ||
<Route exact path="/community/:uuid" component={CommunityPage} /> | ||
|
||
<Route exact path="/user/:uuid" component={UserPage} /> | ||
<Route exact path="/house/:uuid" component={HousePage} /> | ||
|
||
<Route path="*" component={NotFoundPage} /> | ||
</Switch> | ||
</div> | ||
</Transition> | ||
</TransitionGroup> | ||
}} /> | ||
</Page> | ||
</PageContainer> | ||
</MainContainer> | ||
</div> | ||
); | ||
} | ||
} | ||
}; | ||
loadUserInfo(); | ||
const onMenuToggle = () => { | ||
setOverlay(!overlay); | ||
}; | ||
Comment on lines
+99
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change this to |
||
|
||
return ( | ||
<div> | ||
<MainContainer> | ||
<NavigationBar onMenuToggle={onMenuToggle} menuToggled={overlay} /> | ||
<PageContainer> | ||
<Sidebar overlay={overlay} /> | ||
{overlay && <Overlay onClick={onMenuToggle} />} | ||
<Page> | ||
<Route | ||
render={({ location }) => { | ||
return ( | ||
<TransitionGroup> | ||
<Transition | ||
key={location.key} | ||
timeout={300} | ||
className="page-fade" | ||
> | ||
<div> | ||
<Switch location={location}> | ||
<Route | ||
exact | ||
path="/" | ||
component={ | ||
props.currentUser ? HomepageLoggedIn : HomePage | ||
} | ||
/> | ||
|
||
<Route | ||
exact | ||
path="/signin" | ||
component={() => <Redirect to="/login" />} | ||
/> | ||
<Route | ||
exact | ||
path="/login" | ||
component={() => ( | ||
<SignInAndSignUpPage inputBox={<SignIn />} /> | ||
)} | ||
/> | ||
<Route | ||
exact | ||
path="/signup" | ||
component={() => ( | ||
<SignInAndSignUpPage inputBox={<SignUp />} /> | ||
)} | ||
/> | ||
|
||
<Route | ||
exact | ||
path="/communities" | ||
component={CommunitiesPage} | ||
/> | ||
<Route | ||
exact | ||
path="/community/new" | ||
component={CreateCommunityPage} | ||
/> | ||
<Route | ||
exact | ||
path="/community/:uuid" | ||
component={CommunityPage} | ||
/> | ||
|
||
<Route | ||
exact | ||
path="/user/:uuid" | ||
component={UserPage} | ||
/> | ||
<Route | ||
exact | ||
path="/house/:uuid" | ||
component={HousePage} | ||
/> | ||
|
||
<Route path="*" component={NotFoundPage} /> | ||
</Switch> | ||
</div> | ||
</Transition> | ||
</TransitionGroup> | ||
); | ||
}} | ||
/> | ||
</Page> | ||
</PageContainer> | ||
</MainContainer> | ||
</div> | ||
); | ||
}; | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
setCurrentUser: (user) => dispatch(setCurrentUser(user)), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be better if we just destructure the user info and use it to set the current user . use const instead of var or let
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.