diff --git a/apps/web/i18n b/apps/web/i18n index 3c5b9c66..b8585469 160000 --- a/apps/web/i18n +++ b/apps/web/i18n @@ -1 +1 @@ -Subproject commit 3c5b9c66b067e5a65362c9c51d2af544d7a9920c +Subproject commit b8585469303f31a568ebad3a73a07e180a91c1c0 diff --git a/apps/web/src/modules/collection/MainContent.tsx b/apps/web/src/modules/collection/MainContent.tsx index 07321adf..82d12201 100644 --- a/apps/web/src/modules/collection/MainContent.tsx +++ b/apps/web/src/modules/collection/MainContent.tsx @@ -120,7 +120,16 @@ const MainContent = ({ const [compareMode, setCompareMode] = useState(false); const [compareIds, setCompareIds] = useState([]); - const params = { ident: slug, page: 1, per: 30 }; + const [keyword, setKeyword] = useState(''); + const [sort, setSort] = useState(''); + + const params = { + ident: slug, + page: 1, + per: 30, + keyword, + sortOpts: [{ type: 'activity_score', direction: 'asc' }], + }; const { data, status, @@ -150,7 +159,7 @@ const MainContent = ({ const lastItem = last(data?.pages); const total = lastItem?.collectionList.count || 0; - + console.log(data, lastItem, total, hasNextPage); return (
@@ -161,6 +170,11 @@ const MainContent = ({ total={total} compareMode={compareMode} onCompareModeChange={(v) => setCompareMode(v)} + keyword={keyword} + setKeyword={(v) => { + console.log(v); + setKeyword(v); + }} /> ; @@ -17,6 +18,8 @@ const MainHeader = ({ compareIds, compareMode, onCompareModeChange, + keyword, + setKeyword, }: { slug: string; nameKey: 'name_cn' | 'name'; @@ -24,6 +27,8 @@ const MainHeader = ({ compareIds: string[]; compareMode: boolean; onCompareModeChange: (v: boolean) => void; + keyword: string; + setKeyword: (v: string) => void; }) => { const router = useRouter(); @@ -33,6 +38,20 @@ const MainHeader = ({ return collectionsMap[ident].slug === `/${slug}`; }); const collection = ident ? collectionsMap[ident] : null; + const [value, setValue] = useState(keyword); + + useHotkeys( + 'enter', + (e, he) => { + e.preventDefault(); + const press = he.key; + if (press === 'enter') { + if (!value) return; + setKeyword?.(value); + } + }, + { enableOnTags: ['INPUT'] } + ); return (
@@ -80,7 +99,7 @@ const MainHeader = ({ onClick={() => { onCompareModeChange(true); }} - className="h-8 w-36 flex-none cursor-pointer border border-gray-500 text-center text-xs font-semibold leading-8" + className="h-8 flex-none cursor-pointer border border-gray-500 px-2 text-center text-xs font-semibold leading-8" >
@@ -90,6 +109,32 @@ const MainHeader = ({
)}
+
+
+ { + const val = event.target.value; + setValue(val); + }} + alt={'Type the name to insight into your project'} + /> +
{ + setKeyword(value); + }} + className="h-6 w-8 cursor-pointer select-none pl-2" + > + +
+
+
); }; diff --git a/packages/graphql/src/generated.ts b/packages/graphql/src/generated.ts index 3b31a866..feb0bec7 100644 --- a/packages/graphql/src/generated.ts +++ b/packages/graphql/src/generated.ts @@ -1658,9 +1658,11 @@ export type QueryCollectionHottestArgs = { export type QueryCollectionListArgs = { ident: Scalars['String']; + keyword?: InputMaybe; level?: InputMaybe; page?: InputMaybe; per?: InputMaybe; + sortOpts?: InputMaybe>; }; export type QueryCommunityOverviewArgs = { @@ -4392,6 +4394,8 @@ export type CollectionListQueryVariables = Exact<{ level?: InputMaybe; page?: InputMaybe; per?: InputMaybe; + keyword?: InputMaybe; + sortOpts?: InputMaybe | SortOptionInput>; }>; export type CollectionListQuery = { @@ -7961,8 +7965,15 @@ useCollectionHottestQuery.fetcher = ( headers ); export const CollectionListDocument = /*#__PURE__*/ ` - query collectionList($ident: String!, $level: String, $page: Int, $per: Int) { - collectionList(ident: $ident, level: $level, page: $page, per: $per) { + query collectionList($ident: String!, $level: String, $page: Int, $per: Int, $keyword: String, $sortOpts: [SortOptionInput!]) { + collectionList( + ident: $ident + level: $level + page: $page + per: $per + keyword: $keyword + sortOpts: $sortOpts + ) { page totalPage count diff --git a/packages/graphql/src/gql/query.graphql b/packages/graphql/src/gql/query.graphql index 698714f4..a680299d 100644 --- a/packages/graphql/src/gql/query.graphql +++ b/packages/graphql/src/gql/query.graphql @@ -481,9 +481,22 @@ query collectionHottest($ident: String!, $limit: Int) { updatedAt } } - -query collectionList($ident: String!, $level: String, $page: Int, $per: Int) { - collectionList(ident: $ident, level: $level, page: $page, per: $per) { +query collectionList( + $ident: String! + $level: String + $page: Int + $per: Int + $keyword: String + $sortOpts: [SortOptionInput!] +) { + collectionList( + ident: $ident + level: $level + page: $page + per: $per + keyword: $keyword + sortOpts: $sortOpts + ) { page totalPage count