-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
> 参照 https://npmtrends.com/next 实现下载趋势对比, see #75 1. 默认全量展示 2020 年开始相关数据 2. 支持最多5个包横向对比 ![image](https://github.com/cnpm/cnpmweb/assets/5574625/d700f580-a32c-4554-bc14-f741b9393558) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a "Download Trends" tab to provide insights into the download trends of packages. - Added a new `Trends` component that allows users to view and compare the total downloads of multiple packages over different years. - Implemented functionality to search for packages and display their total download statistics on the Trends page. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
5 changed files
with
182 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use client'; | ||
import SizeContainer from '@/components/SizeContainer'; | ||
import { Card, Select, Typography } from 'antd'; | ||
import React, { useState } from 'react'; | ||
import { PageProps } from '@/pages/package/[...slug]'; | ||
import { TotalDownloads } from '@/components/RecentDownloads'; | ||
import { useCachedSearch } from '@/hooks/useSearch'; | ||
import { DownOutlined } from '@ant-design/icons'; | ||
|
||
const MAX_COUNT = 5; | ||
|
||
export default function Trends({ manifest: pkg, additionalInfo: needSync, version }: PageProps) { | ||
const [search, setSearch] = useState(''); | ||
const [pkgs, setPkgs] = useState([pkg.name]); | ||
const { data: searchResult, isLoading } = useCachedSearch({ | ||
keyword: search, | ||
page: 1, | ||
}); | ||
|
||
const suffix = ( | ||
<> | ||
<span> | ||
{pkgs.length} / {MAX_COUNT} | ||
</span> | ||
<DownOutlined /> | ||
</> | ||
); | ||
|
||
return ( | ||
<> | ||
<SizeContainer maxWidth={1072}> | ||
<Select | ||
mode="multiple" | ||
maxCount={MAX_COUNT} | ||
value={pkgs} | ||
style={{ width: '100%' }} | ||
onSearch={setSearch} | ||
suffixIcon={suffix} | ||
placeholder="Please select" | ||
defaultValue={pkgs} | ||
onChange={setPkgs} | ||
options={searchResult?.objects.map((object) => ({ | ||
label: ( | ||
<> | ||
<Typography.Text> | ||
{object.package.name} | ||
</Typography.Text> | ||
<br /> | ||
</> | ||
), | ||
value: object.package.name, | ||
}))} | ||
/> | ||
<Card style={{ marginTop: 24 }}> | ||
<TotalDownloads pkgNameList={pkgs}/> | ||
</Card> | ||
</SizeContainer> | ||
</> | ||
); | ||
} |