From 290c18b8b9de28f9ba2fa89882ecfb75a1379b09 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 19 Apr 2018 17:48:15 +0200 Subject: [PATCH] See friends who liked a character --- pages/character/character.go | 15 ++++++++++++++- pages/character/character.pixy | 16 ++++++++++++++-- pages/character/character.scarlet | 4 ++++ utils/Intersection.go | 16 ++++++++++++++++ utils/routetests/All.go | 4 ++++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 utils/Intersection.go diff --git a/pages/character/character.go b/pages/character/character.go index b284f29f..36b4f171 100644 --- a/pages/character/character.go +++ b/pages/character/character.go @@ -67,5 +67,18 @@ func Get(ctx *aero.Context) string { }, } - return ctx.HTML(components.CharacterDetails(character, characterAnime, quotes, mainQuote, user)) + // Friends + friendIDs := utils.Intersection(character.Likes, user.Follows().Items) + friendObjects := arn.DB.GetMany("User", friendIDs) + friends := []*arn.User{} + + for _, obj := range friendObjects { + if obj == nil { + continue + } + + friends = append(friends, obj.(*arn.User)) + } + + return ctx.HTML(components.CharacterDetails(character, characterAnime, quotes, friends, mainQuote, user)) } diff --git a/pages/character/character.pixy b/pages/character/character.pixy index 244c4226..119616ad 100644 --- a/pages/character/character.pixy +++ b/pages/character/character.pixy @@ -4,7 +4,7 @@ component CharacterTabs(character *arn.Character, user *arn.User) Tab("Edit", "pencil", character.Link() + "/edit") Tab("History", "history", character.Link() + "/history") -component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime, quotes []*arn.Quote, mainQuote *arn.Quote, user *arn.User) +component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime, quotes []*arn.Quote, friends []*arn.User, mainQuote *arn.Quote, user *arn.User) .character-page .character-left-column .character-header @@ -66,6 +66,19 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime else td.character-attributes-value= attribute.Value + if len(friends) > 0 + .character-friends + h3.mountable Friends + + .user-avatars.mountable + each friend in friends + .mountable(data-mountable-type="friend") + if friend.IsActive() + Avatar(friend) + else + .inactive-user + Avatar(friend) + if character.GetMapping("myanimelist/character") != "" h3.mountable Links @@ -77,4 +90,3 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime a.light-button(href="/api" + character.Link(), target="_blank") Icon("code") span API - diff --git a/pages/character/character.scarlet b/pages/character/character.scarlet index 0e00103a..df09f31c 100644 --- a/pages/character/character.scarlet +++ b/pages/character/character.scarlet @@ -56,6 +56,10 @@ .quote-footer display none +.character-friends + .user-avatars + justify-content flex-start + > 1250px .character-page horizontal diff --git a/utils/Intersection.go b/utils/Intersection.go new file mode 100644 index 00000000..eebf6ade --- /dev/null +++ b/utils/Intersection.go @@ -0,0 +1,16 @@ +package utils + +import "github.com/animenotifier/arn" + +// Intersection returns common elements of a and b. +func Intersection(a []string, b []string) []string { + var c []string + + for _, obj := range a { + if arn.Contains(b, obj) { + c = append(c, obj) + } + } + + return c +} diff --git a/utils/routetests/All.go b/utils/routetests/All.go index f133e69b..84dfda35 100644 --- a/utils/routetests/All.go +++ b/utils/routetests/All.go @@ -6,6 +6,10 @@ var routeTests = map[string][]string{ "/+Akyoto", }, + "/user/:nick/characters/liked": []string{ + "/+Akyoto/characters/liked", + }, + "/user/:nick/forum/threads": []string{ "/+Akyoto/forum/threads", },