import React from 'react'; import { getUserCookies, clearUserCookies } from 'utils/cookies'; const VIEW = 'VIEW'; const LOGOUT = 'LOGOUT'; function Logo () { return ( Logo Spee.ch logo Spee<h ); } class NavBar extends React.Component { constructor (props) { super(props); this.checkForLoggedInUser = this.checkForLoggedInUser.bind(this); this.handleSelection = this.handleSelection.bind(this); } componentDidMount () { 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}`); if (channelName) { this.props.onChannelLogin(channelName, channelShortId, channelLongId); } } handleSelection (event) { const value = event.target.selectedOptions[0].value; switch (value) { case LOGOUT: // remove session cookies clearUserCookies(); // send logout request to server window.location.href = '/logout'; break; case VIEW: // redirect to channel page window.location.href = `/${this.props.channelName}:${this.props.channelLongId}`; break; default: break; } } render () { return (
Open-source, decentralized image and video sharing.
Publish About { this.props.channelName ? ( ) : ( Channel )}
); } } export default NavBar;