diff --git a/app/assets/stylesheets/views/mod-center.scss b/app/assets/stylesheets/views/mod-center.scss index 2311dbcc1..5db39e451 100644 --- a/app/assets/stylesheets/views/mod-center.scss +++ b/app/assets/stylesheets/views/mod-center.scss @@ -169,3 +169,21 @@ margin-top: var(--su-6); margin-left: var(--su-3); } + +.mod-filter { + display: grid; + gap: var(--layout-gap); + grid-template-columns: var(--layout); + padding-top: var(--layout-padding); + padding-bottom: var(--layout-padding); + + &__item { + display: flex; + align-items: center; + } + + &__label { + font-weight: var(--fw-medium); + margin-right: var(--su-3); + } +} diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index f3bbb950b..e05cab682 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -5,7 +5,7 @@ class ModerationsController < ApplicationController SCORE_MAX = 5 JSON_OPTIONS = { - only: %i[id title published_at cached_tag_list path], + only: %i[id title published_at cached_tag_list path nth_published_by_author], include: { user: { only: %i[username name path articles_count id] } } @@ -16,6 +16,7 @@ class ModerationsController < ApplicationController return unless current_user&.trusted? @feed = params[:state] == "latest" ? "latest" : "inbox" + @members = params[:members].in?(%w[new not_new]) ? params[:members] : "all" articles = Article.published .order(published_at: :desc).limit(70) articles = articles.cached_tagged_with(params[:tag]) if params[:tag].present? @@ -26,9 +27,10 @@ class ModerationsController < ApplicationController .where("articles.score >= ? AND articles.score <= ?", SCORE_MIN, SCORE_MAX) .where(reactions: { id: nil }) end - if params[:state] == "new-authors" - articles = articles.where("nth_published_by_author > 0 AND nth_published_by_author < 4 AND published_at > ?", - 7.days.ago) + if @members == "new" + articles = articles.where("nth_published_by_author > 0 AND nth_published_by_author < 4") + elsif @members == "not_new" + articles = articles.where("nth_published_by_author > 3") end @articles = articles.includes(:user).to_json(JSON_OPTIONS) @tag = Tag.find_by(name: params[:tag]) || not_found if params[:tag].present? diff --git a/app/javascript/modCenter/moderationArticles.jsx b/app/javascript/modCenter/moderationArticles.jsx index 56ec5e6d7..c0cdce129 100644 --- a/app/javascript/modCenter/moderationArticles.jsx +++ b/app/javascript/modCenter/moderationArticles.jsx @@ -53,6 +53,7 @@ export class ModerationArticles extends Component { path, cached_tag_list: cachedTagList, published_at: publishedAt, + nth_published_by_author: nthPublishedByAuthor, user, } = article; return ( @@ -63,6 +64,7 @@ export class ModerationArticles extends Component { cachedTagList={cachedTagList} key={id} publishedAt={publishedAt} + nthPublishedByAuthor={nthPublishedByAuthor} user={user} articleOpened={id === prevSelectedArticleId} toggleArticle={this.toggleArticle} diff --git a/app/javascript/modCenter/singleArticle/__tests__/singleArticle.test.jsx b/app/javascript/modCenter/singleArticle/__tests__/singleArticle.test.jsx index fcd5ebd79..a1903afd2 100644 --- a/app/javascript/modCenter/singleArticle/__tests__/singleArticle.test.jsx +++ b/app/javascript/modCenter/singleArticle/__tests__/singleArticle.test.jsx @@ -14,6 +14,7 @@ const getTestArticle = () => ({ articles_count: 1, name: 'hello', }, + nthPublishedByAuthor: 1, }); describe('', () => { @@ -94,7 +95,7 @@ describe('', () => { expect(text).toContain(getTestArticle().user.name); }); - it('renders the hand wave emoji if the author has less than 3 articles', () => { + it("renders the hand wave emoji if the article is the author's first, second or third", () => { const { container } = render( diff --git a/app/javascript/modCenter/singleArticle/index.jsx b/app/javascript/modCenter/singleArticle/index.jsx index 34b53c1b2..c848fae34 100644 --- a/app/javascript/modCenter/singleArticle/index.jsx +++ b/app/javascript/modCenter/singleArticle/index.jsx @@ -7,6 +7,7 @@ export const SingleArticle = ({ title, publishedAt, cachedTagList, + nthPublishedByAuthor, user, key, articleOpened, @@ -28,7 +29,7 @@ export const SingleArticle = ({ const tags = cachedTagList.split(', ').map((tag) => tagsFormat(tag, key)); - const newAuthorNotification = user.articles_count <= 3 ? '👋 ' : ''; + const newAuthorNotification = nthPublishedByAuthor <= 3 ? '👋 ' : ''; return ( diff --git a/app/views/moderations/index.html.erb b/app/views/moderations/index.html.erb index 7117b2ee5..872caa851 100644 --- a/app/views/moderations/index.html.erb +++ b/app/views/moderations/index.html.erb @@ -21,6 +21,26 @@
<%= t("views.moderations.feed.#{@feed}_html") %>
+ <%= form_tag(request.path, method: :get, id: "members_filter_form") do %> +
+
+ + <%= select_tag :members, + options_for_select( + { + t("views.moderations.members.all") => "", + t("views.moderations.members.new") => "new", + t("views.moderations.members.established") => "not_new" + }, + params[:members], + ), + { class: "crayons-select crayons-input-sm", "aria-label": t("views.moderations.members.filter"), + onchange: "this.form.submit();" } %> + <%= hidden_field_tag :state, params[:state] %> +
+
+ <% end %> +