diff --git a/app/controllers/admin/articles_controller.rb b/app/controllers/admin/articles_controller.rb index d380e1034..bdd196609 100644 --- a/app/controllers/admin/articles_controller.rb +++ b/app/controllers/admin/articles_controller.rb @@ -18,8 +18,6 @@ module Admin published_at].freeze def index - @pinned_article = PinnedArticle.get - case params[:state] when /top-/ months_ago = params[:state].split("-")[1].to_i.months.ago @@ -30,6 +28,9 @@ module Admin @articles = articles_mixed @featured_articles = articles_featured end + + @pinned_article = PinnedArticle.get + @articles = @articles.where.not(id: @pinned_article) if @pinned_article end def show @@ -55,7 +56,7 @@ module Admin respond_to do |format| format.html do - flash[:success] = I18n.t("admin.articles_controller.pinned") + flash[:danger] = I18n.t("admin.articles_controller.unpinned") redirect_to admin_article_path(article.id) end format.js do diff --git a/app/javascript/admin/controllers/article_controller.js b/app/javascript/admin/controllers/article_controller.js index 7c6f041c8..fb59b87de 100644 --- a/app/javascript/admin/controllers/article_controller.js +++ b/app/javascript/admin/controllers/article_controller.js @@ -6,7 +6,6 @@ export default class ArticleController extends Controller { 'featuredNumber', 'cardBody', 'pinnedCheckbox', - 'unpinButton', ]; static values = { id: Number, pinPath: String }; @@ -74,11 +73,15 @@ export default class ArticleController extends Controller { } } - ajaxSuccess(event) { - if (event.target !== this.unpinButtonTarget) { - return; - } + async unpinArticle(event) { + const unpinArticleForm = event.target; + // We dont want to submit the pin form here. + event.preventDefault(); + unpinArticleForm.submit(); + } + + ajaxSuccess(event) { // Replace the current Article HTML with the HTML sent by the server const newArticle = document.createElement('div'); diff --git a/app/views/admin/articles/_individual_article.html.erb b/app/views/admin/articles/_individual_article.html.erb index 8324f5047..6bc234c22 100644 --- a/app/views/admin/articles/_individual_article.html.erb +++ b/app/views/admin/articles/_individual_article.html.erb @@ -73,14 +73,14 @@
<% if decorated_article.pinned? %> - <%= link_to( - "Unpin post", - unpin_admin_article_path(decorated_article.id), - method: :delete, - remote: true, - class: "c-link c-link--block", - data: { "article-target": "unpinButton" }, - ) %> +
+ + + +
<% else %>
diff --git a/config/locales/controllers/admin/en.yml b/config/locales/controllers/admin/en.yml index 57bb1f57a..a9266118f 100644 --- a/config/locales/controllers/admin/en.yml +++ b/config/locales/controllers/admin/en.yml @@ -4,6 +4,7 @@ en: articles_controller: saved: Article saved! pinned: Article Pinned! + unpinned: Article Unpinned! badge_achievements_controller: deleted: Badge achievement has been deleted! rewarded: Badges are being rewarded. The task will finish shortly. diff --git a/config/locales/controllers/admin/fr.yml b/config/locales/controllers/admin/fr.yml index 86969ea30..df57c48b7 100644 --- a/config/locales/controllers/admin/fr.yml +++ b/config/locales/controllers/admin/fr.yml @@ -4,6 +4,7 @@ fr: articles_controller: saved: Article saved! pinned: Article Pinned! + unpinned: Article Unpinned! badge_achievements_controller: deleted: Badge achievement has been deleted! rewarded: Badges are being rewarded. The task will finish shortly. diff --git a/cypress/integration/seededFlows/adminFlows/articles/pinArticle.spec.js b/cypress/integration/seededFlows/adminFlows/articles/pinArticle.spec.js index f69b97457..3e01e39fe 100644 --- a/cypress/integration/seededFlows/adminFlows/articles/pinArticle.spec.js +++ b/cypress/integration/seededFlows/adminFlows/articles/pinArticle.spec.js @@ -36,7 +36,7 @@ describe('Pin an article from the admin area', () => { cy.url().should('contain', '/content_manager/articles/'); cy.findByRole('button', { name: 'Pin post' }).should('not.exist'); - cy.findByRole('link', { name: 'Unpin post' }).should('exist'); + cy.findByRole('button', { name: 'Unpin post' }).should('exist'); cy.findByTestId('pinned-indicator').should('exist'); }); @@ -96,7 +96,7 @@ describe('Pin an article from the admin area', () => { it('should show the pinned post to a logged out user', () => { cy.findAllByRole('button', { name: 'Pin post' }).first().click(); - cy.findByRole('link', { name: 'Unpin post' }).should('exist'); + cy.findByRole('button', { name: 'Unpin post' }).should('exist'); cy.signOutUser(); cy.findAllByRole('link', { name: 'Log in' }).first().should('exist'); diff --git a/cypress/integration/seededFlows/adminFlows/articles/unpinArticle.spec.js b/cypress/integration/seededFlows/adminFlows/articles/unpinArticle.spec.js index 518b69f2b..8ac5d4ee1 100644 --- a/cypress/integration/seededFlows/adminFlows/articles/unpinArticle.spec.js +++ b/cypress/integration/seededFlows/adminFlows/articles/unpinArticle.spec.js @@ -25,15 +25,15 @@ describe('Unpin an article from the admin area', () => { }); it('should not display the "Unpin post" button by default', () => { - cy.findByRole('link', { name: 'Unpin post' }).should('not.exist'); + cy.findByRole('button', { name: 'Unpin post' }).should('not.exist'); }); it('should unpin the pinned article', () => { cy.findAllByRole('button', { name: 'Pin post' }).first().click(); - cy.findAllByRole('link', { name: 'Unpin post' }).first().click(); + cy.findAllByRole('button', { name: 'Unpin post' }).first().click(); - cy.findAllByRole('link', { name: 'Unpin post' }).should('not.exist'); + cy.findAllByRole('button', { name: 'Unpin post' }).should('not.exist'); cy.findByTestId('pinned-indicator').should('not.exist'); }); });