Skip to content

Commit 9d349a6

Browse files
committed
Update: Add context referencing for chatbot (#196)
1 parent 93649c5 commit 9d349a6

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

index.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ function setupPagination(mainElementId, paginationContainerId, genresContainerId
148148
if (data.total_pages) {
149149
if (data.total_pages > 250) {
150150
totalPages = 250;
151-
} else {
151+
}
152+
else {
152153
totalPages = data.total_pages;
153154
}
154155
}
@@ -299,10 +300,10 @@ document.addEventListener('DOMContentLoaded', async () => {
299300

300301
if (!mostVisitedMovieGenre || !mostCommonGenre) {
301302
recommendedMain.innerHTML = `<div style="display: flex; justify-content: center; align-items: center; height: 100%;">
302-
<p style="text-align: center; font-size: 20px;">
303-
Start exploring and rating movies or add them to your favorites to get personalized recommendations.
304-
</p>
305-
</div>`;
303+
<p style="text-align: center; font-size: 20px;">
304+
Start exploring and rating movies or add them to your favorites to get personalized recommendations.
305+
</p>
306+
</div>`;
306307
return;
307308
}
308309

@@ -379,15 +380,14 @@ document.addEventListener('DOMContentLoaded', async () => {
379380

380381
async function getMovies(url, mainElement, page = 1) {
381382
showSpinner();
382-
url += `&page=${page}`;
383383

384+
url += `&page=${page}`;
384385
const numberOfMovies = calculateMoviesToDisplay();
385386
let allMovies = [];
386387
const response = await fetch(url);
387388
const data = await response.json();
388-
allMovies = allMovies.concat(data.results);
389389
const popularityThreshold = 0.5;
390-
390+
allMovies = allMovies.concat(data.results);
391391
allMovies.sort((a, b) => {
392392
const popularityDifference = Math.abs(a.popularity - b.popularity);
393393
if (popularityDifference < popularityThreshold) {
@@ -402,6 +402,7 @@ async function getMovies(url, mainElement, page = 1) {
402402
else {
403403
mainElement.innerHTML = `<p>We're having trouble fetching movies right now. Please try again later.</p>`;
404404
}
405+
405406
hideSpinner();
406407
}
407408

@@ -464,7 +465,6 @@ function updateFavoriteGenre(genre_ids) {
464465

465466
function updateUniqueMoviesViewed(movieId) {
466467
let viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || [];
467-
468468
if (!viewedMovies.includes(movieId)) {
469469
viewedMovies.push(movieId);
470470
localStorage.setItem('uniqueMoviesViewed', JSON.stringify(viewedMovies));
@@ -595,7 +595,6 @@ async function rotateUserStats() {
595595

596596
const localTimeDiv = document.getElementById('local-time');
597597
let statRotationInterval = setInterval(updateStatDisplay, 3000);
598-
599598
localTimeDiv.addEventListener('click', () => {
600599
clearInterval(statRotationInterval);
601600
updateStatDisplay();
@@ -606,7 +605,6 @@ async function rotateUserStats() {
606605

607606
function updateMovieVisitCount(movieId, movieTitle) {
608607
let movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {};
609-
610608
if (!movieVisits[movieId]) {
611609
movieVisits[movieId] = { count: 0, title: movieTitle };
612610
}
@@ -625,6 +623,7 @@ function getMostVisitedMovie() {
625623
maxVisits = movieVisits[movieId].count;
626624
}
627625
}
626+
628627
return mostVisitedMovie || 'Not Available';
629628
}
630629

@@ -640,14 +639,14 @@ async function getMostVisitedMovieGenre() {
640639
mostVisitedGenre = await fetchGenreForMovie(movieId);
641640
}
642641
}
642+
643643
return mostVisitedGenre;
644644
}
645645

646646
async function fetchGenreForMovie(movieId) {
647647
const movieDetailsUrl = `https://${getMovieVerseData()}/3/movie/${movieId}?${generateMovieNames()}${getMovieCode()}`;
648648
const response = await fetch(movieDetailsUrl);
649649
const movieDetails = await response.json();
650-
651650
return movieDetails.genres[0] ? movieDetails.genres[0].id : null;
652651
}
653652

@@ -668,7 +667,6 @@ function getMostVisitedActor() {
668667

669668
function getMostVisitedDirector() {
670669
const directorVisits = JSON.parse(localStorage.getItem('directorVisits')) || {};
671-
672670
let mostVisitedDirector = '';
673671
let maxVisits = 0;
674672

@@ -683,7 +681,6 @@ function getMostVisitedDirector() {
683681

684682
function getTriviaAccuracy() {
685683
let triviaStats = JSON.parse(localStorage.getItem('triviaStats')) || { totalCorrect: 0, totalAttempted: 0 };
686-
687684
if (triviaStats.totalAttempted === 0) {
688685
return 'No trivia attempted';
689686
}
@@ -694,7 +691,6 @@ function getTriviaAccuracy() {
694691

695692
function getMostCommonGenre() {
696693
const favoriteGenresArray = JSON.parse(localStorage.getItem('favoriteGenres')) || [];
697-
698694
const genreCounts = favoriteGenresArray.reduce((acc, genre) => {
699695
acc[genre] = (acc[genre] || 0) + 1;
700696
return acc;

0 commit comments

Comments
 (0)