Skip to content

Commit

Permalink
Merge pull request #7520 from svbergerem/increase-mobile-post-action-…
Browse files Browse the repository at this point in the history
…size

Include count in mobile post action link and increase reshare counter after reshare
  • Loading branch information
SuperTux88 committed Aug 9, 2017
2 parents 05a4bf2 + bc0088e commit eefa670
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ If so, please delete it since it will prevent the federation from working proper
* Send public profiles publicly [#7501](https://github.com/diaspora/diaspora/pull/7501)
* Change sender for mails [#7495](https://github.com/diaspora/diaspora/pull/7495)
* Move back to top to the right to avoid misclicks [#7516](https://github.com/diaspora/diaspora/pull/7516)
* Include count in mobile post action link [#7520](https://github.com/diaspora/diaspora/pull/7520)

## Bug fixes

* Fix height too high on mobile SPV [#7480](https://github.com/diaspora/diaspora/pull/7480)
* Improve stream when ignoring a person who posts a lot of tagged posts [#7503](https://github.com/diaspora/diaspora/pull/7503)
* Fix order of comments across pods [#7436](https://github.com/diaspora/diaspora/pull/7436)
* Prevent publisher from closing in preview mode [#7518](https://github.com/diaspora/diaspora/pull/7518)
* Increase reshare counter after reshare on mobile [#7520](https://github.com/diaspora/diaspora/pull/7520)

## Features
* Add support for mentions in comments to the backend [#6818](https://github.com/diaspora/diaspora/pull/6818)
Expand Down
8 changes: 6 additions & 2 deletions app/assets/javascripts/mobile/mobile_post_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

onLike: function(evt){
evt.preventDefault();
var link = $(evt.target),
var link = $(evt.target).closest(".like-action"),
likeCounter = $(evt.target).closest(".stream-element").find(".like-count");

if(!link.hasClass("loading") && link.hasClass("inactive")) {
Expand All @@ -89,7 +89,7 @@
onReshare: function(evt) {
evt.preventDefault();

var link = $(this),
var link = $(this).closest(".reshare-action"),
href = link.attr("href"),
confirmText = link.attr("title");

Expand All @@ -103,6 +103,10 @@
},
success: function() {
Diaspora.Mobile.PostActions.toggleActive(link);
var reshareCounter = $(evt.target).closest(".stream-element").find(".reshare-count");
if (reshareCounter) {
reshareCounter.text(parseInt(reshareCounter.text(), 10) + 1);
}
},
error: function(response) {
Diaspora.Mobile.Alert.handleAjaxError(response);
Expand Down
12 changes: 7 additions & 5 deletions app/assets/stylesheets/mobile/comments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@
display: flex;

.count {
color: $text-color;
font-family: $font-family-base;
font-size: $font-size-base;
line-height: 22px;
margin-left: 5px;
vertical-align: top;
z-index: 2;
}

.icon-count-group {
display: flex;
margin: 0 7px;
}

[class^="entypo"] {
color: $text-grey;
font-size: 24px;
Expand All @@ -73,6 +72,9 @@
}

.post-action {
display: flex;
margin: 0 7px;

.disabled { color: $medium-gray; }
}

Expand Down
19 changes: 13 additions & 6 deletions app/helpers/mobile_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,40 @@ def mobile_reshare_icon(post)
reshare = Reshare.where(author_id: current_user.person_id,
root_guid: absolute_root.guid).first
klass = reshare.present? ? "active" : "inactive"
link_to "", reshares_path(root_guid: absolute_root.guid),
link_to content_tag(:span, post.reshares.size, class: "count reshare-count"),
reshares_path(root_guid: absolute_root.guid),
title: t("reshares.reshare.reshare_confirmation", author: absolute_root.author_name),
class: "entypo-reshare reshare-action #{klass}"
else
content_tag :div, nil, class: "entypo-reshare reshare-action disabled"
content_tag :div,
content_tag(:span, post.reshares.size, class: "count reshare-count"),
class: "entypo-reshare reshare-action disabled"
end
else
content_tag :div, nil, class: "entypo-reshare reshare-action disabled"
content_tag :div,
content_tag(:span, post.reshares.size, class: "count reshare-count"),
class: "entypo-reshare reshare-action disabled"
end
end

def mobile_like_icon(post)
if current_user && current_user.liked?(post)
link_to "",
link_to content_tag(:span, post.likes.size, class: "count like-count"),
"#",
data: {url: post_like_path(post.id, current_user.like_for(post).id)},
class: "entypo-heart like-action active"
else
link_to "",
link_to content_tag(:span, post.likes.size, class: "count like-count"),
"#",
data: {url: post_likes_path(post.id)},
class: "entypo-heart like-action inactive"
end
end

def mobile_comment_icon(post)
link_to "", new_post_comment_path(post), class: "entypo-comment comment-action inactive"
link_to content_tag(:span, post.comments.size, class: "count comment-count"),
new_post_comment_path(post),
class: "entypo-comment comment-action inactive"
end

def show_comments_link(post, klass="")
Expand Down
15 changes: 6 additions & 9 deletions app/views/comments/_post_stats.mobile.haml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
.post-stats
- if post.public?
.icon-count-group
.post-action= mobile_reshare_icon(post)
%span.reshare-count.count= post.reshares.size
.post-action
= mobile_reshare_icon(post)

.icon-count-group
.post-action= mobile_comment_icon(post)
%span.comment-count.count= post.comments.size
.post-action
= mobile_comment_icon(post)

.icon-count-group
.post-action= mobile_like_icon(post)
%span.like-count.count= post.likes.size
.post-action
= mobile_like_icon(post)
15 changes: 13 additions & 2 deletions spec/javascripts/mobile/mobile_post_actions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("Diaspora.Mobile.PostActions", function(){
spec.loadFixture("aspects_index_mobile_public_post");
Diaspora.Mobile.PostActions.initialize();
this.link = $(".stream .like-action").first();
this.likeCounter = this.link.closest(".stream-element").find(".like-count");
this.likeCounter = this.link.find(".like-count");
});

it("always calls showLoader before sending request", function(){
Expand Down Expand Up @@ -143,7 +143,7 @@ describe("Diaspora.Mobile.PostActions", function(){
spec.loadFixture("aspects_index_mobile_public_post");
Diaspora.Mobile.PostActions.initialize();
this.link = $(".stream .like-action").first();
this.likeCounter = this.link.closest(".stream-element").find(".like-count");
this.likeCounter = this.link.find(".like-count");
Diaspora.Mobile.PostActions.like(this.likeCounter, this.link);
jasmine.Ajax.requests.mostRecent().respondWith({status: 201, responseText: "{\"id\": \"18\"}"});
});
Expand Down Expand Up @@ -238,6 +238,17 @@ describe("Diaspora.Mobile.PostActions", function(){
expect(Diaspora.Mobile.PostActions.toggleActive).toHaveBeenCalledWith(this.reshareLink);
});

it("increases the reshare count on success", function() {
spyOn(Diaspora.Mobile.PostActions, "toggleActive");
var reshareCounter = this.reshareLink.find(".reshare-count");
reshareCounter.text("8");

this.reshareLink.click();
jasmine.Ajax.requests.mostRecent().respondWith({status: 201, responseText: "{}"});
expect(Diaspora.Mobile.PostActions.toggleActive).toHaveBeenCalledWith(this.reshareLink);
expect(reshareCounter.text()).toBe("9");
});

it("lets Diaspora.Mobile.Alert handle AJAX errors", function() {
spyOn(Diaspora.Mobile.Alert, "handleAjaxError");
this.reshareLink.click();
Expand Down

0 comments on commit eefa670

Please sign in to comment.