import React from 'react' import ModalDialog from './ModalDialog.jsx' import client from '../client' export default class LoggedOutView extends React.Component { constructor() { super() this.state = { modal: null } this.showLogin = this.showLogin.bind(this) this.showSignup = this.showSignup.bind(this) this.closeModal = this.closeModal.bind(this) } showLogin() { this.setState({ modal: 'login' }) } showSignup() { this.setState({ modal: 'signup' }) } closeModal() { this.setState({ modal: '' }) } render() { const loginVisible = this.state.modal == 'login' const signupVisible = this.state.modal == 'signup' return (
) } } class Welcome extends React.Component { render() { return (

Calorie Counter

) } } class LoginForm extends React.Component { constructor() { super() this.state = { email: '', password: '', error: null, } this.updateState = this.updateState.bind(this) this.handleSubmit = this.handleSubmit.bind(this) } updateState(event){ const name = event.target.name const value = event.target.value this.setState({ [name]: value, error: null, }) } handleSubmit(event) { event.preventDefault() client.authenticate({ type: 'local', email: this.state.email, password: this.state.password, }).then(res => { console.log('Authenticated!', res); window.location.reload() }).catch(error => { console.error('Error authenticating!', error); this.setState({ error: error.toString() }) }) } render() { return (


{this.state.error}
) } } class SignupForm extends React.Component { constructor() { super() this.state = { email: '', password: '', goal: 0, error: null, } this.updateState = this.updateState.bind(this) this.handleSubmit = this.handleSubmit.bind(this) } updateState(event){ const name = event.target.name const value = event.target.value this.setState({ [name]: value, error: null, }) } handleSubmit(event) { event.preventDefault() const usersService = client.service('users') usersService.create(this.state).then(result => { console.log(result) return client.authenticate({ type: 'local', email: this.state.email, password: this.state.password, }) }).then(res => { console.log('Authenticated!', res) window.location.reload() }).catch(error => { console.error('Error authenticating!', error) this.setState({ error: error.toString() }) }) } render() { return (



{this.state.error}
) } }