Skip to content

Commit e0c903c

Browse files
committed
remove usememo for better sorting
1 parent c1740cc commit e0c903c

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/components/ModelCatalog.tsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState, useMemo } from "react";
1+
import { useEffect, useState } from "react";
22
import ModelInfo from "./models/ModelInfo";
33
import ModelBadges from "./models/ModelBadges";
44
import { authorData } from "./models/data";
@@ -26,29 +26,27 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
2626
];
2727

2828
// Sort models by pinned status first, then by created_at date
29-
const sortedModels = useMemo(() => {
30-
return [...models].sort((a, b) => {
31-
// First check if either model is pinned
32-
const isPinnedA = pinnedModelNames.includes(a.name);
33-
const isPinnedB = pinnedModelNames.includes(b.name);
34-
35-
// If pinned status differs, prioritize pinned models
36-
if (isPinnedA && !isPinnedB) return -1;
37-
if (!isPinnedA && isPinnedB) return 1;
38-
39-
// If both are pinned, sort by position in pinnedModelNames array (for manual ordering)
40-
if (isPinnedA && isPinnedB) {
41-
return (
42-
pinnedModelNames.indexOf(a.name) - pinnedModelNames.indexOf(b.name)
43-
);
44-
}
29+
const sortedModels = [...models].sort((a, b) => {
30+
// First check if either model is pinned
31+
const isPinnedA = pinnedModelNames.includes(a.name);
32+
const isPinnedB = pinnedModelNames.includes(b.name);
33+
34+
// If pinned status differs, prioritize pinned models
35+
if (isPinnedA && !isPinnedB) return -1;
36+
if (!isPinnedA && isPinnedB) return 1;
37+
38+
// If both are pinned, sort by position in pinnedModelNames array (for manual ordering)
39+
if (isPinnedA && isPinnedB) {
40+
return (
41+
pinnedModelNames.indexOf(a.name) - pinnedModelNames.indexOf(b.name)
42+
);
43+
}
4544

46-
// If neither is pinned, sort by created_at date (newest first)
47-
const dateA = a.created_at ? new Date(a.created_at) : new Date(0);
48-
const dateB = b.created_at ? new Date(b.created_at) : new Date(0);
49-
return dateB.getTime() - dateA.getTime();
50-
});
51-
}, [models]);
45+
// If neither is pinned, sort by created_at date (newest first)
46+
const dateA = a.created_at ? new Date(a.created_at) : new Date(0);
47+
const dateB = b.created_at ? new Date(b.created_at) : new Date(0);
48+
return dateB.getTime() - dateA.getTime();
49+
});
5250

5351
useEffect(() => {
5452
const params = new URLSearchParams(window.location.search);

0 commit comments

Comments
 (0)