From 9198c1e7448df9b782cef54e992e0d9b1ff7bd8f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 18 Mar 2024 21:12:28 +0900 Subject: [PATCH] fix toSorted --- src/pages/showcase/index.tsx | 47 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/pages/showcase/index.tsx b/src/pages/showcase/index.tsx index 15a087152..6abba14d0 100644 --- a/src/pages/showcase/index.tsx +++ b/src/pages/showcase/index.tsx @@ -11,6 +11,28 @@ import Heading from "@theme/Heading"; import Layout from "@theme/Layout"; import { users } from "@site/src/data/users"; +function cmpUser(a: User, b: User): number { + if (a.updated) { + if (b.updated) { + return b.updated.getTime() - a.updated.getTime(); + } + else { + // left + return -1; + } + } + else { + if (b.updated) { + // right + return 1; + } + else { + return 0; + } + } +} +users.sort(cmpUser); + import { type User, type UserInfo } from "@site/src/data/user"; import { tags } from "@site/src/data/tags"; import { type Tag } from "@site/src/data/tag"; @@ -139,27 +161,6 @@ function restoreUserState(userState: UserState | null) { window.scrollTo({ top: scrollTopPosition }); } -function cmpUser(a: User, b: User): number { - if (a.updated) { - if (b.updated) { - return b.updated.getTime() - a.updated.getTime(); - } - else { - // left - return -1; - } - } - else { - if (b.updated) { - // right - return 1; - } - else { - return 0; - } - } -} - function useFilteredUsers() { const location = useLocation(); const [operator, setOperator] = React.useState("OR"); @@ -180,7 +181,7 @@ function useFilteredUsers() { } = useDocusaurusContext(); return React.useMemo( - () => filterUsers(users.toSorted(cmpUser), selectedFlags, operator, searchName, currentLocale), + () => filterUsers(users, selectedFlags, operator, searchName, currentLocale), [selectedFlags, operator, searchName] ); } @@ -249,7 +250,7 @@ function ShowcaseCards() { All sites
    - {users.toSorted(cmpUser).map((user) => ( + {users.map((user) => (