diff --git a/main.go b/main.go index 59c7fc71..07e61e83 100644 --- a/main.go +++ b/main.go @@ -65,6 +65,7 @@ func configure(app *aero.Application) *aero.Application { app.Ajax("/user/:nick", profile.Get) app.Ajax("/user/:nick/threads", profile.GetThreadsByUser) app.Ajax("/user/:nick/posts", profile.GetPostsByUser) + app.Ajax("/user/:nick/tracks", profile.GetSoundTracksByUser) app.Ajax("/user/:nick/animelist", animelist.Get) app.Ajax("/user/:nick/animelist/:id", animelistitem.Get) app.Ajax("/new/thread", newthread.Get) diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index fee38873..aebde1c9 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -86,7 +86,8 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, .post-likes= len(post.Likes) .profile-category.mountable - h3 Tracks + h3 + a.ajax(href="/+" + viewUser.Nick + "/tracks", title="View all tracks") Tracks if len(tracks) == 0 p No soundtracks posted yet. diff --git a/pages/profile/tracks.go b/pages/profile/tracks.go new file mode 100644 index 00000000..abf825a1 --- /dev/null +++ b/pages/profile/tracks.go @@ -0,0 +1,32 @@ +package profile + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// GetSoundTracksByUser shows all soundtracks of a particular user. +func GetSoundTracksByUser(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) + } + + tracks, err := arn.GetSoundTracksByUser(viewUser) + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Error fetching soundtracks", err) + } + + arn.SortSoundTracksLatestFirst(tracks) + + return ctx.HTML(components.TrackList(tracks, viewUser, user)) + +} diff --git a/pages/profile/tracks.pixy b/pages/profile/tracks.pixy new file mode 100644 index 00000000..f554fca8 --- /dev/null +++ b/pages/profile/tracks.pixy @@ -0,0 +1,6 @@ +component TrackList(tracks []*arn.SoundTrack, viewUser *arn.User, user *arn.User) + h2= "Tracks added by " + viewUser.Nick + .sound-tracks + each track in tracks + SoundTrack(track) + \ No newline at end of file