Added liking for soundtracks

This commit is contained in:
Allen Lydiard 2017-11-05 14:54:58 -04:00
parent be4ea860d4
commit 6835cbe0d3
4 changed files with 31 additions and 16 deletions

14
mixins/TabLike.pixy Normal file
View File

@ -0,0 +1,14 @@
component TabLike(label string, icon string, track *arn.SoundTrack, user *arn.User)
if user == nil
a.tab.action(aria-label=label)
Icon(icon)
span.tab-text= label
else
if track.LikedBy(user.ID)
a.tab.action(data-api="/api" + track.Link(), data-action="unlike", data-trigger="click", aria-label=label)
Icon(icon)
span.tab-text= label
else
a.tab.action(data-api="/api" + track.Link(), data-action="like", data-trigger="click", aria-label=label)
Icon(icon)
span.tab-text= label

View File

@ -34,5 +34,5 @@ func Edit(ctx *aero.Context) string {
ctx.Data.(*arn.OpenGraph).Tags["og:image"] = track.MainAnime().Image.Large ctx.Data.(*arn.OpenGraph).Tags["og:image"] = track.MainAnime().Image.Large
} }
return ctx.HTML(components.SoundTrackTabs(track) + editform.Render(track, "Edit soundtrack", user)) return ctx.HTML(components.SoundTrackTabs(track, user) + editform.Render(track, "Edit soundtrack", user))
} }

View File

@ -6,12 +6,14 @@ import (
"github.com/aerogo/aero" "github.com/aerogo/aero"
"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"
) )
// Get track. // Get track.
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
id := ctx.Get("id") id := ctx.Get("id")
track, err := arn.GetSoundTrack(id) track, err := arn.GetSoundTrack(id)
user := utils.GetUser(ctx)
if err != nil { if err != nil {
return ctx.Error(http.StatusNotFound, "Track not found", err) return ctx.Error(http.StatusNotFound, "Track not found", err)
@ -39,5 +41,5 @@ func Get(ctx *aero.Context) string {
ctx.Data = openGraph ctx.Data = openGraph
return ctx.HTML(components.Track(track)) return ctx.HTML(components.Track(track, user))
} }

View File

@ -1,5 +1,5 @@
component Track(track *arn.SoundTrack) component Track(track *arn.SoundTrack, user *arn.User)
SoundTrackTabs(track) SoundTrackTabs(track, user)
.sound-track-full-page .sound-track-full-page
if track.Title == "" if track.Title == ""
@ -29,13 +29,11 @@ component Track(track *arn.SoundTrack)
for index, beatmap := range track.Beatmaps() for index, beatmap := range track.Beatmaps()
li li
a.beatmap(href="https://osu.ppy.sh/s/" + beatmap, target="_blank")= "Beatmap #" + strconv.Itoa(index + 1) a.beatmap(href="https://osu.ppy.sh/s/" + beatmap, target="_blank")= "Beatmap #" + strconv.Itoa(index + 1)
.widget.mountable .widget.mountable
h3.widget-title Tags h3.widget-title Tags
.tags .tags
each tag in track.Tags each tag in track.Tags
.tag= tag .tag= tag
.footer.text-center.mountable .footer.text-center.mountable
if track.EditedBy != "" if track.EditedBy != ""
span Edited span Edited
@ -50,7 +48,8 @@ component Track(track *arn.SoundTrack)
span . span .
component SoundTrackTabs(track *arn.SoundTrack) component SoundTrackTabs(track *arn.SoundTrack, user *arn.User)
.tabs .tabs
Tab("Soundtrack", "music", track.Link()) Tab("Soundtrack", "music", track.Link())
Tab("Edit", "pencil", track.Link() + "/edit") Tab("Edit", "pencil", track.Link() + "/edit")
TabLike(strconv.Itoa(len(track.Likes)), "heart", track, user)