Skip to content

Commit

Permalink
Merge pull request #383 from ousttrue/fix_toSorted
Browse files Browse the repository at this point in the history
fix toSorted
  • Loading branch information
ousttrue authored Mar 18, 2024
2 parents b7faa8f + 9198c1e commit 51b9ad0
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/pages/showcase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<UserState>();
const [operator, setOperator] = React.useState<Operator>("OR");
Expand All @@ -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]
);
}
Expand Down Expand Up @@ -249,7 +250,7 @@ function ShowcaseCards() {
<Translate id="showcase.usersList.allUsers">All sites</Translate>
</Heading>
<ul className={clsx("clean-list", styles.showcaseList)}>
{users.toSorted(cmpUser).map((user) => (
{users.map((user) => (
<ShowcaseCard
key={user[currentLocale].title}
user={user[currentLocale]}
Expand Down

0 comments on commit 51b9ad0

Please sign in to comment.