Merge pull request #16 from FM1337/go

Updated dashboard
This commit is contained in:
Eduard Urbach 2017-06-26 18:59:43 +02:00 committed by GitHub
commit 8a080f1156

View File

@ -2,6 +2,7 @@ package dashboard
import ( import (
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/aerogo/flow"
"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/pages/frontpage" "github.com/animenotifier/notify.moe/pages/frontpage"
@ -11,7 +12,6 @@ import (
const maxPosts = 5 const maxPosts = 5
const maxFollowing = 5 const maxFollowing = 5
// Get dashboard.
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx) user := utils.GetUser(ctx)
@ -19,32 +19,41 @@ func Get(ctx *aero.Context) string {
return frontpage.Get(ctx) return frontpage.Get(ctx)
} }
posts, err := arn.AllPostsSlice() return Dashboard(ctx)
}
if err != nil { // Get dashboard.
return ctx.Error(500, "Error fetching posts", err) func Dashboard(ctx *aero.Context) string {
} var posts []*arn.Post
var err error
arn.SortPostsLatestFirst(posts) var followIDList []string
var userList interface{}
if len(posts) > maxPosts {
posts = posts[:maxPosts]
}
followIDList := user.Following
var followingList []*arn.User var followingList []*arn.User
user := utils.GetUser(ctx)
if len(followIDList) > maxFollowing { flow.Parallel(func() {
followIDList = followIDList[:maxFollowing] posts, err = arn.AllPostsSlice()
} arn.SortPostsLatestFirst(posts)
userList, err := arn.DB.GetMany("User", followIDList) if len(posts) > maxPosts {
posts = posts[:maxPosts]
}
}, func() {
followIDList = user.Following
userList, err = arn.DB.GetMany("User", followIDList)
followingList = userList.([]*arn.User)
followingList = arn.SortUsersLastSeen(followingList)
if len(followingList) > maxFollowing {
followingList = followingList[:maxFollowing]
}
})
if err != nil { if err != nil {
return ctx.Error(500, "Error fetching followed users", err) return ctx.Error(500, "Error displaying dashboard", err)
} }
followingList = userList.([]*arn.User)
return ctx.HTML(components.Dashboard(posts, followingList)) return ctx.HTML(components.Dashboard(posts, followingList))
} }