flyzto 1 周之前
父節點
當前提交
7c534dc866
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      pinnacle/libs/globalData.js

+ 6 - 2
pinnacle/libs/globalData.js

@@ -79,15 +79,19 @@ const isEventAvailable = (event) => {
   return startsTime >= Date.now() - 3 * 60 * 60 * 1000 && startsTime <= tomorrowEndTime;
 }
 
+const sortEventsByStarts = (events) => {
+  return events.sort((a, b) => new Date(a.starts).getTime() - new Date(b.starts).getTime());
+}
+
 export const getEventsByIds = (ids) => {
   const normalizedIds = normalizeIds(ids);
   const { gamesMap={} } = GLOBAL_DATA;
 
   if (!normalizedIds.length) {
-    return Object.values(gamesMap).filter(isEventAvailable);
+    return sortEventsByStarts(Object.values(gamesMap).filter(isEventAvailable));
   }
 
-  return normalizedIds.map(id => gamesMap[id]).filter(Boolean).filter(isEventAvailable);
+  return sortEventsByStarts(normalizedIds.map(id => gamesMap[id]).filter(Boolean).filter(isEventAvailable));
 }
 
 /**