From 85c835bb953b57d096fd98263ef47dcad4490387 Mon Sep 17 00:00:00 2001 From: ThaUnknown Date: Tue, 30 Mar 2021 20:29:04 +0200 Subject: [PATCH] error """handling""" for main menu --- app/js/animeHandler.js | 2 +- app/js/interface.js | 81 +++++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/app/js/animeHandler.js b/app/js/animeHandler.js index 1427bd9..e2fc3d1 100644 --- a/app/js/animeHandler.js +++ b/app/js/animeHandler.js @@ -72,7 +72,7 @@ function searchBox () { // make searchbox behave nicely document.location.hash = '#browse' } // events -navNowPlaying.onclick = () => { viewAnime(playerData.nowPlaying[0]) } +navNowPlaying.onclick = () => { viewAnime(client.nowPlaying?.media) } // AL lookup logic async function alRequest (opts) { let query diff --git a/app/js/interface.js b/app/js/interface.js index 102883a..659376e 100644 --- a/app/js/interface.js +++ b/app/js/interface.js @@ -19,34 +19,40 @@ async function loadHomePage () { }, planning: async function (page) { if (!page) gallerySkeleton(browseGallery) - const res = await alRequest({ method: 'UserLists', status_in: 'PLANNING', id: alID, page: page || 1 }) - galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: browseGallery, method: 'planning', page: page || 1 }) + alRequest({ method: 'UserLists', status_in: 'PLANNING', id: alID, page: page || 1 }).then((res) => { + galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: browseGallery, method: 'planning', page: page || 1 }) + }) }, trending: async function (page) { if (!page) gallerySkeleton(browseGallery) - const res = await alRequest({ method: 'Trending', id: alID, page: page || 1 }) - galleryAppend({ media: res.data.Page.media, gallery: browseGallery, method: 'trending', page: page || 1 }) + alRequest({ method: 'Trending', id: alID, page: page || 1 }).then((res) => { + galleryAppend({ media: res.data.Page.media, gallery: browseGallery, method: 'trending', page: page || 1 }) + }) }, romance: async function (page) { if (!page) gallerySkeleton(browseGallery) - const res = await alRequest({ method: 'Genre', genre: 'Romance', page: page || 1 }) - galleryAppend({ media: res.data.Page.media, gallery: browseGallery, method: 'romance', page: page || 1 }) + alRequest({ method: 'Genre', genre: 'Romance', page: page || 1 }).then((res) => { + galleryAppend({ media: res.data.Page.media, gallery: browseGallery, method: 'romance', page: page || 1 }) + }) }, action: async function (page) { if (!page) gallerySkeleton(browseGallery) - const res = await alRequest({ method: 'Genre', genre: 'Action', page: page || 1 }) - galleryAppend({ media: res.data.Page.media, gallery: browseGallery, method: 'action', page: page || 1 }) + alRequest({ method: 'Genre', genre: 'Action', page: page || 1 }).then((res) => { + galleryAppend({ media: res.data.Page.media, gallery: browseGallery, method: 'action', page: page || 1 }) + }) }, schedule: async function (page) { if (!page) gallerySkeleton(browseGallery) - const res = await alRequest({ method: 'AiringSchedule', page: page || 1 }).then(res => res.data.Page.airingSchedules.filter(entry => entry.media.countryOfOrigin !== 'CN' && entry.media.isAdult === false)) - galleryAppend({ media: res.map(data => data.media), gallery: browseGallery, method: 'schedule', page: page || 1, schedule: true }) + alRequest({ method: 'AiringSchedule', page: page || 1 }).then(res => { + galleryAppend({ media: res.data.Page.airingSchedules.filter(entry => entry.media.countryOfOrigin !== 'CN' && entry.media.isAdult === false), gallery: browseGallery, method: 'schedule', page: page || 1, schedule: true }) + }) } } const homePreviewFunctions = { continue: async function () { - const res = await alRequest({ method: 'UserLists', status_in: 'CURRENT', id: alID, perPage: 5 }) - galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: homeContinue }) + alRequest({ method: 'UserLists', status_in: 'CURRENT', id: alID, perPage: 5 }).then((res) => { + galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: homeContinue }) + }) }, releases: async function () { // this could be cleaner, but oh well await fetch(getRSSurl()).then(res => res.text().then(async xmlTxt => { @@ -80,20 +86,24 @@ async function loadHomePage () { setTimeout(homePreviewFunctions.releases, 30000) }, planning: async function () { - const res = await alRequest({ method: 'UserLists', status_in: 'PLANNING', id: alID, perPage: 5 }) - galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: homePlanning }) + alRequest({ method: 'UserLists', status_in: 'PLANNING', id: alID, perPage: 5 }).then((res) => { + galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: homePlanning }) + }) }, trending: async function () { - const res = await alRequest({ method: 'Trending', id: alID, perPage: 5 }) - galleryAppend({ media: res.data.Page.media, gallery: homeTrending }) + alRequest({ method: 'Trending', id: alID, perPage: 5 }).then((res) => { + galleryAppend({ media: res.data.Page.media, gallery: homeTrending }) + }) }, romance: async function () { - const res = await alRequest({ method: 'Genre', genre: 'Romance', perPage: 5 }) - galleryAppend({ media: res.data.Page.media, gallery: homeRomance }) + alRequest({ method: 'Genre', genre: 'Romance', perPage: 5 }).then((res) => { + galleryAppend({ media: res.data.Page.media, gallery: homeRomance }) + }) }, action: async function () { - const res = await alRequest({ method: 'Genre', genre: 'Action', perPage: 5 }) - galleryAppend({ media: res.data.Page.media, gallery: homeAction }) + alRequest({ method: 'Genre', genre: 'Action', perPage: 5 }).then((res) => { + galleryAppend({ media: res.data.Page.media, gallery: homeAction }) + }) } } const gallerySkeletonFrag = function (limit) { @@ -106,6 +116,7 @@ async function loadHomePage () { let loadTimeout let lastDate let lastRSSDate + let canScroll = true function gallerySkeleton (gallery) { browse.classList.add('loading') @@ -113,11 +124,17 @@ async function loadHomePage () { gallery.appendChild(gallerySkeletonFrag(10)) } function galleryAppend (opts) { + if (opts.page === 1) { + opts.gallery.scrollTop = 0 + browse.classList.remove('loading') + } if (opts.method) { + canScroll = false browse.onscroll = function () { - if (this.scrollTop + this.clientHeight > this.scrollHeight - 800 && !loadTimeout) { + if (this.scrollTop + this.clientHeight > this.scrollHeight - 800 && !loadTimeout && canScroll) { + canScroll = false loadTimeout = setTimeout(function () { loadTimeout = undefined }, 1000) - homeLoadFunctions[opts.method](opts.page + 1) + homeLoadFunctions[opts.method](opts.page + 1).then(() => { canScroll = true }) } } } @@ -127,22 +144,22 @@ async function loadHomePage () { const frag = document.createDocumentFragment() const date = new Date() opts.media.forEach(media => { - if (opts.schedule && media.nextAiringEpisode?.timeUntilAiring && (!lastDate || (new Date(+date + media.nextAiringEpisode.timeUntilAiring * 1000).getDay() !== lastDate.getDay()))) { - const div = document.createElement('div') - lastDate = new Date(+date + media.nextAiringEpisode.timeUntilAiring * 1000) - div.classList.add('day-row', 'font-size-24', 'font-weight-bold', 'h-50', 'd-flex', 'align-items-end') - div.innerHTML = lastDate.toLocaleDateString('en-US', { weekday: 'long' }) - frag.appendChild(div) + if (opts.schedule) { + if (media.timeUntilAiring && (!lastDate || (new Date(+date + media.timeUntilAiring * 1000).getDay() !== lastDate.getDay()))) { + const div = document.createElement('div') + lastDate = new Date(+date + media.timeUntilAiring * 1000) + div.classList.add('day-row', 'font-size-24', 'font-weight-bold', 'h-50', 'd-flex', 'align-items-end') + div.innerHTML = lastDate.toLocaleDateString('en-US', { weekday: 'long' }) + frag.appendChild(div) + } + media = media.media } const template = cardCreator({ media: media, schedule: opts.schedule }) template.onclick = () => viewAnime(media) frag.appendChild(template) }) opts.gallery.appendChild(frag) - if (opts.page === 1) { - opts.gallery.scrollTop = 0 - browse.classList.remove('loading') - } + canScroll = true } for (const item of homePreviewElements) {