From 4466bec476674d82be9dc6488562a2d61415be44 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 6 Dec 2023 13:49:31 +0700 Subject: [PATCH 1/2] fix/models-sorting-order --- .../ExploreModels/ExploreModelList/index.tsx | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/web/screens/ExploreModels/ExploreModelList/index.tsx b/web/screens/ExploreModels/ExploreModelList/index.tsx index d402d5c50d..471896cb3b 100644 --- a/web/screens/ExploreModels/ExploreModelList/index.tsx +++ b/web/screens/ExploreModels/ExploreModelList/index.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import { Model } from '@janhq/core' import ExploreModelItem from '@/screens/ExploreModels/ExploreModelItem' @@ -7,14 +8,38 @@ type Props = { } const ExploreModelList: React.FC = ({ models }) => { + const sortOrder: Record = { + '7b': 1, + '13b': 2, + '34b': 3, + '70b': 4, + '120b': 5, + 'tiny': 6, + } + const sortedModels = models?.sort((a, b) => { + const aIsFeatured = a.metadata.tags.includes('Featured') + const bIsFeatured = b.metadata.tags.includes('Featured') + const aIsRecommended = a.metadata.tags.includes('Recommended') + const bIsRecommended = b.metadata.tags.includes('Recommended') + const aNumericTag = + a.metadata.tags.find((tag) => !!sortOrder[tag.toLowerCase()]) ?? 'Tiny' + const bNumericTag = + b.metadata.tags.find((tag) => !!sortOrder[tag.toLowerCase()]) ?? 'Tiny' + + if (aIsFeatured !== bIsFeatured) return aIsFeatured ? -1 : 1 + if (aNumericTag !== bNumericTag) + return ( + sortOrder[aNumericTag.toLowerCase()] - + sortOrder[bNumericTag.toLowerCase()] + ) + if (aIsRecommended !== bIsRecommended) return aIsRecommended ? -1 : 1 + return a.metadata.size - b.metadata.size + }) return (
- {models - ?.sort((a) => { - if (a.metadata.tags.includes('Recommended')) return -1 - return 0 - }) - ?.map((model) => )} + {sortedModels?.map((model) => ( + + ))}
) } From 57507c304a1aa945db47b1c10dedb636fd13704f Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 6 Dec 2023 14:08:16 +0700 Subject: [PATCH 2/2] fix: cover height should be fixed --- .../ExploreModels/ExploreModelItemHeader/index.tsx | 8 ++++++-- web/screens/ExploreModels/index.tsx | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/web/screens/ExploreModels/ExploreModelItemHeader/index.tsx b/web/screens/ExploreModels/ExploreModelItemHeader/index.tsx index 79428b0423..ba23056c6f 100644 --- a/web/screens/ExploreModels/ExploreModelItemHeader/index.tsx +++ b/web/screens/ExploreModels/ExploreModelItemHeader/index.tsx @@ -102,8 +102,12 @@ const ExploreModelItemHeader: React.FC = ({ model, onClick, open }) => { onClick={onClick} > {model.metadata.cover && ( -
- {`Cover +
+ {`Cover
)}
diff --git a/web/screens/ExploreModels/index.tsx b/web/screens/ExploreModels/index.tsx index fc52c973e7..c9f100dcf4 100644 --- a/web/screens/ExploreModels/index.tsx +++ b/web/screens/ExploreModels/index.tsx @@ -44,7 +44,10 @@ const ExploreModelsScreen = () => { downloadedModels.some((y) => y.id === x.id) ) } else if (sortSelected === 'Recommended') { - return x.metadata.tags.includes('Recommended') + return ( + x.metadata.tags.includes('Featured') || + x.metadata.tags.includes('Recommended') + ) } else { return x.name.toLowerCase().includes(searchValue.toLowerCase()) }