2018-01-18 19:58:34 +01:00
|
|
|
import React from 'react';
|
2018-01-18 21:43:02 +01:00
|
|
|
import { getUserCookies, clearUserCookies } from 'utils/cookies';
|
2018-01-18 19:58:34 +01:00
|
|
|
|
|
|
|
const VIEW = 'VIEW';
|
|
|
|
const LOGOUT = 'LOGOUT';
|
|
|
|
|
2018-01-18 21:43:02 +01:00
|
|
|
function Logo () {
|
|
|
|
return (
|
|
|
|
<svg version="1.1" id="Layer_1" x="0px" y="0px" height="24px" viewBox="0 0 80 31" enableBackground="new 0 0 80 31" className="nav-bar-logo">
|
|
|
|
<a href="/">
|
|
|
|
<title>Logo</title>
|
|
|
|
<desc>Spee.ch logo</desc>
|
|
|
|
<g id="About">
|
|
|
|
<g id="Publish-Form-V2-_x28_filled_x29_" transform="translate(-42.000000, -23.000000)">
|
|
|
|
<g id="Group-17" transform="translate(42.000000, 22.000000)">
|
|
|
|
<text transform="matrix(1 0 0 1 0 20)" fontSize="25" fontFamily="Roboto">Spee<h</text>
|
|
|
|
<g id="Group-16" transform="translate(0.000000, 30.000000)">
|
|
|
|
<path id="Line-8" fill="none" stroke="#09F911" strokeWidth="1" strokeLinecap="square" d="M0.5,1.5h15"/>
|
|
|
|
<path id="Line-8-Copy" fill="none" stroke="#029D74" strokeWidth="1" strokeLinecap="square" d="M16.5,1.5h15"/>
|
|
|
|
<path id="Line-8-Copy-2" fill="none" stroke="#E35BD8" strokeWidth="1" strokeLinecap="square" d="M32.5,1.5h15"/>
|
|
|
|
<path id="Line-8-Copy-3" fill="none" stroke="#4156C5" strokeWidth="1" strokeLinecap="square" d="M48.5,1.5h15"/>
|
|
|
|
<path id="Line-8-Copy-4" fill="none" stroke="#635688" strokeWidth="1" strokeLinecap="square" d="M64.5,1.5h15"/>
|
|
|
|
</g>
|
|
|
|
</g>
|
|
|
|
</g>
|
|
|
|
</g>
|
|
|
|
</a>
|
|
|
|
</svg>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-18 19:58:34 +01:00
|
|
|
class NavBar extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
2018-01-18 21:43:02 +01:00
|
|
|
this.checkForLoggedInUser = this.checkForLoggedInUser.bind(this);
|
2018-01-18 19:58:34 +01:00
|
|
|
this.handleSelection = this.handleSelection.bind(this);
|
|
|
|
}
|
|
|
|
componentDidMount () {
|
2018-01-18 21:43:02 +01:00
|
|
|
this.checkForLoggedInUser();
|
|
|
|
}
|
|
|
|
checkForLoggedInUser () {
|
|
|
|
// check for whether a channel is already logged in
|
|
|
|
let channelName, channelShortId, channelLongId;
|
|
|
|
({ channelName, channelShortId, channelLongId } = getUserCookies());
|
|
|
|
console.log(`cookies found for channel: ${channelName} ${channelShortId} ${channelLongId}`);
|
2018-01-19 19:16:55 +01:00
|
|
|
if (channelName) {
|
|
|
|
this.props.onChannelLogin(channelName, channelShortId, channelLongId);
|
|
|
|
}
|
2018-01-18 19:58:34 +01:00
|
|
|
}
|
|
|
|
handleSelection (event) {
|
|
|
|
const value = event.target.selectedOptions[0].value;
|
|
|
|
switch (value) {
|
2018-01-18 21:43:02 +01:00
|
|
|
case LOGOUT:
|
|
|
|
// remove session cookies
|
|
|
|
clearUserCookies();
|
|
|
|
// send logout request to server
|
|
|
|
window.location.href = '/logout';
|
2018-01-18 19:58:34 +01:00
|
|
|
break;
|
2018-01-18 21:43:02 +01:00
|
|
|
case VIEW:
|
|
|
|
// redirect to channel page
|
|
|
|
window.location.href = `/${this.props.channelName}:${this.props.channelLongId}`;
|
2018-01-18 19:58:34 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div className="row row--wide nav-bar">
|
|
|
|
<div className="row row--padded row--short flex-container--row flex-container--space-between-center">
|
2018-01-18 21:43:02 +01:00
|
|
|
<Logo />
|
2018-01-18 19:58:34 +01:00
|
|
|
<div className="nav-bar--center">
|
|
|
|
<span className="nav-bar-tagline">Open-source, decentralized image and video sharing.</span>
|
|
|
|
</div>
|
|
|
|
<div className="nav-bar--right">
|
|
|
|
<a className="nav-bar-link link--nav" href="/">Publish</a>
|
|
|
|
<a className="nav-bar-link link--nav" href="/about">About</a>
|
2018-01-18 21:43:02 +01:00
|
|
|
{ this.props.channelName ? (
|
|
|
|
<select type="text" id="nav-bar-channel-select" className="select select--arrow link--nav" onChange={this.handleSelection}>
|
|
|
|
<option id="nav-bar-channel-select-channel-option">{this.props.channelName}</option>
|
2018-01-18 19:58:34 +01:00
|
|
|
<option value={VIEW}>View</option>
|
|
|
|
<option value={LOGOUT}>Logout</option>
|
|
|
|
</select>
|
|
|
|
) : (
|
|
|
|
<a id="nav-bar-login-link" className="nav-bar-link link--nav" href="/login">Channel</a>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default NavBar;
|