is this good code?...

This commit is contained in:
ThaUnknown 2021-01-05 09:26:15 +01:00
parent b0f98f2b6a
commit 4841bc4abe

View file

@ -2,20 +2,20 @@ async function loadHomePage() {
let homeLoadElements = [homeContinueMore, homeReleasesMore, homePlanningMore, homeTrendingMore],
homePreviewElements = [homeContinue, homeReleases, homePlanning, homeTrending],
homeLoadFunctions = {
continue: async function () {
let res = await alRequest({ method: "UserLists", status_in: "CURRENT", id: alID })
galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: document.querySelector(".browse") })
continue: async function (page) {
let res = await alRequest({ method: "UserLists", status_in: "CURRENT", id: alID, page: page || 1 })
galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: document.querySelector(".browse"), method: "continue", page: page || 1 })
},
releases: async function () {
},
planning: async function () {
let res = await alRequest({ method: "UserLists", status_in: "PLANNING", id: alID })
galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: document.querySelector(".browse") })
planning: async function (page) {
let res = await alRequest({ method: "UserLists", status_in: "PLANNING", id: alID, page: page || 1 })
galleryAppend({ media: res.data.Page.mediaList.map(i => i.media), gallery: document.querySelector(".browse"), method: "planning", page: page || 1 })
},
trending: async function () {
let res = await alRequest({ method: "Trending", id: alID })
galleryAppend({ media: res.data.Page.media, gallery: document.querySelector(".browse") })
trending: async function (page) {
let res = await alRequest({ method: "Trending", id: alID, page: page || 1 })
galleryAppend({ media: res.data.Page.media, gallery: document.querySelector(".browse"), method: "trending", page: page || 1 })
}
},
homePreviewFunctions = {
@ -34,18 +34,28 @@ async function loadHomePage() {
let res = await alRequest({ method: "Trending", id: alID, perPage: 4 })
galleryAppend({ media: res.data.Page.media, gallery: homeTrending })
}
}
},
loadTimeout
function galleryAppend(opts) {
//TODO: add skeleton loading
let frag = document.createDocumentFragment()
opts.media.forEach(media => {
let template = cardCreator(media)
template.onclick = () => viewAnime(media)
frag.appendChild(template)
function appendFrag(media) {
let frag = document.createDocumentFragment()
media.forEach(media => {
let template = cardCreator(media)
template.onclick = () => viewAnime(media)
frag.appendChild(template)
})
opts.gallery.appendChild(frag)
}
if (opts.method) opts.gallery.addEventListener("scroll", function () {
if (this.scrollTop + this.clientHeight > this.scrollHeight - 800 && !loadTimeout) {
loadTimeout = setTimeout(function () { loadTimeout = undefined }, 1000)
homeLoadFunctions[opts.method](opts.page + 1)
}
})
opts.gallery.textContent = '';
opts.gallery.appendChild(frag)
if (!opts.page || opts.page == 1) opts.gallery.textContent = '';
appendFrag(opts.media)
}
for (let item of homePreviewElements) {