import React from 'react'; import { Link } from 'react-router-dom'; import { browserHistory, Redirect } from 'react-router'; import { Session, Admin } from '../model/'; import { Container, Loader, Icon, NgIf } from '../components/'; import { memory, currentShare } from '../helpers/'; import '../pages/error.scss'; export function LoggedInOnly(WrappedComponent){ memory.set('user::authenticated', false); return class extends React.Component { constructor(props){ super(props); this.state = { is_logged_in: memory.get('user::authenticated') }; } componentDidMount(){ if(this.state.is_logged_in === false && currentShare() === null){ Session.currentUser().then((res) => { if(res.is_authenticated === false){ this.props.error({message: "Authentication Required"}); return; } memory.set('user::authenticated', true); this.setState({is_logged_in: true}); }).catch((err) => { if(err.code === "NO_INTERNET"){ this.setState({is_logged_in: true}); return; } this.props.error(err); }); } } render(){ if(this.state.is_logged_in === true || currentShare() !== null){ return ; } return null; } }; } export function ErrorPage(WrappedComponent){ return class extends React.Component { constructor(props){ super(props); this.state = { error: null, has_back_button: false }; this.unlisten = this.props.history.listen((location, action) => { this.setState({has_back_button: false}); this.unlisten(); }); } componentWillUnmount(){ if(this.unlisten) this.unlisten(); } update(obj){ this.setState({error: obj}); } navigate(e) { if(this.state.has_back_button){ e.preventDefault(); this.props.history.goBack(); } } render(){ if(this.state.error !== null){ const message = this.state.error.message || "There is nothing in here"; return (
{ this.state.has_back_button ? "back" : "home" }

Oops!

{message}

); } return ( ); } }; } export const LoadingPage = (props) => { return (
); };