Implemented group image upload

This commit is contained in:
2018-11-22 10:27:53 +09:00
parent f8be03d4c5
commit 1c7e4d0290
10 changed files with 161 additions and 58 deletions

9
pages/groups/fetch.go Normal file
View File

@ -0,0 +1,9 @@
package groups
import "github.com/animenotifier/arn"
func fetchGroups() []*arn.Group {
return arn.FilterGroups(func(group *arn.Group) bool {
return !group.IsDraft
})
}

View File

@ -1,40 +0,0 @@
package groups
import (
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
const groupsPerPage = 12
// Get ...
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
groups, err := arn.FilterGroups(func(group *arn.Group) bool {
return !group.IsDraft
})
sort.Slice(groups, func(i, j int) bool {
if len(groups[i].Members) == len(groups[j].Members) {
return groups[i].Created > groups[j].Created
}
return len(groups[i].Members) > len(groups[j].Members)
})
if len(groups) > groupsPerPage {
groups = groups[:groupsPerPage]
}
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Error fetching groups", err)
}
return ctx.HTML(components.Groups(groups, groupsPerPage, user))
}

View File

@ -1,4 +1,4 @@
component Groups(groups []*arn.Group, groupsPerPage int, user *arn.User)
component Groups(groups []*arn.Group, nextIndex int, user *arn.User)
.tabs
Tab("Groups", "users", "/groups")
@ -16,17 +16,20 @@ component Groups(groups []*arn.Group, groupsPerPage int, user *arn.User)
span Edit draft
#load-more-target.groups
each group in groups
a.group.mountable(href=group.Link())
img.group-image.lazy(data-src=group.ImageLink("small"), data-webp="true", data-color=group.AverageColor(), alt=group.Name)
.group-info
h3.group-name= group.Name
.group-tagline= group.Tagline
.group-member-count
Icon("user")
span= len(group.Members)
GroupsScrollable(groups, user)
if len(groups) == groupsPerPage
if nextIndex != -1
.buttons
LoadMore(groupsPerPage)
LoadMore(nextIndex)
component GroupsScrollable(groups []*arn.Group, user *arn.User)
each group in groups
a.group.mountable(href=group.Link())
img.group-image.lazy(data-src=group.ImageLink("small"), data-webp="true", data-color=group.AverageColor(), alt=group.Name)
.group-info
h3.group-name= group.Name
.group-tagline= group.Tagline
.group-member-count
Icon("user")
span= len(group.Members)

View File

@ -14,8 +14,6 @@ const group-padding-x = 0.75rem
horizontal
ui-element
position relative
// width 100%
// max-width 520px
padding group-padding-y group-padding-x
color text-color
@ -29,8 +27,6 @@ const group-padding-x = 0.75rem
overflow hidden
.group-name
// horizontal
// align-items center
clip-long-text
.group-tagline

18
pages/groups/latest.go Normal file
View File

@ -0,0 +1,18 @@
package groups
import (
"sort"
"github.com/aerogo/aero"
)
// Latest shows the latest groups.
func Latest(ctx *aero.Context) string {
groups := fetchGroups()
sort.Slice(groups, func(i, j int) bool {
return groups[i].Created > groups[j].Created
})
return render(ctx, groups)
}

22
pages/groups/popular.go Normal file
View File

@ -0,0 +1,22 @@
package groups
import (
"sort"
"github.com/aerogo/aero"
)
// Popular shows the most popular groups.
func Popular(ctx *aero.Context) string {
groups := fetchGroups()
sort.Slice(groups, func(i, j int) bool {
if len(groups[i].Members) == len(groups[j].Members) {
return groups[i].Created > groups[j].Created
}
return len(groups[i].Members) > len(groups[j].Members)
})
return render(ctx, groups)
}

43
pages/groups/render.go Normal file
View File

@ -0,0 +1,43 @@
package groups
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
"github.com/animenotifier/notify.moe/utils/infinitescroll"
)
const (
groupsFirstLoad = 12
groupsPerScroll = 9
)
// render renders the groups page with the given groups.
func render(ctx *aero.Context, allGroups []*arn.Group) string {
user := utils.GetUser(ctx)
index, _ := ctx.GetInt("index")
// Slice the part that we need
groups := allGroups[index:]
maxLength := groupsFirstLoad
if index > 0 {
maxLength = groupsPerScroll
}
if len(groups) > maxLength {
groups = groups[:maxLength]
}
// Next index
nextIndex := infinitescroll.NextIndex(ctx, len(allGroups), maxLength, index)
// In case we're scrolling, send groups only (without the page frame)
if index > 0 {
return ctx.HTML(components.GroupsScrollable(groups, user))
}
// Otherwise, send the full page
return ctx.HTML(components.Groups(groups, nextIndex, user))
}