diff --git a/app/assets/javascripts/mobile/mobile.js b/app/assets/javascripts/mobile/mobile.js index 5cd873f13d56af1a4faa36352b70de25c3446047..0915480ad9627b522ad41cae22e2ea831311d9f8 100644 --- a/app/assets/javascripts/mobile/mobile.js +++ b/app/assets/javascripts/mobile/mobile.js @@ -18,6 +18,7 @@ //= require widgets/timeago //= require mobile/mobile_file_uploader //= require mobile/profile_aspects +//= require mobile/tag_following $(document).ready(function(){ diff --git a/app/assets/javascripts/mobile/tag_following.js b/app/assets/javascripts/mobile/tag_following.js new file mode 100644 index 0000000000000000000000000000000000000000..ef46ac984dd2dba089b119ce7e962e8e413bfd89 --- /dev/null +++ b/app/assets/javascripts/mobile/tag_following.js @@ -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})); + }); + } + }); +}); diff --git a/app/assets/stylesheets/mobile/mobile.scss b/app/assets/stylesheets/mobile/mobile.scss index 9040f6d23b1ed1a614808cb1aa01e80ff612ac3f..94bebc6b0b0955dff4973bf045cfecce30e216ea 100644 --- a/app/assets/stylesheets/mobile/mobile.scss +++ b/app/assets/stylesheets/mobile/mobile.scss @@ -1210,3 +1210,5 @@ select#aspect_ids_ { #app #main h1 { word-wrap: break-word; } + +.tag_following_action { margin: 5px 0 10px 0; } diff --git a/app/views/tags/show.mobile.haml b/app/views/tags/show.mobile.haml index 581af773a6a31ed980a874bd4cc2fad3ddfb042a..4afda991bc616e7bef7797a6ad159689700986e3 100644 --- a/app/views/tags/show.mobile.haml +++ b/app/views/tags/show.mobile.haml @@ -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 diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index a970052fedb6a5152859fdb9cd3834f5cab02c1f..0155b062e4d71f338fa2f76586805343fea3e3cc 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -206,6 +206,8 @@ en: follow: "Follow #<%= tag %>" following: "Following #<%= tag %>" stop_following: "Stop following #<%= tag %>" + follow_error: "Couldn’t follow <%= name %> :(" + stop_following_error: "Couldn’t stop following <%= name %> :(" header: home: "Home" diff --git a/features/mobile/tags.feature b/features/mobile/tags.feature index d1804deea85c17d55edc7145588bc725700a29c6..63a963de50d6ef89c0aa54e56d32a2d2b0ea6690 100644 --- a/features/mobile/tags.feature +++ b/features/mobile/tags.feature @@ -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"