'use strict';

var AppDispatcher = require('../dispatcher/AppDispatcher');
var TracklistConstants = require('../constants/TracklistConstants');
var api = require('../utils/api');

var TracklistActions = {
  fetch: function() {
    api.tracks.get(function(err, tracks) {
      if (err) return console.error(err);
      TracklistActions.set(tracks);
    }.bind(this));
  },
  set: function(tracks) {
    AppDispatcher.handleViewAction({
      actionType: TracklistConstants.TRACKLIST_SET,
      data: tracks
    });
  },
  add: function(track) {
    AppDispatcher.handleViewAction({
      actionType: TracklistConstants.TRACKLIST_ADD,
      data: track
    });
  },
  addUrl: function(trackUrl) {
    console.log(trackUrl)
    api.tracks.post({
      url: trackUrl
    }, function(err) {
      if (err) {
        console.log(err);
        return console.error(err);
      }
    });
  },
  remove: function(index) {
    AppDispatcher.handleViewAction({
      actionType: TracklistConstants.TRACKLIST_REMOVE,
      data: index
    });
  }
};

module.exports = TracklistActions;
@@ -692,33 +692,8 @@
 ) %7B%0A
-    console.log(trackUrl)
 %0A   
@@ -775,33 +775,8 @@
 ) %7B%0A
-        console.log(err);
 %0A   

update tracklist actions