import * as events from '../../services/events';
import NewWorkoutScreen from './new-workout-screen';
import React, { Component } from 'react';
import Screen from './screen';
import WorkoutSummary from '../components/workout-summary';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Icon, Spinner, DeckSwiper } from 'native-base';
import { Platform, View, Image } from 'react-native';
export default class DashboardScreen extends Screen {
constructor(props) {
super(props)
this.state = {
eventsOfInterest: [events.FETCHED_WORKOUTS],
workouts: [],
};
}
componentDidMount() {
super.componentDidMount();
this.onLoadHistory();
}
render() {
let content = this.state.isLoading ? : this.renderWorkouts(this.state.workouts);
let gravatarUri = this.gravatarUri();
return (
{content}
);
}
renderWorkouts(workouts) {
let renderEach = (workout) => ;
if (Platform.OS == 'ios') {
return (
);
} else {
return (
{workouts.map(renderEach)}
);
}
}
onLoadHistory() {
this.setState({isLoading: true})
this.publish({event: events.FETCH_WORKOUTS});
}
notify(event) {
switch(event.event) {
case events.FETCHED_WORKOUTS:
this.setState({
isLoading: false,
workouts: event.workouts
});
}
}
onStartWorkout() {
console.log("start workout");
this.loadScreen(NewWorkoutScreen)
}
onLogout() {
this.publish({event: events.LOGOUT})
this.props.navigator.pop();
}
gravatarUri() {
const secureHost = "https://secure.gravatar.com/avatar";
return `${secureHost}/${this.props.gravatar_id}?s=32&d=mm`;
}
}