Skip to content

Commit

Permalink
Merge pull request #609 from leepeuker/fix-movie-more-modal
Browse files Browse the repository at this point in the history
Fix button not correctly dis/enabling like the rest in the movie deta…
  • Loading branch information
leepeuker authored Aug 19, 2024
2 parents 9ec8ff8 + d2c82ef commit 0a764f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
35 changes: 14 additions & 21 deletions public/js/movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,45 +162,35 @@ function loadRatingModal() {
function toggleWatchlist(isOnWatchlist) {
removeAlert('alertMovieOptionModalDiv')

document.getElementById('refreshTmdbDataButton').disabled = true;
document.getElementById('refreshImdbRatingButton').disabled = true;
document.getElementById('watchlistButton').disabled = true;
disableMoreModalButtons();

if (isOnWatchlist == null) {
addToWatchlistRequest().then(() => {
location.reload()
}).catch(() => {
addAlert('alertMovieOptionModalDiv', 'Could not add to Watchlist', 'danger')
document.getElementById('refreshTmdbDataButton').disabled = false;
document.getElementById('refreshImdbRatingButton').disabled = false;
document.getElementById('watchlistButton').disabled = false;
disableMoreModalButtons(false);
})
} else {
removeFromWatchlistRequest().then(() => {
location.reload()
}).catch(() => {
addAlert('alertMovieOptionModalDiv', 'Could not remove from Watchlist', 'danger')
document.getElementById('refreshTmdbDataButton').disabled = false;
document.getElementById('refreshImdbRatingButton').disabled = false;
document.getElementById('watchlistButton').disabled = false;
disableMoreModalButtons(false);
})
}
}

function refreshTmdbData() {
removeAlert('alertMovieOptionModalDiv')

document.getElementById('refreshTmdbDataButton').disabled = true;
document.getElementById('refreshImdbRatingButton').disabled = true;
document.getElementById('watchlistButton').disabled = true;
disableMoreModalButtons();

refreshTmdbDataRequest().then(() => {
location.reload()
}).catch(() => {
addAlert('alertMovieOptionModalDiv', 'Could not refresh tmdb data', 'danger')
document.getElementById('refreshTmdbDataButton').disabled = false;
document.getElementById('refreshImdbRatingButton').disabled = false;
document.getElementById('watchlistButton').disabled = false;
disableMoreModalButtons(false);
})
}

Expand Down Expand Up @@ -234,21 +224,24 @@ async function refreshTmdbDataRequest() {
return true
}

function disableMoreModalButtons(disable = true) {
document.getElementById('whereToWatchModalButton').disabled = disable;
document.getElementById('refreshTmdbDataButton').disabled = disable;
document.getElementById('refreshImdbRatingButton').disabled = disable;
document.getElementById('watchlistButton').disabled = disable;
}

//region refreshImdbRating
function refreshImdbRating() {
removeAlert('alertMovieOptionModalDiv')

document.getElementById('refreshTmdbDataButton').disabled = true;
document.getElementById('refreshImdbRatingButton').disabled = true;
document.getElementById('watchlistButton').disabled = true;
disableMoreModalButtons();

refreshImdbRatingRequest().then(() => {
location.reload()
}).catch(() => {
addAlert('alertMovieOptionModalDiv', 'Could not refresh imdb rating', 'danger')
document.getElementById('refreshTmdbDataButton').disabled = false;
document.getElementById('refreshImdbRatingButton').disabled = false;
document.getElementById('watchlistButton').disabled = false;
disableMoreModalButtons(false);
})
}

Expand Down
2 changes: 1 addition & 1 deletion templates/component/modal-more-options.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</button>
<button type="button"
class="btn btn-primary"
id="watchlistButton"
id="whereToWatchModalButton"
data-bs-target="#whereToWatchModal"
data-bs-toggle="modal"
onclick="showWhereToWatchModal({{ movie.tmdbId }})">
Expand Down

0 comments on commit 0a764f3

Please sign in to comment.