<commit_before>import data from 'app/data/data';
import handlebars from 'bower_components/handlebars/handlebars';

var sammyApp = Sammy('#content', function () {

  this.get('#/', function () {
    console.log('----HOME');
  });

  this.get('#/books', function () {
    var params = {
      author: this.params.author,
      genre: this.params.genre
    };

    data.books.get(params)
      .then(function (books) {
        var $container = $('<div />');
        $.get('app/partials/book-id-partial.html', function (templateString) {
          var template = handlebars.compile(templateString);
          books.map(template)
            .forEach(function (bookhtml) {
              $container.append(bookhtml);
            });
          $('#content').html($container.html());
        });
      });
  });



  this.get('#/books/add', function (context) {
    //context === this

    this.load('app/partials/book-add-partial.html')
      .swap();

    var $button = $('#content')
      .on('click', '#add-book', function () {
        var genres = [];
        $('.tb-genre').each(function (index, genre) {
          var value = $(genre).val();
          if (value) {
            genres.push(value);
          }
        });
        data.books.save({
            title: $('#tb-title').val(),
            author: $('#tb-author').val(),
            genres: genres,
            description: $('#tb-description').val(),
            pages: $('#tb-pages').val()

          })
          .then(function (book) {
            context.redirect('#/books/' + book._id);
          });
      });

  });<commit_msg>Fixed adding book bug<commit_after>import data from 'app/data/data';
import handlebars from 'bower_components/handlebars/handlebars';

var sammyApp = Sammy('#content', function () {

  this.get('#/', function () {
    console.log('----HOME');
  });

  this.get('#/books', function () {
    var params = {
      author: this.params.author,
      genre: this.params.genre
    };

    data.books.get(params)
      .then(function (books) {
        var $container = $('<div />');
        $.get('app/partials/book-id-partial.html', function (templateString) {
          var template = handlebars.compile(templateString);
          books.map(template)
            .forEach(function (bookhtml) {
              $container.append(bookhtml);
            });
          $('#content').html($container.html());
        });
      });
  });



  this.get('#/books/add', function (context) {
    //context === this

    $.get('app/partials/book-add-partial.html', function (html) {
      // body...
      $('#content').html(html);

      var $button = $('#add-book')
        .on('click', function () {
          var genres = [];
          $('.tb-genre').each(function (index, genre) {
            var value = $(genre).val();
            if (value) {
              genres.push(value);
            }
          });
          data.books.save({
              title: $('#tb-title').val(),
              author: $('#tb-author').val(),
              genres: genres,
              description: $('#tb-description').val(),
              pages: $('#tb-pages').val()

            })
            .then(function (book) {
              context.redirect('#/books/' + book._id);
            });
        });
    });
  });
{'fraction_non_alphanumeric': 0.1939615736505032, 'fraction_numerical': 0.0, 'mean_word_length': 1.844752818733738, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1021992', 'n_tokens_mistral': 952, 'n_tokens_neox': 933, 'n_words': 163}