Merge pull request #38372 from ShrihariMahabal/load-notifications-on-demand

perf: load notifications and events on demand
This commit is contained in:
Shrihari Mahabal 2026-04-08 22:24:03 +05:30 committed by GitHub
commit 4c94239b1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 58 additions and 26 deletions

View file

@ -34,7 +34,6 @@ frappe.ui.Notifications = class Notifications {
</span>`)
.on("click", (e) => {
e.stopImmediatePropagation();
console.log("what");
frappe.set_route("Form", "Notification Settings", frappe.session.user);
})
.appendTo(this.header_actions)
@ -224,15 +223,13 @@ class NotificationsView extends BaseNotificationsView {
.tooltip({ delay: { show: 600, hide: 100 }, trigger: "hover" });
this.setup_notification_listeners();
this.get_notifications_list(this.max_length).then((r) => {
if (!r.message) return;
this.dropdown_items = r.message.notification_logs;
frappe.update_user_info(r.message.user_info);
this.render_notifications_dropdown();
if (this.settings.seen == 0 && this.dropdown_items.length > 0) {
this.dropdown_items = [];
this.notifications_fetched = false;
if (this.settings && this.settings.seen == 0) {
this.toggle_notification_icon(false);
}
});
}
update_dropdown() {
@ -347,7 +344,7 @@ class NotificationsView extends BaseNotificationsView {
<div class="full-log-btn">${__("See all Activity")}</div>
</a>`);
} else {
this.container.append(
this.container.html(
$(`<div class="notification-null-state">
<div class="text-center">
<img src="/assets/frappe/images/ui-states/notification-empty-state.svg" alt="Generic Empty State" class="null-state">
@ -408,6 +405,24 @@ class NotificationsView extends BaseNotificationsView {
});
this.parent.on("show.bs.dropdown", () => {
if (!this.notifications_fetched) {
this.container.html(`<div class="notification-null-state">
<div class="text-center">
<div class="spinner-border spinner-border-sm text-muted"></div>
</div>
</div>`);
this.get_notifications_list(this.max_length).then((r) => {
if (r.message && r.message.notification_logs) {
this.dropdown_items = r.message.notification_logs;
frappe.update_user_info(r.message.user_info);
} else {
this.dropdown_items = [];
}
this.render_notifications_dropdown();
this.notifications_fetched = true;
});
}
this.toggle_seen(true);
if (this.notifications_icon.find(".notifications-unseen").is(":visible")) {
this.toggle_notification_icon(true);
@ -421,6 +436,17 @@ class NotificationsView extends BaseNotificationsView {
class EventsView extends BaseNotificationsView {
make() {
this.events_fetched = false;
this.parent.on("show.bs.dropdown", () => {
if (this.events_fetched) return;
this.container.html(`<div class="notification-null-state">
<div class="text-center">
<div class="spinner-border spinner-border-sm text-muted"></div>
</div>
</div>`);
let today = frappe.datetime.get_today();
frappe
.xcall(
@ -434,6 +460,8 @@ class EventsView extends BaseNotificationsView {
)
.then((event_list) => {
this.render_events_html(event_list);
this.events_fetched = true;
});
});
}

View file

@ -484,7 +484,11 @@ frappe.ui.Sidebar = class Sidebar {
type: "Button",
class: "sidebar-notification hidden",
onClick: () => {
this.wrapper.find(".dropdown-notifications").toggleClass("hidden");
const $dropdown = this.wrapper.find(".dropdown-notifications");
$dropdown.toggleClass("hidden");
if (!$dropdown.hasClass("hidden")) {
$dropdown.trigger("show.bs.dropdown");
}
if (frappe.is_mobile()) {
this.wrapper.removeClass("expanded");
}