-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
6,565 additions
and
447 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
TMDBconfiguration, | ||
getMovies, | ||
movieDescription, | ||
} from './js-partials/themoviedbAPI'; | ||
import { showLoader } from './js-partials/loader'; | ||
import './js-partials/gallery_markup'; | ||
import './js-partials/localStorage'; | ||
import './js-partials/search'; | ||
import './js-partials/refs'; | ||
import './js-partials/api.js'; | ||
import './js-partials/gallery.js'; | ||
import './js-partials/library.js'; | ||
import './js-partials/scrollToTop.js'; | ||
import './js-partials/pagination.js'; | ||
import './js-partials/footer-modal.js'; | ||
import './js-partials/open-close-modal_movie_card.js' | ||
import './js-partials/movie-modal-description.js' | ||
|
||
|
||
/* getMovies().then(sr => { | ||
let cards = sr.results | ||
.map(movie => { | ||
return ` | ||
<div class="card"> | ||
<img src="${TMDBconfiguration.images.secure_base_url}w342${ | ||
movie.poster_path | ||
}" alt="${movie.title}"> | ||
<h3>${movie.title}</h3> | ||
<h4>${movieDescription(movie)}</h3 > | ||
</div > | ||
`; | ||
}) | ||
.join(''); | ||
console.log(sr.results); | ||
console.log(cards); | ||
}); */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { | ||
getFromStorage, | ||
localStorageKeys, | ||
setToLocalStorage, | ||
} from './localStorage'; | ||
|
||
import { refs } from './refs'; | ||
|
||
import { renderGallery } from './gallery_markup'; | ||
|
||
export const state = { | ||
currentPage: 1, | ||
totalPages: 0, | ||
activeFilm: null, | ||
query: null, | ||
whatPaginated: null, | ||
whatchedOrQueue: null, | ||
}; | ||
|
||
export const onBtnAddToLibrary = evt => { | ||
const watchedFilmsArray = getFromStorage(localStorageKeys.WATCHED) || []; | ||
const queueFilmsArray = getFromStorage(localStorageKeys.QUEUE) || []; | ||
|
||
if (evt.target.innerText === 'ADD TO WATCHED') { | ||
saveToStorageFilm( | ||
watchedFilmsArray, | ||
localStorageKeys.WATCHED, | ||
'WATCHED', | ||
evt | ||
); | ||
} else if (evt.target.innerText === 'REMOVE FROM WATCHED') { | ||
deleteFromStorageFilm( | ||
watchedFilmsArray, | ||
localStorageKeys.WATCHED, | ||
'WATCHED', | ||
evt | ||
); | ||
} else if (evt.target.innerText === 'ADD TO QUEUE') { | ||
saveToStorageFilm(queueFilmsArray, localStorageKeys.QUEUE, 'QUEUE', evt); | ||
} else if (evt.target.innerText === 'REMOVE FROM QUEUE') { | ||
deleteFromStorageFilm( | ||
queueFilmsArray, | ||
localStorageKeys.QUEUE, | ||
'QUEUE', | ||
evt | ||
); | ||
} | ||
}; | ||
|
||
function saveToStorageFilm(array, key, keyValue, evt) { | ||
array.push(state.activeFilm); | ||
setToLocalStorage(key, array); | ||
evt.target.innerText = `REMOVE FROM ${keyValue}`; | ||
} | ||
function deleteFromStorageFilm(array, key, keyValue, evt) { | ||
const filteredFilms = array.filter(film => film.id !== state.activeFilm.id); | ||
setToLocalStorage(key, filteredFilms); | ||
evt.target.innerText = `ADD TO ${keyValue}`; | ||
} | ||
|
||
export function updateMarkupLibrary(evt) { | ||
if (evt.target.innerText === 'ADD TO WATCHED') { | ||
deleteFromWatchedMarkup(); | ||
} else if (evt.target.innerText === 'REMOVE FROM WATCHED') { | ||
deleteFromWatchedMarkup(); | ||
} else if (evt.target.innerText === 'ADD TO QUEUE') { | ||
deleteFromQueueMarkup(); | ||
} else if (evt.target.innerText === 'REMOVE FROM QUEUE') { | ||
deleteFromQueueMarkup(); | ||
} | ||
} | ||
async function deleteFromWatchedMarkup() { | ||
resetCurrentPage(); | ||
const watchedFilmsinLocalStorage = | ||
getFromStorage(localStorageKeys.WATCHED) || []; | ||
const films = localPaginate(watchedFilmsinLocalStorage, state.currentPage); | ||
updateLibRender(films); | ||
changeBtnActiveStatus(refs.addToWachedButton, refs.addToQueueButton); | ||
} | ||
|
||
async function deleteFromQueueMarkup() { | ||
resetCurrentPage(); | ||
const queueFilmsinLocalStorage = getFromStorage(localStorageKeys.QUEUE) || []; | ||
const films = localPaginate(queueFilmsinLocalStorage, state.currentPage); | ||
updateLibRender(films); | ||
changeBtnActiveStatus(refs.addToQueueButton, refs.addToWachedButton); | ||
} | ||
|
||
function changeBtnActiveStatus(elFirst, elSecond) { | ||
elFirst.classList.add('active'); | ||
elSecond.classList.remove('active'); | ||
} |
Oops, something went wrong.