Skip to content

Commit

Permalink
favorite now works
Browse files Browse the repository at this point in the history
  • Loading branch information
duhminick committed Aug 1, 2016
1 parent b3b4e40 commit fe7f144
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 17 additions & 1 deletion js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<tr>'
html += '<td>' + checkBox + '></td>'
html += '<td><span class="favorite ' + favorite + '" /></td>'
html += '<td><span class="favorite ' + favorite + '" id="favoriteBtn" data-pokemon-id="' + poke['id'] + '" data-pokemon-favorited="' + favoriteBool + '" /></td>'
html += '<td>' + poke['pokemon_id'] + '</td>'
html += '<td>' + poke['name'] + '</td>'
html += '<td class="nickname" data-toggle="modal" data-target="#bulbasaurModal">' + poke['nickname'] + '</td>'
Expand All @@ -110,6 +111,8 @@ function sortPokemonList (sorting, refresh) {
html += '</tr>'
pokemonList.innerHTML += html
})

addFavoriteButtonEvent()
}

function runningCheck () {
Expand Down Expand Up @@ -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()
})
})
}

0 comments on commit fe7f144

Please sign in to comment.