-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68eab86
commit b1f5bae
Showing
9 changed files
with
225 additions
and
250 deletions.
There are no files selected for viewing
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
32 changes: 20 additions & 12 deletions
32
src/components/RightIconButton.js → ...components/AuthWrapper/RightIconButton.js
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, { PureComponent } from "react"; | ||
import propTypes from "prop-types"; | ||
import AppBar from "material-ui/AppBar"; | ||
import { Grid, Row } from "react-flexbox-grid"; | ||
import FirebaseManager from "../../utils/FirebaseManager"; | ||
import RightIconButton from "./RightIconButton"; | ||
import IconButton from "material-ui/IconButton"; | ||
import Sidebar from "../utils/Sidebar"; | ||
|
||
class AuthWrapper extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
sidebar: false | ||
}; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
const { auth, match } = this.props; | ||
const isAuth = auth.get("isAuth"); | ||
const nextAuth = nextProps.auth.get("isAuth"); | ||
|
||
if (nextAuth !== isAuth && isAuth === false) { | ||
this.props.goTo("/"); | ||
} | ||
} | ||
componentDidMount() { | ||
const { auth, match } = this.props; | ||
const isAuth = auth.get("isAuth"); | ||
if (isAuth === false) { | ||
this.props.goTo("/"); | ||
} | ||
} | ||
render() { | ||
const { auth } = this.props; | ||
|
||
return ( | ||
<Grid fluid> | ||
<AppBar | ||
title="訂便當" | ||
onLeftIconButtonClick={() => { | ||
if (FirebaseManager.user) { | ||
this.setState({ sidebar: true }); | ||
} | ||
}} | ||
iconElementLeft={ | ||
<IconButton | ||
tooltipPosition="bottom-left" | ||
iconClassName="fa fa-bars" | ||
/> | ||
} | ||
iconElementRight={ | ||
<RightIconButton | ||
logout={this.logout} | ||
setLoginModal={() => this.setState({ LoginModal: true })} | ||
isAuth={auth.get("isAuth")} | ||
LOGON={auth.get("LOGON")} | ||
user={auth.get("user")} | ||
/> | ||
} | ||
/> | ||
<Row>{this.props.children}</Row> | ||
<Sidebar | ||
openSidebar={() => this.setState({ sidebar: false })} | ||
isOpen={this.state.sidebar} | ||
/> | ||
</Grid> | ||
); | ||
} | ||
} | ||
|
||
export default AuthWrapper; |
Oops, something went wrong.