From 966943fd2e31c34799bb67d2e731166773d213ab Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 17 Apr 2018 00:02:24 +0200 Subject: [PATCH] Added anime multisearch --- pages/index.go | 3 +++ pages/search/multisearch/multisearch.go | 11 +++++++++++ pages/search/multisearch/multisearch.pixy | 3 +++ scripts/Actions/Editor.ts | 21 +++++++++++++++++++++ scripts/Actions/Search.ts | 14 +++++++++----- 5 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 pages/search/multisearch/multisearch.go create mode 100644 pages/search/multisearch/multisearch.pixy diff --git a/pages/index.go b/pages/index.go index 68108174..e4a76c14 100644 --- a/pages/index.go +++ b/pages/index.go @@ -60,6 +60,7 @@ import ( "github.com/animenotifier/notify.moe/pages/quotes" "github.com/animenotifier/notify.moe/pages/recommended" "github.com/animenotifier/notify.moe/pages/search" + "github.com/animenotifier/notify.moe/pages/search/multisearch" "github.com/animenotifier/notify.moe/pages/settings" "github.com/animenotifier/notify.moe/pages/shop" "github.com/animenotifier/notify.moe/pages/soundtrack" @@ -252,7 +253,9 @@ func Configure(app *aero.Application) { l.Page("/soundtrack-search/*term", search.SoundTracks) l.Page("/user-search/*term", search.Users) l.Page("/company-search/*term", search.Companies) + l.Page("/multisearch/anime", multisearch.Anime) + // Shop // Shop l.Page("/support", support.Get) l.Page("/shop", shop.Get) diff --git a/pages/search/multisearch/multisearch.go b/pages/search/multisearch/multisearch.go new file mode 100644 index 00000000..01adee1f --- /dev/null +++ b/pages/search/multisearch/multisearch.go @@ -0,0 +1,11 @@ +package multisearch + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" +) + +// Anime search page. +func Anime(ctx *aero.Context) string { + return ctx.HTML(components.MultiSearch()) +} diff --git a/pages/search/multisearch/multisearch.pixy b/pages/search/multisearch/multisearch.pixy new file mode 100644 index 00000000..39f17c82 --- /dev/null +++ b/pages/search/multisearch/multisearch.pixy @@ -0,0 +1,3 @@ +component MultiSearch + textarea.action(data-action="multiSearchAnime", data-trigger="change", placeholder="Paste multiple anime titles here, one per line") + #multi-search-anime \ No newline at end of file diff --git a/scripts/Actions/Editor.ts b/scripts/Actions/Editor.ts index f1fc94f9..4bc545b9 100644 --- a/scripts/Actions/Editor.ts +++ b/scripts/Actions/Editor.ts @@ -1,4 +1,6 @@ import AnimeNotifier from "../AnimeNotifier" +import { findAllInside } from "../Utils"; +import { showSearchResults } from "./Search" // newAnimeDiffIgnore export function newAnimeDiffIgnore(arn: AnimeNotifier, button: HTMLButtonElement) { @@ -34,4 +36,23 @@ export async function importKitsuAnime(arn: AnimeNotifier, button: HTMLButtonEle } else { arn.statusMessage.showError(await response.text()) } +} + +// Multi-search anime +export async function multiSearchAnime(arn: AnimeNotifier, textarea: HTMLTextAreaElement) { + let results = document.getElementById("multi-search-anime") as HTMLDivElement + let animeTitles = textarea.value.split("\n") + let animeIDs = new Array(animeTitles.length) + + results.innerHTML = "" + + for(let i = 0; i < animeTitles.length; i++) { + console.log(animeTitles[i]) + let response = await fetch("/_/anime-search/" + animeTitles[i]) + let html = await response.text() + results.innerHTML += "

" + animeTitles[i] + "

" + html + } + + results.classList.remove("hidden") + showSearchResults(arn, results) } \ No newline at end of file diff --git a/scripts/Actions/Search.ts b/scripts/Actions/Search.ts index 67e43839..71fabc28 100644 --- a/scripts/Actions/Search.ts +++ b/scripts/Actions/Search.ts @@ -165,10 +165,14 @@ function showResponseInElement(arn: AnimeNotifier, url: string, typeName: string await arn.innerHTML(element, html) - // Do the same as for the content loaded event, - // except here we are limiting it to the element. - arn.app.ajaxify(element.getElementsByTagName("a")) - arn.lazyLoad(findAllInside("lazy", element)) - arn.mountMountables(findAllInside("mountable", element)) + showSearchResults(arn, element) } } + +export function showSearchResults(arn: AnimeNotifier, element: HTMLElement) { + // Do the same as for the content loaded event, + // except here we are limiting it to the element. + arn.app.ajaxify(element.getElementsByTagName("a")) + arn.lazyLoad(findAllInside("lazy", element)) + arn.mountMountables(findAllInside("mountable", element)) +}