/**
 *
 * @flow
 */
'use strict';

import React from 'react';
import TaskListView from './TaskListView';
import type {Task} from '../../reducers/tasks';
import ENV from '../../common/Environment';

export default class TaskListContainer extends React.Component {
    state: {
        tasks: Array<Task>
    };

    constructor() {
        super();
        this.state = {
            tasks: []
        };
    }

    async getAllTasks(): Promise {
        try {
            let response = await fetch(ENV.__API_BRIDGE+'/tasks');
            let responseJSON = await response.json();
            return responseJSON.data;
        } catch (err) {
            console.error("getAllTasks() -> Error: ", err);
        }
    }

    componentWillMount() {
        let testRows = () => {
            let arr = [];
            let flip = false;
            for (let i = 0; i < 20; i++) {
                arr.push({
                    id: `${i}`,
                    title: `Task ${i}`,
                    desc: `desc for task ${i}`,
                    reward: '200',
                    complete: '3/5',
                    status: flip ? 'To Do' : 'Completed',
                    address: "asdasdadasdas"
                });
                flip = !flip;
            }
            return arr;
        };
        let tr: Array<Task> = testRows();
        this.setState({tasks: tr});
    }

    componentDidMount() {
        this.getAllTasks().then(tasks => {
            this.setState({tasks: tasks});
        });
    }

    render() {
        return (
            <TaskListView navigator={this.props.navigator} tasks={this.state.tasks} />
        );
    }
}

@@ -400,24 +400,112 @@
   %7D;%0A    %7D%0A%0A
+    setTasks(tasks: Array%3CTask%3E) %7B%0A        return this.setState(%7Btasks: tasks%7D);%0A    %7D%0A%0A
     async ge
@@ -805,661 +805,150 @@
  %7D%0A%0A
+%0A
     
-componentWillMount() %7B%0A        let testRows = () =%3E %7B%0A            let arr = %5B%5D;%0A            let flip = false;%0A            for (let i = 0; i %3C 20; i++) %7B%0A                arr.push(%7B%0A                    id: %60$%7Bi%7D%60,%0A                    title: %60Task $%7Bi%7D%60,%0A                    desc: %60desc for task $%7Bi%7D%60,%0A                    reward: '200',%0A                    complete: '3/5',%0A                    status: flip ? 'To Do' : 'Completed',%0A                    address: %22asdasdadasdas%22%0A                %7D);%0A                flip = !flip;%0A            %7D%0A            return arr;%0A        %7D;%0A        let tr: Array%3CTask%3E = testRows();%0A        this.setState(%7Btasks: tr%7D
+async onRefresh(): Promise %7B%0A        console.log(%22Refreshing TaskList...%22);%0A        this.getAllTasks().then(tasks =%3E this.setTasks(tasks)
 );%0A 
@@ -1024,62 +1024,28 @@
  =%3E 
-%7B%0A            this.setState(%7Bt
+this.setT
 asks
-: 
+(
 tasks
-%7D);%0A        %7D
+)
 );%0A 
@@ -1111,66 +1111,164 @@
 View
- navigator=%7Bthis.props.navigator%7D tasks=%7Bthis.state.tasks%7D
+%0A                tasks=%7Bthis.state.tasks%7D%0A                navigator=%7Bthis.props.navigator%7D%0A                onRefresh=%7Bthis.onRefresh.bind(this)%7D%0A           
  /%3E%0A

Remove test row generator. Adds `onRefresh` & `setTasks` methods.