Show liked soundtracks #54
This commit is contained in:
Eduard Urbach 2018-03-14 16:19:12 +01:00 committed by GitHub
commit 30080861c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 15 deletions

View File

@ -169,7 +169,10 @@ func Configure(app *aero.Application) {
l.Page("/user/:nick", profile.Get) l.Page("/user/:nick", profile.Get)
l.Page("/user/:nick/forum/threads", profile.GetThreadsByUser) l.Page("/user/:nick/forum/threads", profile.GetThreadsByUser)
l.Page("/user/:nick/forum/posts", profile.GetPostsByUser) l.Page("/user/:nick/forum/posts", profile.GetPostsByUser)
l.Page("/user/:nick/soundtracks", profile.GetSoundTracksByUser) l.Page("/user/:nick/soundtracks/added", profile.GetSoundTracksByUser)
l.Page("/user/:nick/soundtracks/added/from/:index", profile.GetSoundTracksByUser)
l.Page("/user/:nick/soundtracks/liked", profile.GetSoundTracksLikedByUser)
l.Page("/user/:nick/soundtracks/liked/from/:index", profile.GetSoundTracksLikedByUser)
l.Page("/user/:nick/stats", profile.GetStatsByUser) l.Page("/user/:nick/stats", profile.GetStatsByUser)
l.Page("/user/:nick/followers", profile.GetFollowers) l.Page("/user/:nick/followers", profile.GetFollowers)
l.Page("/user/:nick/animelist", animelist.Get) l.Page("/user/:nick/animelist", animelist.Get)

View File

@ -26,12 +26,16 @@ component ProfileTabs(viewUser *arn.User, uri string)
Tab("Anime", "th", "/+" + viewUser.Nick) Tab("Anime", "th", "/+" + viewUser.Nick)
Tab("Collection", "list", "/+" + viewUser.Nick + "/animelist/watching") Tab("Collection", "list", "/+" + viewUser.Nick + "/animelist/watching")
Tab("Forum", "comment", "/+" + viewUser.Nick + "/forum/threads") Tab("Forum", "comment", "/+" + viewUser.Nick + "/forum/threads")
Tab("Tracks", "music", "/+" + viewUser.Nick + "/soundtracks") Tab("Tracks", "music", "/+" + viewUser.Nick + "/soundtracks/liked")
Tab("Stats", "area-chart", "/+" + viewUser.Nick + "/stats") Tab("Stats", "area-chart", "/+" + viewUser.Nick + "/stats")
Tab("Followers", "users", "/+" + viewUser.Nick + "/followers") Tab("Followers", "users", "/+" + viewUser.Nick + "/followers")
if strings.Contains(uri, "/animelist") if strings.Contains(uri, "/animelist")
StatusTabs("/+" + viewUser.Nick + "/animelist") StatusTabs("/+" + viewUser.Nick + "/animelist")
if strings.Contains(uri, "/soundtracks")
.tabs
Tab("Liked", "heart", "/+" + viewUser.Nick + "/soundtracks/liked")
Tab("Added", "music", "/+" + viewUser.Nick + "/soundtracks/added")
component ProfileHeader(viewUser *arn.User, user *arn.User, uri string) component ProfileHeader(viewUser *arn.User, user *arn.User, uri string)
ProfileHead(viewUser, user, uri) ProfileHead(viewUser, user, uri)

View File

@ -7,6 +7,7 @@ import (
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils"
"github.com/animenotifier/notify.moe/utils/infinitescroll"
) )
// GetSoundTracksByUser shows all soundtracks of a particular user. // GetSoundTracksByUser shows all soundtracks of a particular user.
@ -19,12 +20,67 @@ func GetSoundTracksByUser(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "User not found", err) return ctx.Error(http.StatusNotFound, "User not found", err)
} }
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool { index, _ := ctx.GetInt("index")
return !track.IsDraft && len(track.Media) > 0 && track.CreatedBy == viewUser.ID
})
arn.SortSoundTracksLatestFirst(tracks) // Fetch all eligible tracks
allTracks := fetchAllByUser(viewUser.ID)
return ctx.HTML(components.TrackList(tracks, viewUser, user, ctx.URI())) // Sort the tracks by publication date
arn.SortSoundTracksLatestFirst(allTracks)
// Slice the part that we need
tracks := allTracks[index:]
if len(tracks) > maxTracks {
tracks = tracks[:maxTracks]
}
// Next index
nextIndex := infinitescroll.NextIndex(ctx, len(allTracks), maxTracks, index)
// In case we're scrolling, send soundtracks only (without the page frame)
if index > 0 {
return ctx.HTML(components.SoundTracksScrollable(tracks, user))
}
// Otherwise, send the full page
return ctx.HTML(components.TrackList(tracks, viewUser, nextIndex, user, ctx.URI()))
} }
// GetSoundTracksLikedByUser shows all soundtracks liked by a particular user.
func GetSoundTracksLikedByUser(ctx *aero.Context) string {
nick := ctx.Get("nick")
user := utils.GetUser(ctx)
viewUser, err := arn.GetUserByNick(nick)
if err != nil {
return ctx.Error(http.StatusNotFound, "User not found", err)
}
index, _ := ctx.GetInt("index")
// Fetch all eligible tracks
allTracks := fetchAllLikedByUser(viewUser.ID)
// Sort the tracks by publication date
arn.SortSoundTracksLatestFirst(allTracks)
// Slice the part that we need
tracks := allTracks[index:]
if len(tracks) > maxTracks {
tracks = tracks[:maxTracks]
}
// Next index
nextIndex := infinitescroll.NextIndex(ctx, len(allTracks), maxTracks, index)
// In case we're scrolling, send soundtracks only (without the page frame)
if index > 0 {
return ctx.HTML(components.SoundTracksScrollable(tracks, user))
}
// Otherwise, send the full page
return ctx.HTML(components.TrackList(tracks, viewUser, nextIndex, user, ctx.URI()))
}

View File

@ -1,12 +1,18 @@
component TrackList(tracks []*arn.SoundTrack, viewUser *arn.User, user *arn.User, uri string) component TrackList(tracks []*arn.SoundTrack, viewUser *arn.User, nextIndex int, user *arn.User, uri string)
ProfileHeader(viewUser, user, uri) ProfileHeader(viewUser, user, uri)
if strings.Contains(uri, "/added")
h1.page-title= "Tracks added by " + viewUser.Nick h1.page-title= "Tracks added by " + viewUser.Nick
else
h1.page-title= "Tracks liked by " + viewUser.Nick
if len(tracks) == 0 if len(tracks) == 0
p.no-data.mountable= viewUser.Nick + " hasn't added any tracks yet." p.no-data.mountable= viewUser.Nick + " hasn't added any tracks yet."
else else
.soundtracks #load-more-target.soundtracks
each track in tracks SoundTracksScrollable(tracks, user)
SoundTrack(track)
if nextIndex != -1
.buttons
LoadMore(nextIndex)

View File

@ -14,8 +14,20 @@ var routeTests = map[string][]string{
"/+Akyoto/forum/posts", "/+Akyoto/forum/posts",
}, },
"/user/:nick/soundtracks": []string{ "/user/:nick/soundtracks/added": []string{
"/+Akyoto/soundtracks", "/+Akyoto/soundtracks/added",
},
"/user/:nick/soundtracks/added/from/:index": []string{
"/+Akyoto/soundtracks/added/from/3",
},
"/user/:nick/soundtracks/liked": []string{
"/+Akyoto/soundtracks/liked",
},
"/user/:nick/soundtracks/liked/from/:index": []string{
"/+Akyoto/soundtracks/liked/from/3",
}, },
"/user/:nick/followers": []string{ "/user/:nick/followers": []string{