From 2d825739ca00af045b75272a301dea502e7c23d5 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 19 Jun 2019 18:57:22 +0900 Subject: [PATCH] Added groups to user profiles --- pages/profile/profile.go | 26 ++++++++++++++++++++++++++ pages/profile/profile.pixy | 14 +++++++++++++- pages/profile/profile.scarlet | 7 +++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/pages/profile/profile.go b/pages/profile/profile.go index 539d1b16..2e60e9c1 100644 --- a/pages/profile/profile.go +++ b/pages/profile/profile.go @@ -16,6 +16,7 @@ const ( maxCharacters = 6 maxFriends = 7 maxStudios = 4 + maxGroups = 5 ) // Get user profile page. @@ -155,6 +156,30 @@ func Profile(ctx aero.Context, viewUser *arn.User) error { dayToActivityCount[days+dayOffset]++ } + // Groups + groups := []*arn.Group{} + + for group := range arn.StreamGroups() { + if group.HasMember(viewUser.ID) { + groups = append(groups, group) + } + } + + sort.Slice(groups, func(i, j int) bool { + aMembers := len(groups[i].Members) + bMembers := len(groups[j].Members) + + if aMembers == bMembers { + return groups[i].Name < groups[j].Name + } + + return aMembers > bMembers + }) + + if len(groups) > maxGroups { + groups = groups[:maxGroups] + } + // Characters characters := []*arn.Character{} @@ -188,6 +213,7 @@ func Profile(ctx aero.Context, viewUser *arn.User) error { animeList, completedList, characters, + groups, friends, topGenres, topStudios, diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 7140656a..2f43d169 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -1,4 +1,4 @@ -component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, completedList *arn.AnimeList, characters []*arn.Character, friends []*arn.User, topGenres []string, topStudios []*arn.Company, animeWatchingTime time.Duration, dayToActivityCount map[int]int, uri string) +component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, completedList *arn.AnimeList, characters []*arn.Character, groups []*arn.Group, friends []*arn.User, topGenres []string, topStudios []*arn.Company, animeWatchingTime time.Duration, dayToActivityCount map[int]int, uri string) .profile ProfileHeader(viewUser, animeList, user, uri) @@ -29,6 +29,18 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, each character in characters .mountable(data-mountable-type="character") CharacterSmall(character, user) + + //- Groups + .profile-section + h3.profile-column-header.mountable(data-mountable-type="favorites") Groups + + if len(groups) == 0 + p.no-data.mountable(data-mountable-type="favorites") Nothing here yet. + else + .profile-groups.mountable(data-mountable-type="favorites") + each group in groups + a.profile-group.tip.mountable(href=group.Link(), aria-label=group.Name, data-mountable-type="group") + img.group-image.lazy(data-src=group.ImageLink("small"), data-webp=true, alt=group.Name) //- //- People //- .profile-section diff --git a/pages/profile/profile.scarlet b/pages/profile/profile.scarlet index 989d4403..97a3fcf1 100644 --- a/pages/profile/profile.scarlet +++ b/pages/profile/profile.scarlet @@ -84,6 +84,13 @@ const profile-image-size = 280px grid-gap 0.5rem justify-content space-evenly +.profile-groups + display grid + grid-template-columns repeat(auto-fill, 70px) + grid-template-rows repeat(auto-fill, 70px) + grid-gap 0.5rem + justify-content space-evenly + .profile-introduction a color white