Make announcements appear faster

This commit is contained in:
Lim Chee Aun 2023-05-21 08:46:51 +08:00
parent 904e82872e
commit da46171ef6

View file

@ -103,14 +103,11 @@ function Notifications() {
setUIState('loading'); setUIState('loading');
(async () => { (async () => {
try { try {
const fetchNotificationsPromise = fetchNotifications(firstLoad);
const fetchFollowRequestsPromise = fetchFollowRequests(); const fetchFollowRequestsPromise = fetchFollowRequests();
const fetchAnnouncementsPromise = fetchAnnouncements(); const fetchAnnouncementsPromise = fetchAnnouncements();
const { done } = await fetchNotifications(firstLoad);
setShowMore(!done);
if (firstLoad) { if (firstLoad) {
const requests = await fetchFollowRequestsPromise;
setFollowRequests(requests);
const announcements = await fetchAnnouncementsPromise; const announcements = await fetchAnnouncementsPromise;
announcements.sort((a, b) => { announcements.sort((a, b) => {
// Sort by updatedAt first, then createdAt // Sort by updatedAt first, then createdAt
@ -119,8 +116,13 @@ function Notifications() {
return bDate - aDate; return bDate - aDate;
}); });
setAnnouncements(announcements); setAnnouncements(announcements);
const requests = await fetchFollowRequestsPromise;
setFollowRequests(requests);
} }
const { done } = await fetchNotificationsPromise;
setShowMore(!done);
setUIState('default'); setUIState('default');
} catch (e) { } catch (e) {
setUIState('error'); setUIState('error');