Added soundtracks to dashboard

This commit is contained in:
Eduard Urbach 2017-06-27 16:51:27 +02:00
parent 990a8032f3
commit 064a3e1fa5
3 changed files with 40 additions and 21 deletions

View File

@ -11,6 +11,7 @@ import (
const maxPosts = 5
const maxFollowing = 5
const maxSoundTracks = 5
// Get the dashboard or the frontpage when logged out.
func Get(ctx *aero.Context) string {
@ -26,22 +27,43 @@ func Get(ctx *aero.Context) string {
// Render the dashboard.
func dashboard(ctx *aero.Context) string {
var posts []*arn.Post
var err error
var userList interface{}
var followingList []*arn.User
var soundTracks []*arn.SoundTrack
user := utils.GetUser(ctx)
flow.Parallel(func() {
var err error
posts, err = arn.AllPosts()
if err != nil {
return
}
arn.SortPostsLatestFirst(posts)
posts = arn.FilterPostsWithUniqueThreads(posts, maxPosts)
}, func() {
// threads, err = arn.AllThreadsSlice()
// arn.SortPostsLatestFirst(posts)
// posts = arn.FilterPostsWithUniqueThreads(posts, maxPosts)
var err error
soundTracks, err = arn.AllSoundTracks()
if err != nil {
return
}
arn.SortSoundTracksLatestFirst(soundTracks)
if len(soundTracks) > maxSoundTracks {
soundTracks = soundTracks[:maxSoundTracks]
}
}, func() {
var err error
userList, err = arn.DB.GetMany("User", user.Following)
if err != nil {
return
}
followingList = userList.([]*arn.User)
followingList = arn.SortUsersLastSeen(followingList)
@ -50,9 +72,5 @@ func dashboard(ctx *aero.Context) string {
}
})
if err != nil {
return ctx.Error(500, "Error displaying dashboard", err)
}
return ctx.HTML(components.Dashboard(posts, followingList))
return ctx.HTML(components.Dashboard(posts, soundTracks, followingList))
}

View File

@ -1,4 +1,4 @@
component Dashboard(posts []*arn.Post, following []*arn.User)
component Dashboard(posts []*arn.Post, soundTracks []*arn.SoundTrack, following []*arn.User)
h2.page-title Dash
.widgets
@ -30,12 +30,18 @@ component Dashboard(posts []*arn.Post, following []*arn.User)
span ...
.widget.mountable
h3.widget-title Messages
h3.widget-title Soundtracks
for i := 1; i <= 5; i++
for i := 0; i <= 4; i++
if i < len(soundTracks)
a.widget-element.ajax(href="/music")
.widget-element-text
Icon("music")
span= soundTracks[i].MainAnime().Title.Canonical
else
.widget-element
.widget-element-text
Icon("comment")
Icon("music")
span ...
.widget.mountable

View File

@ -2,7 +2,6 @@ package music
import (
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
@ -19,10 +18,6 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusInternalServerError, "Error fetching soundtracks", err)
}
sort.Slice(tracks, func(i, j int) bool {
return tracks[i].Created > tracks[j].Created
})
if len(tracks) > maxTracks {
tracks = tracks[:maxTracks]
}