1- import { useEffect , useState } from "react" ;
1+ import { useEffect , useState , useMemo } from "react" ;
22import ModelInfo from "./models/ModelInfo" ;
33import ModelBadges from "./models/ModelBadges" ;
44import { authorData } from "./models/data" ;
@@ -25,28 +25,28 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
2525 "@cf/meta/llama-3.1-8b-instruct-fast" ,
2626 ] ;
2727
28- // Sort models by pinned status first, then by created_at date
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- }
28+ // Only sort by pinned status (models should already be sorted by created_at in index.astro)
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+ }
4445
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- } ) ;
46+ // For non-pinned models, maintain the original order
47+ return 0 ;
48+ } ) ;
49+ } , [ models ] ) ;
5050
5151 useEffect ( ( ) => {
5252 const params = new URLSearchParams ( window . location . search ) ;
0 commit comments