diff --git a/README.md b/README.md index 7409f71..91b73d1 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This is my first project using [Electron](http://electron.atom.io/) and [Node.js * IV * Transfer Pokemon * Evolve Pokemon -* Favorite Pokemon +* Favorite/Unfavorite Pokemon ## Development git clone https://github.com/duhminick/PokeNurse @@ -25,7 +25,6 @@ This is my first project using [Electron](http://electron.atom.io/) and [Node.js This project follows the [JS Standard Code Style](http://standardjs.com/index.html) for the most part. ## Todo -* Favorite/unfavorite Pokemon * Evolve Pokemon with x amount of times * Show Pokemon moveset * Nickname Pokemon diff --git a/js/home.js b/js/home.js index 8d624ec..4d72b10 100644 --- a/js/home.js +++ b/js/home.js @@ -98,10 +98,11 @@ function sortPokemonList (sorting, refresh) { if (poke['deployed']) checkBox += ' disabled' if (poke['favorite']) favorite = 'glyphicon glyphicon-star favorite-yellow' + var favoriteBool = poke['favorite'] ? 'true' : 'false' var html = '' html += '' + checkBox + '>' - html += '' + html += '' html += '' + poke['pokemon_id'] + '' html += '' + poke['name'] + '' html += '' + poke['nickname'] + '' @@ -110,6 +111,8 @@ function sortPokemonList (sorting, refresh) { html += '' pokemonList.innerHTML += html }) + + addFavoriteButtonEvent() } function runningCheck () { @@ -158,3 +161,16 @@ function sortBy (props) { return doSort(a, b, 0) } } + +function addFavoriteButtonEvent () { + var buttons = document.querySelectorAll('#favoriteBtn') + buttons.forEach((button) => { + button.addEventListener('click', (event) => { + var setToFavorite = button.dataset.pokemonFavorited === 'false' + ipc.send('favorite-pokemon', button.dataset.pokemonId, setToFavorite) + var newClass = setToFavorite ? 'favorite glyphicon glyphicon-star favorite-yellow' : 'favorite glyphicon glyphicon-star-empty' + button.className = newClass + button.dataset.pokemonFavorited = setToFavorite.toString() + }) + }) +}