Added AMV search

This commit is contained in:
Eduard Urbach 2018-11-12 16:52:07 +09:00
parent dc04601072
commit 9e3ec7656d
5 changed files with 49 additions and 5 deletions

View File

@ -16,6 +16,7 @@ func Register(l *layout.Layout) {
l.Page("/forum-search/*term", search.Forum)
l.Page("/soundtrack-search/*term", search.SoundTracks)
l.Page("/user-search/*term", search.Users)
l.Page("/amv-search/*term", search.AMVs)
l.Page("/company-search/*term", search.Companies)
// Multi-search

View File

@ -19,6 +19,7 @@ const (
maxPosts = 2
maxThreads = 2
maxSoundTracks = 3
maxAMVs = 3
maxCharacters = 22
maxCompanies = 3
)
@ -29,7 +30,7 @@ func Get(ctx *aero.Context) string {
term = strings.TrimPrefix(term, "/")
user := utils.GetUser(ctx)
users, animes, posts, threads, tracks, characters, companies := search.All(
users, animes, posts, threads, tracks, characters, amvs, companies := search.All(
term,
maxUsers,
maxAnime,
@ -37,15 +38,16 @@ func Get(ctx *aero.Context) string {
maxThreads,
maxSoundTracks,
maxCharacters,
maxAMVs,
maxCompanies,
)
return ctx.HTML(components.SearchResults(term, users, animes, posts, threads, tracks, characters, companies, nil, user))
return ctx.HTML(components.SearchResults(term, users, animes, posts, threads, tracks, characters, amvs, companies, nil, user))
}
// GetEmptySearch renders the search page with no contents.
func GetEmptySearch(ctx *aero.Context) string {
return ctx.HTML(components.SearchResults("", nil, nil, nil, nil, nil, nil, nil, nil, utils.GetUser(ctx)))
return ctx.HTML(components.SearchResults("", nil, nil, nil, nil, nil, nil, nil, nil, nil, utils.GetUser(ctx)))
}
// Anime search.
@ -96,6 +98,16 @@ func SoundTracks(ctx *aero.Context) string {
return ctx.HTML(components.SoundTrackSearchResults(tracks, user))
}
// AMVs search.
func AMVs(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
user := utils.GetUser(ctx)
amvs := search.AMVs(term, maxAMVs)
return ctx.HTML(components.AMVSearchResults(amvs, user))
}
// Users search.
func Users(ctx *aero.Context) string {
term := ctx.Get("term")

View File

@ -1,4 +1,4 @@
component SearchResults(term string, users []*arn.User, animes []*arn.Anime, posts []*arn.Post, threads []*arn.Thread, tracks []*arn.SoundTrack, characters []*arn.Character, companies []*arn.Company, quotes []*arn.Quote, user *arn.User)
component SearchResults(term string, users []*arn.User, animes []*arn.Anime, posts []*arn.Post, threads []*arn.Thread, tracks []*arn.SoundTrack, characters []*arn.Character, amvs []*arn.AMV, companies []*arn.Company, quotes []*arn.Quote, user *arn.User)
h1.page-title= "Search: " + term
.search
@ -34,6 +34,14 @@ component SearchResults(term string, users []*arn.User, animes []*arn.Anime, pos
#soundtrack-search-results
SoundTrackSearchResults(tracks, user)
.widget
h3.widget-title
Icon("video-camera")
span AMVs
#amv-search-results
AMVSearchResults(amvs, user)
//- .widget
//- h3.widget-title
//- Icon("quote-left")
@ -107,6 +115,20 @@ component SoundTrackSearchResults(tracks []*arn.SoundTrack, user *arn.User)
a(href=track.Link())= track.Title.ByUser(user)
span.soundtrack-search-anime= " - " + track.MainAnime().Title.Canonical
component AMVSearchResults(amvs []*arn.AMV, user *arn.User)
if len(amvs) == 0
p.no-search-results.mountable No AMVs found.
else
ul.amv-search
each amv in amvs
li.mountable(data-mountable-type="amv")
a(href=amv.Link())= amv.Title.ByUser(user)
if amv.MainAnime() != nil
span.amv-search-anime= " - " + amv.MainAnime().Title.Canonical
else
span.amv-search-anime= fmt.Sprintf(" - %d anime", len(amv.ExtraAnimeIDs))
component CompanySearchResults(companies []*arn.Company)
if len(companies) == 0
p.no-search-results.mountable No companies found.

View File

@ -37,7 +37,8 @@
margin-bottom 1rem
opacity 0.8
.soundtrack-search-anime
.soundtrack-search-anime,
.amv-search-anime
opacity 0.35
.no-search-results

View File

@ -11,6 +11,7 @@ var correctResponseRendered = {
"forum": false,
"soundtrack": false,
"user": false,
"amv": false,
"company": false
}
@ -23,6 +24,7 @@ var characterSearchResults: HTMLElement
var forumSearchResults: HTMLElement
var soundtrackSearchResults: HTMLElement
var userSearchResults: HTMLElement
var amvSearchResults: HTMLElement
var companySearchResults: HTMLElement
// Delay before a request is sent
@ -60,6 +62,7 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, evt?:
correctResponseRendered.forum = false
correctResponseRendered.soundtrack = false
correctResponseRendered.user = false
correctResponseRendered.amv = false
correctResponseRendered.company = false
// Set browser URL
@ -108,6 +111,7 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, evt?:
forumSearchResults = document.getElementById("forum-search-results")
soundtrackSearchResults = document.getElementById("soundtrack-search-results")
userSearchResults = document.getElementById("user-search-results")
amvSearchResults = document.getElementById("amv-search-results")
companySearchResults = document.getElementById("company-search-results")
searchPageTitle = document.getElementsByTagName("h1")[0]
}
@ -147,6 +151,10 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, evt?:
.then(showResponseInElement(arn, url, "user", userSearchResults))
.catch(console.error)
fetch("/_/amv-search/" + term, fetchOptions)
.then(showResponseInElement(arn, url, "amv", amvSearchResults))
.catch(console.error)
fetch("/_/company-search/" + term, fetchOptions)
.then(showResponseInElement(arn, url, "company", companySearchResults))
.catch(console.error)