Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit cc0b86f

Browse files
committed
build(1.0.0): add basic sort for ordering list
1 parent 6ff3f48 commit cc0b86f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/pages/games-list/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ const gamesConverter = (doc: DocumentData, id: string): Game => {
2323
return game;
2424
};
2525

26+
const dateComparator = (first: Game, second: Game) => {
27+
if (second.createdAt && first.createdAt) {
28+
return second?.createdAt - first?.createdAt;
29+
}
30+
31+
return 0;
32+
};
33+
2634
const GamesList = (): JSX.Element => {
2735
const { t } = useTranslation();
2836
const { uid } = useStore(nanoUser);
@@ -36,7 +44,6 @@ const GamesList = (): JSX.Element => {
3644
}
3745
);
3846

39-
4047
useEffect(() => {
4148
if (!loading) {
4249
const g = value?.docs.map((doc) => gamesConverter(doc.data(), doc.id));
@@ -56,10 +63,12 @@ const GamesList = (): JSX.Element => {
5663

5764
const filteredGames = useMemo(() => {
5865
if (status === 'all') {
59-
return nanoList;
66+
return nanoList.sort(dateComparator);
6067
}
6168

62-
return nanoList.filter((game) => game.status === status);
69+
return nanoList
70+
.filter((game) => game.status === status)
71+
.sort(dateComparator);
6372
}, [nanoList, status]);
6473

6574
return (

0 commit comments

Comments
 (0)