Skip to content

Commit ba72269

Browse files
author
Pompurin404
committed
profile page
1 parent e11a98b commit ba72269

File tree

6 files changed

+68
-16
lines changed

6 files changed

+68
-16
lines changed

src/renderer/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const App: React.FC = () => {
4444
return (
4545
<div className="w-full h-[100vh] flex">
4646
<div className="side w-[250px] h-full overflow-y-auto no-scrollbar">
47-
<div className="sticky top-0 z-40 backdrop-blur h-[48px]">
47+
<div className="sticky top-0 z-40 backdrop-blur bg-background/70 h-[48px]">
4848
<div className="flex justify-between p-2">
4949
<h3 className="select-none text-lg font-bold leading-[32px]">Mihomo Party</h3>
5050
<Button

src/renderer/src/components/base/base-page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface Props {
1010
const BasePage: React.FC<Props> = (props) => {
1111
return (
1212
<div className="w-full h-full overflow-y-auto custom-scrollbar">
13-
<div className="sticky top-0 z-40 h-[48px] w-full backdrop-blur">
13+
<div className="sticky top-0 z-40 h-[48px] w-full backdrop-blur bg-background/70">
1414
<div className="p-2 flex justify-between">
1515
<div className="select-none title h-full text-lg leading-[32px]">{props.title}</div>
1616
<div className="header h-full">{props.header}</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Button, Card, CardBody, CardFooter, Progress } from '@nextui-org/react'
2+
import { calcPercent, calcTraffic } from '@renderer/utils/calc'
3+
import React from 'react'
4+
import { IoMdRefresh } from 'react-icons/io'
5+
6+
interface Props {
7+
info: IProfileItem
8+
isCurrent: boolean
9+
onClick: () => void
10+
}
11+
12+
const ProfileItem: React.FC<Props> = (props) => {
13+
const { info, onClick, isCurrent } = props
14+
const extra = info?.extra
15+
const usage = (extra?.upload ?? 0) + (extra?.download ?? 0)
16+
const total = extra?.total ?? 0
17+
return (
18+
<Card fullWidth isPressable onPress={onClick} className={isCurrent ? 'bg-primary' : ''}>
19+
<CardBody>
20+
<div className="flex justify-between h-[32px]">
21+
<h3 className="select-none text-ellipsis whitespace-nowrap overflow-hidden text-md font-bold leading-[32px]">
22+
{info?.name}
23+
</h3>
24+
<Button isIconOnly size="sm" variant="light" color="default">
25+
<IoMdRefresh color="default" className="text-[24px]" />
26+
</Button>
27+
</div>
28+
</CardBody>
29+
<CardFooter className="pt-1">
30+
<Progress
31+
classNames={{ indicator: 'bg-foreground', label: 'select-none' }}
32+
label={extra ? `${calcTraffic(usage)}/${calcTraffic(total)}` : undefined}
33+
value={calcPercent(extra?.upload, extra?.download, extra?.total)}
34+
className="max-w-md"
35+
/>
36+
</CardFooter>
37+
</Card>
38+
)
39+
}
40+
41+
export default ProfileItem

src/renderer/src/components/sider/profile-card.tsx

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Button, Card, CardBody, CardFooter, Progress } from '@nextui-org/react'
22
import { useProfileConfig } from '@renderer/hooks/use-profile'
33
import { useLocation, useNavigate } from 'react-router-dom'
4-
import { calcTraffic } from '@renderer/utils/calc'
4+
import { calcTraffic, calcPercent } from '@renderer/utils/calc'
55
import { IoMdRefresh } from 'react-icons/io'
66

77
const ProfileCard: React.FC = () => {
@@ -50,14 +50,3 @@ const ProfileCard: React.FC = () => {
5050
}
5151

5252
export default ProfileCard
53-
54-
function calcPercent(
55-
upload: number | undefined,
56-
download: number | undefined,
57-
total: number | undefined
58-
): number {
59-
if (upload === undefined || download === undefined || total === undefined) {
60-
return 100
61-
}
62-
return Math.round(((upload + download) / total) * 100)
63-
}

src/renderer/src/pages/profiles.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Button, Input } from '@nextui-org/react'
22
import BasePage from '@renderer/components/base/base-page'
3+
import ProfileItem from '@renderer/components/profiles/profile-item'
34
import { useProfileConfig } from '@renderer/hooks/use-profile'
45
import { useState } from 'react'
56
import { MdContentPaste } from 'react-icons/md'
67

78
const Profiles: React.FC = () => {
89
const { profileConfig, addProfileItem } = useProfileConfig()
10+
const { current, items } = profileConfig || {}
911
const [importing, setImporting] = useState(false)
1012
const [url, setUrl] = useState('')
1113

@@ -22,7 +24,7 @@ const Profiles: React.FC = () => {
2224

2325
return (
2426
<BasePage title="订阅">
25-
<div className="flex m-2">
27+
<div className="sticky top-[48px] z-40 backdrop-blur bg-background/70 flex p-2">
2628
<Input
2729
variant="bordered"
2830
className="mr-2"
@@ -48,7 +50,16 @@ const Profiles: React.FC = () => {
4850
导入
4951
</Button>
5052
</div>
51-
{JSON.stringify(profileConfig)}
53+
<div className="grid sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-2 mx-2">
54+
{items?.map((item) => (
55+
<ProfileItem
56+
key={item.id}
57+
isCurrent={item.id === current}
58+
info={item}
59+
onClick={() => {}}
60+
/>
61+
))}
62+
</div>
5263
</BasePage>
5364
)
5465
}

src/renderer/src/utils/calc.ts

+11
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ export function calcTraffic(bit: number): string {
1717
bit /= 1024
1818
return `${bit.toFixed(2)} YB`
1919
}
20+
21+
export function calcPercent(
22+
upload: number | undefined,
23+
download: number | undefined,
24+
total: number | undefined
25+
): number {
26+
if (upload === undefined || download === undefined || total === undefined) {
27+
return 100
28+
}
29+
return Math.round(((upload + download) / total) * 100)
30+
}

0 commit comments

Comments
 (0)