2019-11-18 02:04:13 +00:00
|
|
|
import emptyPixel from "scripts/Utils/emptyPixel"
|
|
|
|
import findAll from "scripts/Utils/findAll"
|
2018-04-02 05:34:16 +00:00
|
|
|
import AnimeNotifier from "../AnimeNotifier"
|
2017-11-07 16:46:39 +00:00
|
|
|
|
|
|
|
// Filter anime on explore page
|
2019-04-22 09:06:50 +00:00
|
|
|
export function filterAnime(arn: AnimeNotifier, _: HTMLInputElement) {
|
2019-11-17 09:25:14 +00:00
|
|
|
const root = document.getElementById("filter-root") as HTMLElement
|
2018-03-23 00:43:45 +00:00
|
|
|
|
2019-11-17 09:25:14 +00:00
|
|
|
const elementYear = document.getElementById("filter-year") as HTMLSelectElement
|
|
|
|
const elementSeason = document.getElementById("filter-season") as HTMLSelectElement
|
|
|
|
const elementStatus = document.getElementById("filter-status") as HTMLSelectElement
|
|
|
|
const elementType = document.getElementById("filter-type") as HTMLSelectElement
|
2017-11-07 16:46:39 +00:00
|
|
|
|
2019-11-17 09:25:14 +00:00
|
|
|
for(const element of findAll("anime-grid-image")) {
|
|
|
|
const img = element as HTMLImageElement
|
2019-11-18 02:04:13 +00:00
|
|
|
img.src = emptyPixel
|
2018-03-14 03:18:57 +00:00
|
|
|
img.classList.remove("element-found")
|
2018-03-20 22:58:37 +00:00
|
|
|
img.classList.remove("element-color-preview")
|
2018-03-14 02:50:39 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 09:25:14 +00:00
|
|
|
const year = elementYear.value || "any"
|
|
|
|
const season = elementSeason.value || "any"
|
|
|
|
const status = elementStatus.value || "any"
|
|
|
|
const type = elementType.value || "any"
|
2018-03-23 00:43:45 +00:00
|
|
|
|
2018-04-13 15:55:52 +00:00
|
|
|
arn.diff(`${root.dataset.url}/${year}/${season}/${status}/${type}`)
|
2017-12-02 20:06:15 +00:00
|
|
|
}
|
|
|
|
|
2018-07-05 16:52:05 +00:00
|
|
|
// Toggle hiding added anime.
|
2018-11-16 07:46:56 +00:00
|
|
|
export function toggleHideAddedAnime() {
|
2018-07-05 16:52:05 +00:00
|
|
|
hideAddedAnime()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hides anime that are already in your list.
|
|
|
|
export function hideAddedAnime() {
|
2019-11-17 09:25:14 +00:00
|
|
|
for(const anime of findAll("anime-grid-cell")) {
|
2018-07-05 16:55:04 +00:00
|
|
|
if(anime.dataset.added !== "true") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-07-05 17:37:22 +00:00
|
|
|
anime.classList.toggle("anime-grid-cell-hide")
|
2017-12-02 20:06:15 +00:00
|
|
|
}
|
2017-12-03 18:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hides anime that are not in your list.
|
2019-04-27 11:23:15 +00:00
|
|
|
export async function calendarShowAddedAnimeOnly(arn: AnimeNotifier, element: HTMLInputElement) {
|
2019-11-17 09:25:14 +00:00
|
|
|
const calendar = document.getElementById("calendar")
|
2019-03-02 21:16:24 +00:00
|
|
|
|
2019-04-27 11:23:15 +00:00
|
|
|
if(!calendar || calendar.dataset.showAddedAnimeOnly === undefined) {
|
|
|
|
return
|
|
|
|
}
|
2019-03-02 21:16:24 +00:00
|
|
|
|
2019-04-27 11:23:15 +00:00
|
|
|
// Toggling the switch will trigger the CSS rules
|
|
|
|
if(calendar.dataset.showAddedAnimeOnly === "true") {
|
|
|
|
calendar.dataset.showAddedAnimeOnly = "false"
|
|
|
|
} else {
|
|
|
|
calendar.dataset.showAddedAnimeOnly = "true"
|
2019-03-02 21:16:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 11:23:15 +00:00
|
|
|
// Save the state in the database
|
2019-11-17 09:25:14 +00:00
|
|
|
const showAddedAnimeOnly = calendar.dataset.showAddedAnimeOnly === "true"
|
|
|
|
const apiEndpoint = arn.findAPIEndpoint(element)
|
2019-04-27 11:23:15 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await arn.post(apiEndpoint, {
|
|
|
|
"Calendar.ShowAddedAnimeOnly": showAddedAnimeOnly
|
|
|
|
})
|
|
|
|
} catch(err) {
|
|
|
|
arn.statusMessage.showError(err)
|
|
|
|
}
|
2019-11-17 09:44:30 +00:00
|
|
|
}
|