Improved search
This commit is contained in:
@ -5,10 +5,7 @@ import (
|
||||
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
|
||||
"github.com/aerogo/flow"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/arn/search"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
)
|
||||
@ -70,22 +67,24 @@ func Characters(ctx *aero.Context) string {
|
||||
return ctx.HTML(components.CharacterSearchResults(characters, user))
|
||||
}
|
||||
|
||||
// Forum search.
|
||||
func Forum(ctx *aero.Context) string {
|
||||
// Posts search.
|
||||
func Posts(ctx *aero.Context) string {
|
||||
term := ctx.Get("term")
|
||||
term = strings.TrimPrefix(term, "/")
|
||||
user := utils.GetUser(ctx)
|
||||
posts := search.Posts(term, maxPosts)
|
||||
|
||||
var posts []*arn.Post
|
||||
var threads []*arn.Thread
|
||||
return ctx.HTML(components.PostsSearchResults(posts, user))
|
||||
}
|
||||
|
||||
flow.Parallel(func() {
|
||||
posts = search.Posts(term, maxPosts)
|
||||
}, func() {
|
||||
threads = search.Threads(term, maxThreads)
|
||||
})
|
||||
// Threads search.
|
||||
func Threads(ctx *aero.Context) string {
|
||||
term := ctx.Get("term")
|
||||
term = strings.TrimPrefix(term, "/")
|
||||
user := utils.GetUser(ctx)
|
||||
threads := search.Threads(term, maxThreads)
|
||||
|
||||
return ctx.HTML(components.ForumSearchResults(posts, threads, user))
|
||||
return ctx.HTML(components.ThreadsSearchResults(threads, user))
|
||||
}
|
||||
|
||||
// SoundTracks search.
|
||||
|
@ -2,7 +2,7 @@ component SearchResults(term string, users []*arn.User, animes []*arn.Anime, pos
|
||||
h1.page-title= "Search: " + term
|
||||
|
||||
.search
|
||||
.widget
|
||||
.widget(class=utils.SearchClass(animes))
|
||||
h3.widget-title
|
||||
Icon("tv")
|
||||
span Anime
|
||||
@ -10,7 +10,7 @@ component SearchResults(term string, users []*arn.User, animes []*arn.Anime, pos
|
||||
#anime-search-results
|
||||
AnimeSearchResults(animes, user)
|
||||
|
||||
.widget
|
||||
.widget(class=utils.SearchClass(characters))
|
||||
h3.widget-title
|
||||
Icon("user")
|
||||
span Characters
|
||||
@ -18,15 +18,23 @@ component SearchResults(term string, users []*arn.User, animes []*arn.Anime, pos
|
||||
#character-search-results
|
||||
CharacterSearchResults(characters, user)
|
||||
|
||||
.widget
|
||||
.widget(class=utils.SearchClass(posts))
|
||||
h3.widget-title
|
||||
Icon("comment")
|
||||
span Forum
|
||||
span Posts
|
||||
|
||||
#forum-search-results
|
||||
ForumSearchResults(posts, threads, user)
|
||||
#posts-search-results
|
||||
PostsSearchResults(posts, user)
|
||||
|
||||
.widget(class=utils.SearchClass(threads))
|
||||
h3.widget-title
|
||||
Icon("comments")
|
||||
span Threads
|
||||
|
||||
.widget
|
||||
#threads-search-results
|
||||
ThreadsSearchResults(threads, user)
|
||||
|
||||
.widget(class=utils.SearchClass(tracks))
|
||||
h3.widget-title
|
||||
Icon("music")
|
||||
span Soundtracks
|
||||
@ -34,7 +42,7 @@ component SearchResults(term string, users []*arn.User, animes []*arn.Anime, pos
|
||||
#soundtrack-search-results
|
||||
SoundTrackSearchResults(tracks, user)
|
||||
|
||||
.widget
|
||||
.widget(class=utils.SearchClass(amvs))
|
||||
h3.widget-title
|
||||
Icon("video-camera")
|
||||
span AMVs
|
||||
@ -50,7 +58,7 @@ component SearchResults(term string, users []*arn.User, animes []*arn.Anime, pos
|
||||
//- #quote-search-results
|
||||
//- QuoteSearchResults(quotes)
|
||||
|
||||
.widget
|
||||
.widget(class=utils.SearchClass(companies))
|
||||
h3.widget-title
|
||||
Icon("building")
|
||||
span Companies
|
||||
@ -58,7 +66,7 @@ component SearchResults(term string, users []*arn.User, animes []*arn.Anime, pos
|
||||
#company-search-results
|
||||
CompanySearchResults(companies)
|
||||
|
||||
.widget
|
||||
.widget(class=utils.SearchClass(users))
|
||||
h3.widget-title
|
||||
Icon("user")
|
||||
span Users
|
||||
@ -84,26 +92,34 @@ component CharacterSearchResults(characters []*arn.Character, user *arn.User)
|
||||
.mountable(data-mountable-type="character")
|
||||
CharacterSmall(character, user)
|
||||
|
||||
component ForumSearchResults(posts []*arn.Post, threads []*arn.Thread, user *arn.User)
|
||||
if len(posts) == 0 && len(threads) == 0
|
||||
component PostsSearchResults(posts []*arn.Post, user *arn.User)
|
||||
if len(posts) == 0
|
||||
p.no-search-results.mountable No posts found.
|
||||
else
|
||||
.forum-search-results
|
||||
each thread in threads
|
||||
.forum-search-result.mountable(data-mountable-type="forum")
|
||||
.forum-search-result-header
|
||||
a.forum-search-result-title(href=thread.Link())= thread.Title
|
||||
if thread.Creator().HasNick()
|
||||
.forum-search-result-author= thread.Creator().Nick
|
||||
.forum-search-result-sample= thread.Text
|
||||
|
||||
.posts-search-results
|
||||
each post in posts
|
||||
.forum-search-result.mountable(data-mountable-type="forum")
|
||||
.forum-search-result-header
|
||||
a.forum-search-result-title(href=post.Link(), data-mountable-type="forum")= post.Parent().TitleByUser(user)
|
||||
.posts-search-result.mountable(data-mountable-type="post")
|
||||
.posts-search-result-header
|
||||
a.posts-search-result-title(href=post.Link(), data-mountable-type="post")= post.Parent().TitleByUser(user)
|
||||
|
||||
if post.Creator().HasNick()
|
||||
.forum-search-result-author= post.Creator().Nick
|
||||
.forum-search-result-sample= post.Text
|
||||
.posts-search-result-author= post.Creator().Nick
|
||||
|
||||
.posts-search-result-sample= post.Text
|
||||
|
||||
component ThreadsSearchResults(threads []*arn.Thread, user *arn.User)
|
||||
if len(threads) == 0
|
||||
p.no-search-results.mountable No threads found.
|
||||
else
|
||||
each thread in threads
|
||||
.posts-search-result.mountable(data-mountable-type="thread")
|
||||
.posts-search-result-header
|
||||
a.posts-search-result-title(href=thread.Link())= thread.Title
|
||||
|
||||
if thread.Creator().HasNick()
|
||||
.posts-search-result-author= thread.Creator().Nick
|
||||
|
||||
.posts-search-result-sample= thread.Text
|
||||
|
||||
component SoundTrackSearchResults(tracks []*arn.SoundTrack, user *arn.User)
|
||||
if len(tracks) == 0
|
||||
|
@ -10,29 +10,29 @@
|
||||
width anime-image-small-width !important
|
||||
height anime-image-small-height !important
|
||||
|
||||
.forum-search-results
|
||||
.posts-search-results
|
||||
horizontal-wrap
|
||||
justify-content space-around
|
||||
|
||||
.forum-search-result
|
||||
.posts-search-result
|
||||
vertical
|
||||
flex 1
|
||||
flex-basis 380px
|
||||
padding 0.75rem
|
||||
overflow hidden
|
||||
|
||||
.forum-search-result-header
|
||||
.posts-search-result-header
|
||||
horizontal
|
||||
|
||||
.forum-search-result-title
|
||||
.posts-search-result-title
|
||||
flex 1
|
||||
clip-long-text
|
||||
|
||||
.forum-search-result-author
|
||||
.posts-search-result-author
|
||||
text-align right
|
||||
opacity 0.5
|
||||
|
||||
.forum-search-result-sample
|
||||
.posts-search-result-sample
|
||||
clip-long-text
|
||||
margin-bottom 1rem
|
||||
opacity 0.8
|
||||
@ -43,4 +43,7 @@
|
||||
|
||||
.no-search-results
|
||||
text-align left
|
||||
padding-bottom typography-margin
|
||||
padding-bottom typography-margin
|
||||
|
||||
.search-section-disabled
|
||||
display none !important
|
Reference in New Issue
Block a user