Skip to content

Commit

Permalink
Refactor package download link handling in PackageDetails component
Browse files Browse the repository at this point in the history
- Simplified the construction of the download URL for packages.
- Moved the URL generation logic directly into the onClick handler for better readability.
- Ensured the download functionality remains intact while improving code clarity.
  • Loading branch information
239573049 committed Dec 1, 2024
1 parent 20a683d commit ba97e87
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 38 deletions.
22 changes: 13 additions & 9 deletions web/src/app/packages/details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,23 @@ const PackageDetails = () => {
</li>
)}
<li>
<CloudDownloadOutlined /> <a onClick={() => {

const url = detail.packageDownloadUrl ?? location.origin + '/v3/package/' +
<CloudDownloadOutlined /> <a
href={detail.packageDownloadUrl ?? location.origin + '/v3/package/' +
detail.package.id + '/' +
detail.package.normalizedVersionString + '/' +
`${detail.package.id}.${detail.package.normalizedVersionString}.nupkg`;
`${detail.package.id}.${detail.package.normalizedVersionString}.nupkg`}
onClick={() => {
const url = detail.packageDownloadUrl ?? location.origin + '/v3/package/' +
detail.package.id + '/' +
detail.package.normalizedVersionString + '/' +
`${detail.package.id}.${detail.package.normalizedVersionString}.nupkg`;

const a = document.createElement('a');
a.href = url;
a.download = `${detail.package.id}.${detail.package.normalizedVersionString}.nupkg`;
a.click();
const a = document.createElement('a');
a.href = url;
a.download = `${detail.package.id}.${detail.package.normalizedVersionString}.nupkg`;
a.click();

}}>下载</a>
}}>下载</a>
</li>
</ul>
</Card>
Expand Down
73 changes: 44 additions & 29 deletions web/src/app/welcome/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
import { GridShowcase, Input } from "@lobehub/ui";
import { Button } from 'antd';
import { useState } from "react";
import { useNavigate } from "react-router-dom";
const Welcome = () => {
const [search, setSearch] = useState("");
import React from 'react';
import { Button, Typography, Card } from 'antd';
import { useNavigate } from 'react-router-dom';
import { Flexbox } from 'react-layout-kit';

const { Title, Paragraph } = Typography;

const WelcomePage = () => {
const navigate = useNavigate();

return <>
<GridShowcase style={{ width: '100%' }}>
<div style={{ fontSize: 48, fontWeight: 600, marginTop: -16 }}>
使用NuGet Next 更快创建 .NET 程序。</div>
<div style={{
marginLeft: 'auto',
marginRight: 'auto',
width: 500,
}}>
<Input
return (
<Flexbox
style={{
height: '100vh',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f0f2f5',
padding: '20px',
}}
>
<Card
style={{
maxWidth: '600px',
textAlign: 'center',
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)',
}}
>
<Title level={2}>欢迎来到 NuGet Next</Title>
<Paragraph>
这是一个现代化的NuGet包管理平台,提供快速、可靠的包上传和下载服务。
</Paragraph>
<Paragraph>
了解更多关于如何创建和管理NuGet包的信息,请访问我们的文档。
</Paragraph>
<Button
type="primary"
size="large"
value={search}
onChange={(e) => setSearch(e.target.value)}
suffix={<Button onClick={() => {
var query = new URLSearchParams();
query.set('q', encodeURIComponent(search));
navigate(`/packages?${query}`);
}} type="text">🔍</Button>}
placeholder="搜索包..." />
</div>
</GridShowcase>
</>;
}
onClick={() => navigate('/upload')}
style={{ marginTop: '20px' }}
>
开始上传
</Button>
</Card>
</Flexbox>
);
};

export default Welcome;
export default WelcomePage;

0 comments on commit ba97e87

Please sign in to comment.