From c33a8d658b31aae2d8ae7b7bb307e18191e0867d Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 16 Jan 2024 09:50:55 +0800 Subject: [PATCH] DEV: Avoid duplicating constant between client and server (#25179) Why this change? While the constant does not change very often, we should still avoid duplicating the value of a constant used on the server side in the client side to avoid the values going out of sync. --- .../discourse/app/components/user-menu/notifications-list.js | 3 ++- app/assets/javascripts/discourse/app/lib/constants.js | 2 ++ lib/tasks/javascript.rake | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/components/user-menu/notifications-list.js b/app/assets/javascripts/discourse/app/components/user-menu/notifications-list.js index e62d28d7255..1b4bf291cd6 100644 --- a/app/assets/javascripts/discourse/app/components/user-menu/notifications-list.js +++ b/app/assets/javascripts/discourse/app/components/user-menu/notifications-list.js @@ -3,6 +3,7 @@ import { inject as service } from "@ember/service"; import DismissNotificationConfirmationModal from "discourse/components/modal/dismiss-notification-confirmation"; import UserMenuItemsList from "discourse/components/user-menu/items-list"; import { ajax } from "discourse/lib/ajax"; +import { MAX_NOTIFICATIONS_LIMIT_PARAMS } from "discourse/lib/constants"; import UserMenuNotificationItem from "discourse/lib/user-menu/notification-item"; import UserMenuReviewableItem from "discourse/lib/user-menu/reviewable-item"; import { @@ -13,7 +14,7 @@ import Notification from "discourse/models/notification"; import UserMenuReviewable from "discourse/models/user-menu-reviewable"; import I18n from "discourse-i18n"; -const MAX_LIMIT = 60; +const MAX_LIMIT = MAX_NOTIFICATIONS_LIMIT_PARAMS; const DEFAULT_LIMIT = 30; let limit = DEFAULT_LIMIT; diff --git a/app/assets/javascripts/discourse/app/lib/constants.js b/app/assets/javascripts/discourse/app/lib/constants.js index 37c744941c5..6b447258089 100644 --- a/app/assets/javascripts/discourse/app/lib/constants.js +++ b/app/assets/javascripts/discourse/app/lib/constants.js @@ -68,3 +68,5 @@ export const AUTO_GROUPS = { display_name: "trust_level_4", }, }; + +export const MAX_NOTIFICATIONS_LIMIT_PARAMS = 60; diff --git a/lib/tasks/javascript.rake b/lib/tasks/javascript.rake index 5abfad215df..0e63464091d 100644 --- a/lib/tasks/javascript.rake +++ b/lib/tasks/javascript.rake @@ -160,6 +160,8 @@ task "javascript:update_constants" => :environment do } export const AUTO_GROUPS = #{auto_groups.to_json}; + + export const MAX_NOTIFICATIONS_LIMIT_PARAMS = #{NotificationsController::INDEX_LIMIT}; JS pretty_notifications = Notification.types.map { |n| " #{n[0]}: #{n[1]}," }.join("\n")