Skip to content

Commit

Permalink
feat:completed hnav
Browse files Browse the repository at this point in the history
  • Loading branch information
dev1abhi committed Mar 23, 2024
1 parent b8dce77 commit 6db19eb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
59 changes: 44 additions & 15 deletions content_explore/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,71 @@ const apiKey = '68e094699525b18a70bab2f86b1fa706';
let currentPage = parseInt(localStorage.getItem('currentPage')) || 1;
const totalPages = 20; // Example: total number of pages
let contentType="";
let Rank="";
let Region="";

document.addEventListener("DOMContentLoaded", function() {
// Get the query parameter from the URL
const urlParams = new URLSearchParams(window.location.search);
const type = urlParams.get('type');
const rank=urlParams.get('rank');
const region = urlParams.get('region');
Rank=rank;
Region=region;
//console.log(rank);

// Fetch data based on the type parameter
if (type === 'movies') {
contentType="movie";
fillCardsWithPageAndType(currentPage, 'movie');
} else if (type === 'series') {
fillCardsWithPageAndType(currentPage, 'movie',rank , region);
} else if (type === 'series' ) {
contentType="tv";
fillCardsWithPageAndType(currentPage, 'tv');
} else {
// Handle the case where no type is specified
fillCardsWithPageAndType(currentPage, 'tv',rank , region);
} else{

}
});

// Function to fetch trending movies from TMDB API with pagination support
async function fetchMoviesByPageAndType(page,type) {
const response = await fetch(`https://api.themoviedb.org/3/trending/${type}/week?api_key=${apiKey}&page=${page}`);
async function fetchMoviesByPageAndType(page,type,rank,region) {
let response;
console.log(rank);
console.log(region);
if (rank==null && region==null) //trending US
{
response = await fetch(`https://api.themoviedb.org/3/trending/${type}/week?api_key=${apiKey}&page=${page}`);
}
else if (rank=='topRanked' && region==null) //Top-rated US
{
console.log('yes')
response = await fetch(`https://api.themoviedb.org/3/${type}/top_rated?api_key=${apiKey}&page=${page}`);
}
else if (rank=='topRanked' && region == "KR") //Popular Korean
{
response = await fetch(`https://api.themoviedb.org/3/discover/movie?api_key=${apiKey}&language=ko-KR&region=KR&sort_by=popularity.desc&with_original_language=ko&page=${page}`)
}

else if (rank=='topRanked' && region == "IN") //Popular Indian
{
response = await fetch(`https://api.themoviedb.org/3/discover/movie?api_key=${apiKey}&language=en-IN&region=IN&sort_by=popularity.desc&with_original_language=hi&page=${page}`)
}

const data = await response.json();
return data.results;
}

// Function to fetch movie details including poster URLs from TMDB API
// Function to fetch movie/series details including poster URLs from TMDB API
//dont change this
async function fetchMovieDetails(movieId,type) {
const response = await fetch(`https://api.themoviedb.org/3/${type}/${movieId}?api_key=${apiKey}`);
const data = await response.json();
return data;
}

// Function to dynamically fill the cards with movie data
async function fillCardsWithPageAndType(page,type) {
async function fillCardsWithPageAndType(page,type,rank,region) {

const movies = await fetchMoviesByPageAndType(page,type);
const movies = await fetchMoviesByPageAndType(page,type,rank,region);
var movieDivs = document.querySelectorAll(".view.movie");
const cards = document.querySelectorAll('.card');

Expand Down Expand Up @@ -186,26 +215,26 @@ cards.forEach(function(card) {
if (!isNaN(pageNum) && pageNum !== currentPage) {
currentPage = pageNum;
updatePaginationButtons();
fillCardsWithPageAndType(currentPage,contentType);
fillCardsWithPageAndType(currentPage,contentType,Rank,Region);
}
} else if (event.target.id === 'prevPage' && currentPage > 1) {
currentPage--;
updatePaginationButtons();
fillCardsWithPageAndType(currentPage,contentType);
fillCardsWithPageAndType(currentPage,contentType,Rank,Region);
} else if (event.target.id === 'nextPage' && currentPage < totalPages) {
++currentPage;
updatePaginationButtons();
fillCardsWithPageAndType(currentPage,contentType);
fillCardsWithPageAndType(currentPage,contentType,Rank,Region);
}
else if (event.target.id === 'firstPage') {
currentPage=1;
updatePaginationButtons();
fillCardsWithPageAndType(currentPage,contentType);
fillCardsWithPageAndType(currentPage,contentType,Rank,Region);
}
else if (event.target.id === 'lastPage') {
currentPage=20;
updatePaginationButtons();
fillCardsWithPageAndType(currentPage,contentType);
fillCardsWithPageAndType(currentPage,contentType,Rank,Region);
}
});

Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@
<nav >
<a href="content_explore/content.html?type=movies"> Trending Movies</a>
<a href="content_explore/content.html?type=series"> Buzzin Series</a>
<a href="#TopratedMovies"> Top-Ranked Movies</a>
<a href="#SeriesTr"> Top-Rated Series</a>
<a href="#Bollywood"> Bollywood</a>
<a href="#Bollywood"> Korean </a>
<a href="content_explore/content.html?type=movies&rank=topRanked"> Top-Ranked Movies</a>
<a href="content_explore/content.html?type=series&rank=topRanked"> Top-Rated Series</a>
<a href="content_explore/content.html?type=movies&rank=topRanked&region=IN"> Bollywood</a>
<a href="content_explore/content.html?type=movies&rank=topRanked&region=KR"> Korean </a>
</nav>


Expand Down

0 comments on commit 6db19eb

Please sign in to comment.