|
1 | | -import { useEffect, useState, useMemo } from "react"; |
| 1 | +import { useEffect, useState } from "react"; |
2 | 2 | import ModelInfo from "./models/ModelInfo"; |
3 | 3 | import ModelBadges from "./models/ModelBadges"; |
4 | 4 | import { authorData } from "./models/data"; |
@@ -26,29 +26,27 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => { |
26 | 26 | ]; |
27 | 27 |
|
28 | 28 | // 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 | + } |
45 | 44 |
|
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 | + }); |
52 | 50 |
|
53 | 51 | useEffect(() => { |
54 | 52 | const params = new URLSearchParams(window.location.search); |
|
0 commit comments