Skip to content

Commit d4d790d

Browse files
committed
fix(frontend): avoid showing empty state while other lists are still loading
1 parent 90cb5b6 commit d4d790d

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

modules/core/js_modules/Hm_MessagesStore.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ class Hm_MessagesStore {
110110
$('.total_unread_count').html(' '+this.rows.length+' ');
111111
}
112112

113-
this.sort();
114-
this.saveToLocalStorage();
113+
this.sort();
114+
this.saveToLocalStorage();
115115

116116
if (messagesReadyCB) {
117117
messagesReadyCB(this);
118118
}
119119
};
120120

121-
this.fetch(hideLoadingState).forEach((req) => {
122-
req.then((response) => {
121+
await Promise.all(this.fetch(hideLoadingState).map((req) => {
122+
return req.then((response) => {
123123
pendingResponses.set(response.sourceId, response);
124124

125125
if (processingTimeout) {
@@ -128,10 +128,10 @@ class Hm_MessagesStore {
128128

129129
// Process after a short delay to allow batching
130130
processingTimeout = setTimeout(processPendingResponses, 10);
131-
}).catch((error) => {
131+
}, (error) => {
132132
console.error('Error loading messages from source:', error);
133133
});
134-
});
134+
}));
135135

136136
return this;
137137
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
function performSearch(routeParams) {
1+
async function performSearch(routeParams) {
22
if (routeParams.search_terms) {
33
const messages = new Hm_MessagesStore('search', Hm_Utils.get_url_page_number(), `${routeParams.search_terms}_${routeParams.search_fld}_${routeParams.search_since}`, routeParams.sort);
4-
messages.load(true, false, false, function() {
5-
display_imap_mailbox(messages.rows, messages.list, messages);
4+
await messages.load(true, false, false, function() {
5+
display_imap_mailbox(messages.rows, messages.list, messages, false);
66
});
7+
Hm_Message_List.check_empty_list();
78
}
89
}

modules/imap/site.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ async function select_imap_folder(path, page = 1, reload, processInTheBackground
428428
}
429429
});
430430
} else {
431-
display_imap_mailbox(messages.rows, messages.list, messages);
431+
display_imap_mailbox(messages.rows, messages.list, messages, false);
432432
}
433433

434434
showPagination(messages.pages);
@@ -445,6 +445,8 @@ async function select_imap_folder(path, page = 1, reload, processInTheBackground
445445
});
446446
});
447447

448+
Hm_Message_List.check_empty_list();
449+
448450
if (path === 'unread') {
449451
Hm_Message_List.set_unread_state();
450452
}
@@ -512,10 +514,14 @@ $(document).on('submit', '#imap_filter_form', async function(event) {
512514
}
513515
});
514516

515-
var display_imap_mailbox = function(rows, id, store) {
517+
var display_imap_mailbox = function(rows, id, store, checkEmptyState = true) {
516518
Hm_Message_List.toggle_msg_controls();
517519
Hm_Message_List.update(rows, id, store);
518-
Hm_Message_List.check_empty_list();
520+
521+
if (checkEmptyState) {
522+
Hm_Message_List.check_empty_list();
523+
}
524+
519525
$('input[type=checkbox]').on("click", function(e) {
520526
Hm_Message_List.toggle_msg_controls();
521527
});

0 commit comments

Comments
 (0)