diff --git a/pages/index.go b/pages/index.go index effb57fe..493e7542 100644 --- a/pages/index.go +++ b/pages/index.go @@ -170,7 +170,9 @@ func Configure(app *aero.Application) { l.Page("/user/:nick/forum/threads", profile.GetThreadsByUser) l.Page("/user/:nick/forum/posts", profile.GetPostsByUser) 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/followers", profile.GetFollowers) l.Page("/user/:nick/animelist", animelist.Get) diff --git a/pages/profile/tracks.go b/pages/profile/tracks.go index 2be2db8d..f2ba841e 100644 --- a/pages/profile/tracks.go +++ b/pages/profile/tracks.go @@ -7,6 +7,7 @@ import ( "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" + "github.com/animenotifier/notify.moe/utils/infinitescroll" ) // GetSoundTracksByUser shows all soundtracks of a particular user. @@ -19,17 +20,35 @@ func GetSoundTracksByUser(ctx *aero.Context) string { return ctx.Error(http.StatusNotFound, "User not found", err) } - tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool { - return !track.IsDraft && len(track.Media) > 0 && track.CreatedBy == viewUser.ID - }) + index, _ := ctx.GetInt("index") - 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 number of likes + 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())) } -// GetSoundTracksByUser shows all soundtracks of a particular user. +// GetSoundTracksLikedByUser shows all soundtracks of a particular user. func GetSoundTracksLikedByUser(ctx *aero.Context) string { nick := ctx.Get("nick") user := utils.GetUser(ctx) @@ -39,12 +58,29 @@ func GetSoundTracksLikedByUser(ctx *aero.Context) string { return ctx.Error(http.StatusNotFound, "User not found", err) } - tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool { - return !track.IsDraft && len(track.Media) > 0 && track.LikedBy(viewUser.ID) - }) + index, _ := ctx.GetInt("index") - arn.SortSoundTracksLatestFirst(tracks) + // Fetch all eligible tracks + allTracks := fetchAllLikedByUser(viewUser.ID) - return ctx.HTML(components.TrackList(tracks, viewUser, user, ctx.URI())) + // Sort the tracks by number of likes + 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())) } diff --git a/pages/profile/tracks.pixy b/pages/profile/tracks.pixy index 1b4d3f9f..5ce54191 100644 --- a/pages/profile/tracks.pixy +++ b/pages/profile/tracks.pixy @@ -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) - h1.page-title= "Tracks added by " + viewUser.Nick - + if strings.Contains(uri, "/added") + h1.page-title= "Tracks added by " + viewUser.Nick + else + h1.page-title= "Tracks liked by " + viewUser.Nick + if len(tracks) == 0 p.no-data.mountable= viewUser.Nick + " hasn't added any tracks yet." else - .soundtracks - each track in tracks - SoundTrack(track) + #load-more-target.soundtracks + SoundTracksScrollable(tracks, user) + + if nextIndex != -1 + .buttons + LoadMore(nextIndex) \ No newline at end of file