-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from kirkchen/implement_login_feature
Implement login feature
- Loading branch information
Showing
8 changed files
with
363 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
var React = require('react/addons'); | ||
var $ = require('jquery'); | ||
|
||
var Nav = React.createClass({ | ||
getInitialState: function () { | ||
return { | ||
hideMenu: true, | ||
isLogin: false, | ||
user: null | ||
} | ||
}, | ||
componentDidMount: function () { | ||
var self = this; | ||
$.get('/api/login/getStatus') | ||
.then(function (result) { | ||
self.setState({ | ||
isLogin: result.isLogin, | ||
user: result.user | ||
}); | ||
}); | ||
}, | ||
handleToggleMenu: function () { | ||
this.setState({ | ||
hideMenu: !this.state.hideMenu | ||
}) | ||
}, | ||
render: function () { | ||
var cx = React.addons.classSet; | ||
var logoClass = cx({ | ||
'nav-logo': true, | ||
'hide': !this.state.hideMenu | ||
}); | ||
var menuClass = cx({ | ||
'nav-menu': true, | ||
'hide': this.state.hideMenu | ||
}); | ||
|
||
return ( | ||
<nav className="nav"> | ||
<div className={ logoClass } | ||
onClick={ this.handleToggleMenu }> | ||
<h1>K</h1> | ||
</div> | ||
<div className={ menuClass } | ||
onMouseLeave={ this.handleToggleMenu }> | ||
<ul className="nav-menu-list"> | ||
<li className="nav-menu-item"> | ||
<a title="回首頁" href="/"> | ||
<i className="icon icons-keanux">K</i> | ||
<span className="nav-menu-title"> | ||
首頁 | ||
</span> | ||
</a> | ||
</li> | ||
{this.state.isLogin ? | ||
<li className="nav-menu-item"> | ||
<a title="到個人頁面" href="#"> | ||
<i className="icon icons-avatar"> | ||
<img src={ this.state.user.photo }/> | ||
</i> | ||
<span className="nav-menu-title"> | ||
{ this.state.user.nickname } | ||
</span> | ||
</a> | ||
</li> : | ||
<li className="nav-menu-item"> | ||
<a title="Login" href="api/login/facebook"> | ||
<span className="nav-menu-title"> | ||
Facebook Login | ||
</span> | ||
</a> | ||
</li> | ||
} | ||
</ul> | ||
</div> | ||
</nav> | ||
); | ||
} | ||
}) | ||
; | ||
|
||
module.exports = Nav; |
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
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
Oops, something went wrong.