Skip to content

Commit 0009976

Browse files
authored
feat(style): add driver icons and disk usage (#212)
* feat(style): add driver icons and disk usage * fix: wrong unit * chore * feat(style): add disk usage on the manage page
1 parent 0190138 commit 0009976

File tree

11 files changed

+193
-24
lines changed

11 files changed

+193
-24
lines changed

src/lang/en/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"ftp_tls_private_key_path": "Ftp tls private key path",
2828
"ftp_tls_public_cert_path": "Ftp tls public cert path",
2929
"hide_files": "Hide files",
30+
"hide_storage_details": "Hide storage details",
3031
"home_container": "Home container",
3132
"home_containers": {
3233
"hope_container": "Hope container",

src/lang/en/storages.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"driver": "Driver",
66
"order": "Order",
77
"order-tips": "Use to sort",
8+
"usage": "Usage",
89
"status": "Status",
910
"remark": "Remark",
1011
"cache_expiration": "Cache Expiration",

src/pages/home/folder/ListItem.tsx

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { HStack, Icon, Text } from "@hope-ui/solid"
1+
import {
2+
HStack,
3+
Icon,
4+
Progress,
5+
ProgressIndicator,
6+
ProgressLabel,
7+
Text,
8+
} from "@hope-ui/solid"
29
import { Motion } from "solid-motionone"
310
import { useContextMenu } from "solid-contextmenu"
411
import { batch, Show } from "solid-js"
@@ -11,8 +18,17 @@ import {
1118
OrderBy,
1219
selectIndex,
1320
} from "~/store"
14-
import { ObjType, StoreObj } from "~/types"
15-
import { bus, formatDate, getFileSize, hoverColor } from "~/utils"
21+
import { MountDetails, ObjType, StoreObj } from "~/types"
22+
import {
23+
bus,
24+
formatDate,
25+
getFileSize,
26+
hoverColor,
27+
showDiskUsage,
28+
usedPercentage,
29+
toReadableUsage,
30+
nearlyFull,
31+
} from "~/utils"
1632
import { getIconByObj } from "~/utils/icon"
1733
import { ItemCheckbox, useSelectWithMouse } from "./helper"
1834

@@ -145,9 +161,37 @@ export const ListItem = (props: { obj: StoreObj; index: number }) => {
145161
{props.obj.name}
146162
</Text>
147163
</HStack>
148-
<Text class="size" w={cols[1].w} textAlign={cols[1].textAlign as any}>
149-
{getFileSize(props.obj.size)}
150-
</Text>
164+
<Show
165+
fallback={
166+
<Text
167+
class="size"
168+
w={cols[1].w}
169+
textAlign={cols[1].textAlign as any}
170+
>
171+
{getFileSize(props.obj.size)}
172+
</Text>
173+
}
174+
when={showDiskUsage(props.obj.mount_details)}
175+
>
176+
<Progress
177+
w={cols[1].w}
178+
class="disk-usage-percentage"
179+
trackColor="$info3"
180+
rounded="$full"
181+
size="md"
182+
value={usedPercentage(props.obj.mount_details!)}
183+
>
184+
<ProgressIndicator
185+
color={
186+
nearlyFull(props.obj.mount_details!) ? "$danger6" : "$info6"
187+
}
188+
rounded="$md"
189+
/>
190+
<ProgressLabel class="disk-usage-text">
191+
{toReadableUsage(props.obj.mount_details!)}
192+
</ProgressLabel>
193+
</Progress>
194+
</Show>
151195
<Text
152196
class="modified"
153197
display={{ "@initial": "none", "@md": "inline" }}

src/pages/manage/storages/Storage.tsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@ import {
88
Tr,
99
useColorModeValue,
1010
VStack,
11+
Progress,
12+
ProgressIndicator,
13+
ProgressLabel,
1114
} from "@hope-ui/solid"
15+
import { Show } from "solid-js"
1216
import { useFetch, useRouter, useT } from "~/hooks"
1317
import { getMainColor } from "~/store"
14-
import { PEmptyResp, Storage } from "~/types"
15-
import { handleResp, handleRespWithNotifySuccess, notify, r } from "~/utils"
18+
import { MountDetails, PEmptyResp, Storage } from "~/types"
19+
import {
20+
handleResp,
21+
handleRespWithNotifySuccess,
22+
notify,
23+
r,
24+
showDiskUsage,
25+
usedPercentage,
26+
toReadableUsage,
27+
nearlyFull,
28+
} from "~/utils"
1629
import { DeletePopover } from "../common/DeletePopover"
1730

1831
interface StorageProps {
@@ -70,6 +83,28 @@ function StorageOp(props: StorageProps) {
7083
)
7184
}
7285

86+
function StorageUsage(props: { details: MountDetails | undefined }) {
87+
return (
88+
<Show when={props.details}>
89+
<Progress
90+
class="disk-usage-percentage"
91+
trackColor="$info3"
92+
rounded="$full"
93+
size="md"
94+
value={usedPercentage(props.details!)}
95+
>
96+
<ProgressIndicator
97+
color={nearlyFull(props.details!) ? "$danger6" : "$info6"}
98+
rounded="$md"
99+
/>
100+
<ProgressLabel class="disk-usage-text">
101+
{toReadableUsage(props.details!)}
102+
</ProgressLabel>
103+
</Progress>
104+
</Show>
105+
)
106+
}
107+
73108
export function StorageGridItem(props: StorageProps) {
74109
const t = useT()
75110
return (
@@ -97,6 +132,15 @@ export function StorageGridItem(props: StorageProps) {
97132
<Badge colorScheme="info">
98133
{t(`drivers.drivers.${props.storage.driver}`)}
99134
</Badge>
135+
<Show when={props.storage.mount_details}>
136+
<Badge
137+
colorScheme={
138+
nearlyFull(props.storage.mount_details!) ? "danger" : "success"
139+
}
140+
>
141+
{toReadableUsage(props.storage.mount_details!)}
142+
</Badge>
143+
</Show>
100144
</HStack>
101145
<HStack>
102146
<Text>{t("storages.common.status")}:&nbsp;</Text>
@@ -125,6 +169,9 @@ export function StorageListItem(props: StorageProps) {
125169
<Td>{props.storage.mount_path}</Td>
126170
<Td>{t(`drivers.drivers.${props.storage.driver}`)}</Td>
127171
<Td>{props.storage.order}</Td>
172+
<Td>
173+
<StorageUsage details={props.storage.mount_details} />
174+
</Td>
128175
<Td>
129176
{t(
130177
`storages.table_fields.status.${props.storage.status}`,

src/pages/manage/storages/Storages.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,14 @@ const Storages = () => {
162162
<Thead>
163163
<Tr>
164164
<For
165-
each={["mount_path", "driver", "order", "status", "remark"]}
165+
each={[
166+
"mount_path",
167+
"driver",
168+
"order",
169+
"usage",
170+
"status",
171+
"remark",
172+
]}
166173
>
167174
{(title) => <Th>{t(`storages.common.${title}`)}</Th>}
168175
</For>

src/pages/manage/tasks/Task.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,14 @@ export const Task = (props: TaskAttribute & TasksProps & TaskLocalSetter) => {
143143
let speedText = "-"
144144
const parseSpeedText = (timeDelta: number, lengthDelta: number) => {
145145
let delta = lengthDelta / timeDelta
146-
let unit = "bytes/s"
147-
if (delta > 1024) {
148-
delta /= 1024
149-
unit = "KB/s"
146+
const units = ["B/s", "KB/s", "MB/s", "GB/s", "TB/s"]
147+
const k = 1000
148+
let unit_i = 0
149+
while (unit_i < units.length - 1 && delta >= k) {
150+
delta /= k
151+
unit_i++
150152
}
151-
if (delta > 1024) {
152-
delta /= 1024
153-
unit = "MB/s"
154-
}
155-
if (delta > 1024) {
156-
delta /= 1024
157-
unit = "GB/s"
158-
}
159-
return `${delta.toFixed(2)} ${unit}`
153+
return `${delta.toFixed(2)} ${units[unit_i]}`
160154
}
161155
if (props.done) {
162156
if (

src/types/obj.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface Obj {
2020
thumb: string
2121
type: ObjType
2222
path: string
23+
mount_details?: MountDetails
2324
}
2425

2526
export type StoreObj = Obj & {
@@ -48,4 +49,10 @@ export type ArchiveMeta = {
4849
sign: string
4950
}
5051

52+
export type MountDetails = {
53+
total_space?: number
54+
free_space?: number
55+
driver_name: string
56+
}
57+
5158
export type ArchiveList = PageResp<Obj>

src/types/storage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { MountDetails } from "./obj"
2+
13
export enum OrderBy {
24
Name = "name",
35
Size = "size",
@@ -38,6 +40,7 @@ export interface Storage {
3840
web_proxy: boolean
3941
webdav_policy: WebdavPolicy
4042
disabled: boolean
43+
mount_details?: MountDetails
4144
}
4245

4346
export type Addition = Record<string, string | boolean | number>

src/utils/icon.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
BsWindows,
1313
BsFileEarmarkZipFill,
1414
BsMarkdownFill,
15+
BsDeviceHddFill,
1516
} from "solid-icons/bs"
1617
import {
1718
FaSolidDatabase,
@@ -20,7 +21,7 @@ import {
2021
FaSolidLink,
2122
} from "solid-icons/fa"
2223
import { IoFolder } from "solid-icons/io"
23-
import { ImAndroid } from "solid-icons/im"
24+
import { ImAndroid, ImGoogleDrive, ImOnedrive } from "solid-icons/im"
2425
import { Obj, ObjType } from "~/types"
2526
import { ext } from "./path"
2627
import {
@@ -29,6 +30,8 @@ import {
2930
} from "~/components"
3031
import { SiAsciinema } from "solid-icons/si"
3132
import { isArchive } from "~/store/archive"
33+
import { AiFillGithub } from "solid-icons/ai"
34+
import { RiLogosNeteaseCloudMusicFill } from "solid-icons/ri"
3235

3336
const iconMap = {
3437
"dmg,ipa,plist,tipa": BsApple,
@@ -89,6 +92,31 @@ export const getIconByTypeAndName = (type: number, name: string) => {
8992
}
9093
}
9194

92-
export const getIconByObj = (obj: Pick<Obj, "type" | "name">) => {
95+
export const getIconByDriver = (driverName: string) => {
96+
switch (driverName) {
97+
case "Local":
98+
return BsDeviceHddFill
99+
case "GitHub API":
100+
case "GitHub Releases":
101+
return AiFillGithub
102+
case "GoogleDrive":
103+
return ImGoogleDrive
104+
case "NeteaseMusic":
105+
return RiLogosNeteaseCloudMusicFill
106+
case "Onedrive":
107+
case "OnedriveApp":
108+
case "Onedrive Sharelink":
109+
return ImOnedrive
110+
default:
111+
return IoFolder
112+
}
113+
}
114+
115+
export const getIconByObj = (
116+
obj: Pick<Obj, "type" | "name" | "mount_details">,
117+
) => {
118+
if (obj.mount_details) {
119+
return getIconByDriver(obj.mount_details.driver_name)
120+
}
93121
return getIconByTypeAndName(obj.type, obj.name)
94122
}

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export * from "./api"
1212
export * from "./hash"
1313
export * from "./compatibility"
1414
export * from "./share"
15+
export * from "./storage"

0 commit comments

Comments
 (0)