Improved post UI

This commit is contained in:
Eduard Urbach 2019-08-30 11:42:46 +09:00
parent 2894a92af1
commit 3ba9b8bf3b
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
6 changed files with 55 additions and 38 deletions

View File

@ -35,13 +35,19 @@ func LikeAction() *api.Action {
return errors.New("Drafts need to be published before they can be liked") return errors.New("Drafts need to be published before they can be liked")
} }
likeable := obj.(Likeable)
user := GetUserFromContext(ctx) user := GetUserFromContext(ctx)
if user == nil { if user == nil {
return errors.New("Not logged in") return errors.New("Not logged in")
} }
postable, isPostable := obj.(Postable)
if isPostable && postable.Creator().ID == user.ID {
return errors.New("You can't like your own posts")
}
likeable := obj.(Likeable)
likeable.Like(user.ID) likeable.Like(user.ID)
// Call OnLike if the object implements it // Call OnLike if the object implements it

View File

@ -4,11 +4,11 @@ component Postable(post arn.Postable, user *arn.User, includeReplies bool, showP
.post-author .post-author
Avatar(post.Creator()) Avatar(post.Creator())
.post-content(data-highlight=post.Creator().ID == highlightAuthorID) .post-box(data-highlight=post.Creator().ID == highlightAuthorID)
.post-header .post-header
.post-creator .post-header-info
a(href=post.Creator().Link())= post.Creator().Nick a(href=post.Creator().Link())= post.Creator().Nick
if showParent if showParent
if post.GetParentType() == "User" if post.GetParentType() == "User"
if post.GetParentID() != post.Creator().ID if post.GetParentID() != post.Creator().ID
@ -17,35 +17,23 @@ component Postable(post arn.Postable, user *arn.User, includeReplies bool, showP
else if post.GetParentType() != "" else if post.GetParentType() != ""
span in span in
a(href=post.Parent().Link())= post.Parent().TitleByUser(user) a(href=post.Parent().Link())= post.Parent().TitleByUser(user)
if user == nil || user.ID == post.Creator().ID
//- Don't display a like icon.
else if post.LikedBy(user.ID)
button.post-action.post-likes.tip.action(id="unlike-" + post.GetID(), aria-label="Unlike", data-action="unlike", data-trigger="click")
RawIcon("heart")
else
button.post-action.post-likes.tip.action(id="like-" + post.GetID(), aria-label="Like", data-action="like", data-trigger="click")
RawIcon("heart-o")
if user != nil if user != nil
button.post-action.tip.action(data-post-id=post.GetID(), aria-label="Reply", data-action="reply", data-trigger="click")
RawIcon("reply")
if user.ID == post.Creator().ID if user.ID == post.Creator().ID
button.post-action.tip.action(data-action="editPost", data-trigger="click", data-id=post.GetID(), aria-label="Edit") button.post-action.post-header-action.tip.action(data-action="editPost", data-trigger="click", data-id=post.GetID(), aria-label="Edit")
RawIcon("pencil") RawIcon("pencil")
if post.TypeName() != "Thread" if post.TypeName() != "Thread"
if user != nil && (user.Role == "admin" || user.Role == "editor") if user != nil && (user.Role == "admin" || user.Role == "editor")
button.post-action.tip.action(data-action="deletePost", data-trigger="click", data-id=post.GetID(), aria-label="Delete") button.post-action.post-header-action.tip.action(data-action="deletePost", data-trigger="click", data-id=post.GetID(), aria-label="Delete")
RawIcon("trash") RawIcon("trash")
a.post-action.tip(href=post.Link(), aria-label="Link") a.post-action.post-header-action.tip(href=post.Link(), aria-label="Link")
RawIcon("link") RawIcon("link")
.post-date.utc-date(data-date=post.GetCreated()) .post-date.utc-date(data-date=post.GetCreated())
div(id="render-" + post.GetID())!= post.HTML() .post-content(id="render-" + post.GetID())!= post.HTML()
if user != nil && user.ID == post.Creator().ID if user != nil && user.ID == post.Creator().ID
.post-edit-interface .post-edit-interface
@ -63,6 +51,21 @@ component Postable(post arn.Postable, user *arn.User, includeReplies bool, showP
Icon("close") Icon("close")
span Cancel span Cancel
.post-toolbar
if user != nil
button.post-action.post-toolbar-action.tip.action(data-post-id=post.GetID(), aria-label="Reply", data-action="reply", data-trigger="click")
Icon("reply")
span= post.CountPosts()
if user != nil && post.LikedBy(user.ID)
button.post-action.post-toolbar-action.tip.action(id="unlike-" + post.GetID(), aria-label="Unlike", data-action="unlike", data-trigger="click", data-like="true")
Icon("heart")
span= post.CountLikes()
else
button.post-action.post-toolbar-action.tip.action(id="like-" + post.GetID(), aria-label="Like", data-action="like", data-trigger="click", data-like="false")
Icon("heart-o")
span= post.CountLikes()
.replies(id="replies-" + post.GetID()) .replies(id="replies-" + post.GetID())
if includeReplies if includeReplies
each reply in post.Posts() each reply in post.Posts()

View File

@ -36,7 +36,7 @@ component Activity(activity arn.Activity, user *arn.User)
//- Avatar(activity.Creator()) //- Avatar(activity.Creator())
//- .post-content //- .post-content
//- .post-header //- .post-header
//- .post-creator //- .post-header-info
//- a(href=activity.Creator().Link())= activity.Creator().Nick //- a(href=activity.Creator().Link())= activity.Creator().Nick
//- if activity.TypeName() == "ActivityCreate" //- if activity.TypeName() == "ActivityCreate"

View File

@ -4,6 +4,7 @@ component Post(post *arn.Post, user *arn.User)
Postable(post, user, true, true, "") Postable(post, user, true, true, "")
if user != nil && user.Role == "admin" if user != nil && user.Role == "admin"
.side-note-container.mountable .buttons
a.side-note.tip(href=post.Link() + "/edit", aria-label="Admin Edit") a.button.mountable(href=post.Link() + "/edit")
Icon("edit") Icon("edit")
span Edit (admin)

View File

@ -1,6 +0,0 @@
.side-note-container
horizontal
justify-content flex-end
.side-note
font-size 0.9rem

View File

@ -10,8 +10,9 @@ post-content-padding-y = 0.75rem
horizontal horizontal
horizontal-line-bottom horizontal-line-bottom
.post-creator .post-header-info
flex 1 flex 1
clip-long-text
.post-action .post-action
display flex display flex
@ -20,23 +21,26 @@ post-content-padding-y = 0.75rem
background none background none
padding 0 padding 0
height auto height auto
margin-right 0.5rem
opacity 0
color hsla(text-color-h, text-color-s, text-color-l, 0.5) color hsla(text-color-h, text-color-s, text-color-l, 0.5)
:hover :hover
color link-hover-color color link-hover-color
background none background none
.post-header-action
opacity 0
margin-right 0.5rem
.post-date .post-date
color hsla(text-color-h, text-color-s, text-color-l, 0.5) color hsla(text-color-h, text-color-s, text-color-l, 0.5)
white-space nowrap white-space nowrap
.post-content .post-box
ui-element ui-element
flex-grow 1 flex-grow 1
padding 0.75rem 1rem padding 0.75rem 1rem
position relative position relative
overflow hidden
h1, h2, h3 h1, h2, h3
font-weight bold font-weight bold
@ -60,9 +64,22 @@ post-content-padding-y = 0.75rem
object-fit cover object-fit cover
:hover :hover
.post-action .post-header-action
opacity 1 opacity 1
.post-toolbar
horizontal
justify-content flex-end
margin-top typography-margin
padding-top typography-margin
border-top 1px solid reverse-light-color
.post-toolbar-action
margin-left 1rem
[data-like="true"]
color hsla(0, 90%, 50%, 1)
.new-post-actions .new-post-actions
justify-content flex-end justify-content flex-end
opacity 0 opacity 0
@ -82,10 +99,6 @@ post-content-padding-y = 0.75rem
button button
pointer-events all pointer-events all
.post-likes
color hsla(text-color-h, text-color-s, text-color-l, 0.4)
margin-right 0.4em
.post-edit-interface .post-edit-interface
vertical vertical