Skip to content

Commit 1f12f79

Browse files
committed
update sort fn
1 parent 8e5cc97 commit 1f12f79

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/pages/RoomList/index.tsx

+14-9
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,22 @@ const sortConnections = (data: I.SpyRoom[]) => {
4343
[[], []] as I.SpyRoom[][],
4444
);
4545

46-
// 再按创建时间排序
47-
const sortFn = (a: I.SpyRoom, b: I.SpyRoom) => {
48-
if (a.createdAt > b.createdAt) {
49-
return 1;
46+
// 有效房间再按创建时间升序
47+
const ascWithCreatedAtForInvalid = valid.sort((a, b) => {
48+
if (a.createdAt < b.createdAt) {
49+
return -1;
5050
}
51-
return -1;
52-
};
53-
const createdAtWithAscForValid = valid.sort(sortFn);
54-
const createdAtWithAscForInvalid = invalid.sort(sortFn);
51+
return 1;
52+
});
53+
// 失效房间再按活动时间升序
54+
const ascWithActiveAtForInvalid = invalid.sort((a, b) => {
55+
if (a.activeAt < b.activeAt) {
56+
return -1;
57+
}
58+
return 1;
59+
});
5560

56-
return [...createdAtWithAscForValid, ...createdAtWithAscForInvalid];
61+
return [...ascWithCreatedAtForInvalid, ...ascWithActiveAtForInvalid];
5762
};
5863

5964
const filterConnections = (

0 commit comments

Comments
 (0)