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,6 +1,6 @@
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 == ""
h1.mountable untitled h1.mountable untitled
@ -13,7 +13,7 @@ component Track(track *arn.SoundTrack)
h3.widget-title= media.Service h3.widget-title= media.Service
.sound-track-media .sound-track-media
ExternalMedia(media) ExternalMedia(media)
.widget.mountable .widget.mountable
h3.widget-title Anime h3.widget-title Anime
@ -21,7 +21,7 @@ component Track(track *arn.SoundTrack)
each anime in track.Anime() each anime in track.Anime()
a.sound-track-anime-list-item.ajax(href=anime.Link(), title=anime.Title.Canonical) a.sound-track-anime-list-item.ajax(href=anime.Link(), title=anime.Title.Canonical)
img.sound-track-anime-list-item-image.lazy(data-src=anime.Image.Tiny, alt=anime.Title.Canonical) img.sound-track-anime-list-item-image.lazy(data-src=anime.Image.Tiny, alt=anime.Title.Canonical)
if len(track.Beatmaps()) > 0 if len(track.Beatmaps()) > 0
.widget.mountable .widget.mountable
h3.widget-title Beatmaps h3.widget-title Beatmaps
@ -29,28 +29,27 @@ 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
span.utc-date(data-date=track.Edited) span.utc-date(data-date=track.Edited)
span by span by
span= track.EditedByUser().Nick span= track.EditedByUser().Nick
else else
span Posted span Posted
span.utc-date(data-date=track.Created) span.utc-date(data-date=track.Created)
span by span by
span= track.Creator().Nick span= track.Creator().Nick
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)