1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 09:50:31 +01:00
onion/js/components/header.js

97 lines
3.0 KiB
JavaScript
Raw Normal View History

'use strict';
2015-05-20 16:19:40 +02:00
import React from 'react';
2015-06-11 15:57:19 +02:00
import Router from 'react-router';
2015-05-21 15:14:05 +02:00
2015-05-20 16:19:40 +02:00
import UserActions from '../actions/user_actions';
import UserStore from '../stores/user_store';
2015-06-15 12:36:27 +02:00
import apiUrls from '../constants/api_urls.js';
2015-06-16 20:35:19 +02:00
//import PieceListActions from '../actions/piece_list_actions';
import requests from '../utils/requests';
2015-06-15 11:02:49 +02:00
import Nav from 'react-bootstrap/lib/Nav';
import Navbar from 'react-bootstrap/lib/Navbar';
2015-06-15 12:36:27 +02:00
import NavItem from 'react-bootstrap/lib/NavItem';
import DropdownButton from 'react-bootstrap/lib/DropdownButton';
import MenuItem from 'react-bootstrap/lib/MenuItem';
2015-06-17 17:48:23 +02:00
import MenuItemLink from 'react-router-bootstrap/lib/MenuItemLink';
2015-06-15 15:28:53 +02:00
import LoginModal from '../components/ascribe_modal/modal_login';
import SignupModal from '../components/ascribe_modal/modal_signup';
2015-06-11 15:35:18 +02:00
import { getLangText } from '../utils/lang_utils';
2015-06-11 15:57:19 +02:00
let Link = Router.Link;
2015-05-20 16:19:40 +02:00
let Header = React.createClass({
2015-06-16 20:35:19 +02:00
//mixins: [Router.Navigation],
2015-05-20 16:19:40 +02:00
getInitialState() {
return UserStore.getState();
},
componentDidMount() {
UserActions.fetchCurrentUser();
2015-06-05 11:40:49 +02:00
UserStore.listen(this.onChange);
2015-06-03 11:49:39 +02:00
},
componentWillUnmount() {
2015-06-04 13:16:19 +02:00
UserStore.unlisten(this.onChange);
2015-05-20 16:19:40 +02:00
},
2015-06-16 20:35:19 +02:00
handleLogout(){
requests
.get(apiUrls.users_logout)
.then(this.refreshData);
},
2015-05-20 16:19:40 +02:00
onChange(state) {
this.setState(state);
},
2015-06-15 15:28:53 +02:00
refreshData(){
2015-06-16 14:01:53 +02:00
location.reload();
2015-06-11 15:35:18 +02:00
},
2015-05-20 16:19:40 +02:00
render() {
2015-06-15 15:28:53 +02:00
let account = null;
let signup = null;
2015-06-15 12:36:27 +02:00
if (this.state.currentUser.username){
account = (
<DropdownButton eventKey="1" title={this.state.currentUser.username}>
2015-06-17 17:48:23 +02:00
<MenuItemLink to="settings">{getLangText('Account Settings')}</MenuItemLink>
2015-06-15 12:36:27 +02:00
<li className="divider"></li>
<MenuItem eventKey="2" href="/art/faq/">{getLangText('FAQ')}</MenuItem>
<MenuItem eventKey="3" href="/art/terms/">{getLangText('Terms of Service')}</MenuItem>
<MenuItem divider />
2015-06-16 20:35:19 +02:00
<MenuItem eventKey="4" href="#" onClick={this.handleLogout}>{getLangText('Log out')}</MenuItem>
2015-06-15 12:36:27 +02:00
</DropdownButton>
);
}
2015-06-15 15:28:53 +02:00
else {
account = (
<LoginModal
button={<NavItem to="pieces">LOGIN</NavItem>}
handleSuccess={this.refreshData}/>);
signup = (
<SignupModal
button={<NavItem to="pieces">SIGNUP</NavItem>} />);
}
2015-05-20 16:19:40 +02:00
return (
<Navbar>
<Nav>
<Link className="navbar-brand" to="pieces" path="/?page=1">
<span>ascribe </span>
<span className="glyph-ascribe-spool-chunked ascribe-color"></span>
2015-06-09 16:10:25 +02:00
</Link>
</Nav>
<Nav right>
2015-06-15 12:36:27 +02:00
{account}
2015-06-15 15:28:53 +02:00
{signup}
</Nav>
</Navbar>
2015-05-21 15:20:02 +02:00
);
2015-05-20 16:19:40 +02:00
}
});
export default Header;