diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 876b68a35..0fd7b25f7 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -150,6 +150,10 @@ class StoriesController < ApplicationController render template: "articles/index" end + def pinned_article + @pinned_article ||= PinnedArticle.get + end + def featured_story @featured_story ||= Articles::Feeds::LargeForemExperimental.find_featured_story(@stories) end @@ -239,6 +243,7 @@ class StoriesController < ApplicationController def assign_feed_stories feed = Articles::Feeds::LargeForemExperimental.new(page: @page, tag: params[:tag]) + if params[:timeframe].in?(Timeframe::FILTER_TIMEFRAMES) @stories = feed.top_articles_by_timeframe(timeframe: params[:timeframe]) elsif params[:timeframe] == Timeframe::LATEST_TIMEFRAME @@ -247,7 +252,10 @@ class StoriesController < ApplicationController @default_home_feed = true @featured_story, @stories = feed.default_home_feed_and_featured_story(user_signed_in: user_signed_in?) end + + @pinned_article = pinned_article&.decorate @featured_story = (featured_story || Article.new)&.decorate + @stories = ArticleDecorator.decorate_collection(@stories) end diff --git a/app/views/articles/_single_story.html.erb b/app/views/articles/_single_story.html.erb index 5a97be81f..20873ad1e 100644 --- a/app/views/articles/_single_story.html.erb +++ b/app/views/articles/_single_story.html.erb @@ -48,6 +48,14 @@ + + <% if local_assigns[:pinned] == true %> +
+ <%= inline_svg_tag("pin.svg", alt: "", aria_hidden: true, class: "mr-1 align-text-bottom color-accent-brand") %>Pinned +
+ <% end %>
diff --git a/app/views/stories/_main_stories_feed.html.erb b/app/views/stories/_main_stories_feed.html.erb index e719ec81e..7ab33e26e 100644 --- a/app/views/stories/_main_stories_feed.html.erb +++ b/app/views/stories/_main_stories_feed.html.erb @@ -1,5 +1,9 @@ -<% if @featured_story.id %> - <%= render "articles/single_story", story: @featured_story, featured: true %> +<% if @pinned_article %> + <%= render partial: "articles/single_story", locals: { story: @pinned_article, pinned: true, featured: @pinned_article.id == @featured_story.id } %> +<% end %> + +<% if @featured_story.id && @pinned_article&.id != @featured_story.id %> + <%= render partial: "articles/single_story", locals: { story: @featured_story, featured: true, pinned: false } %> <% end %>
@@ -8,10 +12,12 @@ <% if @stories.any? %> <% @stories.each_with_index do |story, i| %> <% next if story.id == @featured_story.id %> + <% next if story.id == @pinned_article&.id %> + <% if !user_signed_in? && i == 4 %> <%= render "stories/sign_in_invitation" %> <% end %> - <%= render "articles/single_story", story: story, featured: false %> + <%= render partial: "articles/single_story", locals: { story: story, featured: false, pinned: false } %> <% end %> <% if @stories.size > 1 %>
diff --git a/cypress/integration/articleFlows/pinArticle.spec.js b/cypress/integration/articleFlows/pinArticle.spec.js index 550a104e9..269e6bd8d 100644 --- a/cypress/integration/articleFlows/pinArticle.spec.js +++ b/cypress/integration/articleFlows/pinArticle.spec.js @@ -208,4 +208,17 @@ describe('Pin an article - Admin User', () => { .should('exist'); }); }); + + it('should show the pinned post to a logged out user', () => { + cy.findByRole('main').within(() => { + cy.findAllByRole('button', { name: 'Pin Post' }).first().click(); + + // check the button has changed to "Unpin Post" + cy.findAllByRole('button', { name: 'Unpin Post' }).first(); + }); + + cy.signOutUser(); + + cy.findByRole('main').findByTestId('pinned-article').should('be.visible'); + }); });