Mobile: Add button to follow/unfollow tags

This commit is contained in:
Steffen van Bergerem 2015-05-08 23:46:21 +02:00 committed by Dennis Schubert
parent 59e57c013b
commit 1428369849
6 changed files with 78 additions and 5 deletions

View file

@ -18,6 +18,7 @@
//= require widgets/timeago
//= require mobile/mobile_file_uploader
//= require mobile/profile_aspects
//= require mobile/tag_following
$(document).ready(function(){

View file

@ -0,0 +1,43 @@
$(document).ready(function(){
$(".tag_following_action").bind("tap click", function(evt){
evt.preventDefault();
var button = $(this),
tagName = button.data("name");
if(button.hasClass("btn-success")){
$.ajax({
url: Routes.tag_followings_path(),
data: JSON.stringify({"name": tagName}),
type: "POST",
dataType: "json",
headers: {
"Accept": "application/json, text/javascript, */*; q=0.01"
},
contentType: "application/json; charset=UTF-8"
}).done(function(data) {
gon.preloads.tagFollowings.push(data);
button.removeClass("btn-success").addClass("btn-danger");
button.text(Diaspora.I18n.t("stream.tags.stop_following", {tag: tagName}));
}).fail(function() {
alert(Diaspora.I18n.t("stream.tags.follow_error", {name: "#" + tagName}));
});
}
else if(button.hasClass("btn-danger")){
var tagFollowing = _.findWhere(gon.preloads.tagFollowings,{name: tagName});
if(!tagFollowing) { return; }
$.ajax({
url: Routes.tag_following_path(tagFollowing.id),
dataType: "json",
type: "DELETE",
headers: {
"Accept": "application/json, text/javascript, */*; q=0.01"
}
}).done(function() {
button.removeClass("btn-danger").addClass("btn-success");
button.text(Diaspora.I18n.t("stream.tags.follow", {tag: tagName}));
}).fail(function() {
alert(Diaspora.I18n.t("stream.tags.stop_following_error", {name: "#" + tagName}));
});
}
});
});

View file

@ -1210,3 +1210,5 @@ select#aspect_ids_ {
#app #main h1 {
word-wrap: break-word;
}
.tag_following_action { margin: 5px 0 10px 0; }

View file

@ -4,6 +4,13 @@
%h1
= @stream.display_tag_name
- if user_signed_in?
- unless tag_followed?
.btn.btn-success.tag_following_action{data: {name: @stream.tag_name}}
= t(".follow", tag: @stream.tag_name)
- else
.btn.btn-danger.tag_following_action{data: {name: @stream.tag_name}}
= t(".stop_following", tag: @stream.tag_name)
#main_stream.stream
= render 'shared/stream', :posts => @stream.stream_posts

View file

@ -206,6 +206,8 @@ en:
follow: "Follow #<%= tag %>"
following: "Following #<%= tag %>"
stop_following: "Stop following #<%= tag %>"
follow_error: "Couldnt follow <%= name %> :("
stop_following_error: "Couldnt stop following <%= name %> :("
header:
home: "Home"

View file

@ -2,13 +2,31 @@
Feature: Interacting with tags
Background:
Given a user with username "alice"
And "alice@alice.alice" has a public post with text "Hello! i am #newhere"
When I sign in as "alice@alice.alice"
Given following users exist:
| username |
| bob |
| alice |
And "alice@alice.alice" has a public post with text "Hello! I am #newhere"
When I sign in as "bob@bob.bob"
And I visit the mobile search page
And I fill in the following:
| q | #newhere |
And I press "Search"
Then I should see "Follow #newhere" within ".tag_following_action"
Scenario: Start and stop following a tag
When I click on selector ".tag_following_action"
Then I should see "Stop following #newhere" within ".tag_following_action"
When I am on the home page
Then I should see "Hello! I am #newhere"
Scenario: Searching for a tag
When I visit the mobile search page
And I fill in the following:
| q | #newhere |
And I press "Search"
Then I should see "#newhere" within ".ltr"
Then I should see "Stop following #newhere" within ".tag_following_action"
When I click on selector ".tag_following_action"
Then I should see "Follow #newhere" within ".tag_following_action"
When I am on the home page
Then I should not see "Hello! I am #newhere"