From 1bd572cf3cb52e2d8422de00cfe8d2c2cba7fbf4 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 17 Nov 2018 05:33:40 +0900 Subject: [PATCH] Started working on activity likes --- pages/activity/activity.pixy | 16 ++++++++++++---- pages/profile/profile.pixy | 24 ++++++++++++------------ utils/ActivityLink.go | 22 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 utils/ActivityLink.go diff --git a/pages/activity/activity.pixy b/pages/activity/activity.pixy index 4e6c6d87..09431454 100644 --- a/pages/activity/activity.pixy +++ b/pages/activity/activity.pixy @@ -26,7 +26,7 @@ component ActivitiesScrollable(entries []arn.Activity, user *arn.User) Activity(entry, user) component Activity(activity arn.Activity, user *arn.User) - .activity.post-parent.mountable(id=fmt.Sprintf("activity-%s", activity.GetID())) + .activity.post-parent.mountable(id=fmt.Sprintf("activity-%s", activity.GetID()), data-api=utils.ActivityAPILink(activity)) .post-author Avatar(activity.Creator()) .post-content @@ -37,9 +37,17 @@ component Activity(activity arn.Activity, user *arn.User) else if activity.TypeName() == "ActivityConsumeAnime" ActivityConsumeAnimeTitle(activity.(*arn.ActivityConsumeAnime), user) - if user != nil && user.ID == activity.GetCreatedBy() && activity.TypeName() == "ActivityConsumeAnime" - button.activity-action.tip.action(data-action="deleteObject", data-trigger="click", aria-label="Delete", data-return-path="/activity", data-confirm-type="activity", data-api=fmt.Sprintf("/api/%s/%s", strings.ToLower(activity.TypeName()), activity.GetID())) - RawIcon("trash") + if user != nil + //- button.activity-action.tip.action(data-action="like", data-trigger="click", aria-label="Like") + //- Icon("heart") + //- if activity.TypeName() == "ActivityCreate" + //- span= activity.(*arn.ActivityCreate).Object().CountLikes() + //- else + //- span= len(activity.(*arn.ActivityConsumeAnime).Likes) + + if user.ID == activity.GetCreatedBy() && activity.TypeName() == "ActivityConsumeAnime" + button.activity-action.tip.action(data-action="deleteObject", data-trigger="click", aria-label="Delete", data-return-path="/activity", data-confirm-type="activity") + RawIcon("trash") .activity-date.utc-date(data-date=activity.GetCreated()) diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 9f290030..0de63bfe 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -50,6 +50,18 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, each genre in topGenres a.anime-genre.mountable(href="/genre/" + strings.ToLower(genre), data-mountable-type="genre")= genre + //- Friends + .profile-section.profile-section-friends + h3.profile-column-header.mountable(data-mountable-type="extra") Friends + + if len(friends) == 0 + p.no-data.mountable(data-mountable-type="extra") Nothing here yet. + else + .profile-friends.mountable(data-mountable-type="extra") + each friend in friends + .profile-friend.mountable(data-mountable-type="friend") + Avatar(friend) + //- Activity .profile-section.profile-section-activity h3.profile-column-header.mountable(data-mountable-type="extra") Activity @@ -68,18 +80,6 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, if day == 2 .spacer-box - //- Friends - .profile-section - h3.profile-column-header.mountable(data-mountable-type="extra") Friends - - if len(friends) == 0 - p.no-data.mountable(data-mountable-type="extra") Nothing here yet. - else - .profile-friends.mountable(data-mountable-type="extra") - each friend in friends - .profile-friend.mountable(data-mountable-type="friend") - Avatar(friend) - component ProfileHeader(viewUser *arn.User, user *arn.User, uri string) ProfileHead(viewUser, user, uri) diff --git a/utils/ActivityLink.go b/utils/ActivityLink.go new file mode 100644 index 00000000..bb154474 --- /dev/null +++ b/utils/ActivityLink.go @@ -0,0 +1,22 @@ +package utils + +import ( + "fmt" + "strings" + + "github.com/animenotifier/arn" +) + +// ActivityAPILink returns the API link for any activity. +func ActivityAPILink(activity arn.Activity) string { + id := activity.GetID() + typeName := activity.TypeName() + + if activity.TypeName() == "ActivityCreate" { + created := activity.(*arn.ActivityCreate) + typeName = created.ObjectType + id = created.ObjectID + } + + return fmt.Sprintf("/api/%s/%s", strings.ToLower(typeName), id) +}