4
4
* @author darcrand
5
5
*/
6
6
7
- import { hasSameKeys , pickVideoInfo } from '@/components/DownloadModal/utils'
8
- import { mediaService } from '@/services/media'
7
+ import { ALL_BV_DATA_KEY } from '@/queries/useAllBVData'
9
8
import type { BVItemFromFile } from '@/types/global'
10
9
import UImage from '@/ui/UImage'
11
10
import { cls } from '@/utils/cls'
12
11
import { formatSeconds } from '@/utils/common'
13
- import { DatabaseOutlined , DeleteOutlined , FolderOpenOutlined , LinkOutlined , MoreOutlined } from '@ant-design/icons'
14
- import { useQuery , useQueryClient } from '@tanstack/react-query'
15
- import { removeDir , writeTextFile } from '@tauri-apps/api/fs'
12
+ import { DeleteOutlined , FolderOpenOutlined , LinkOutlined , MoreOutlined } from '@ant-design/icons'
13
+ import { useMutation , useQuery , useQueryClient } from '@tanstack/react-query'
14
+ import { removeDir } from '@tauri-apps/api/fs'
16
15
import { open as openShell } from '@tauri-apps/api/shell'
17
16
import { convertFileSrc } from '@tauri-apps/api/tauri'
18
- import { Button , Dropdown , Modal } from 'antd'
17
+ import { App , Button , Dropdown , Modal } from 'antd'
19
18
import dayjs from 'dayjs'
20
19
import * as R from 'ramda'
21
20
import { useMemo , useState } from 'react'
22
- import { NavLink , useNavigate } from 'react-router-dom'
21
+ import { NavLink } from 'react-router-dom'
23
22
24
23
export type BVListItemProps = {
25
24
data : BVItemFromFile
@@ -29,6 +28,7 @@ export type BVListItemProps = {
29
28
30
29
export default function BVListItem ( props : BVListItemProps ) {
31
30
const { videoInfo, bvid, path : bvPath , children } = props . data
31
+ const { message } = App . useApp ( )
32
32
33
33
const dateLabel = useMemo ( ( ) => {
34
34
if ( ! videoInfo ) return ''
@@ -68,34 +68,20 @@ export default function BVListItem(props: BVListItemProps) {
68
68
await openShell ( `https://www.bilibili.com/video/${ bvid } ` )
69
69
}
70
70
71
- const navigate = useNavigate ( )
72
71
const queryClient = useQueryClient ( )
73
72
const [ openRemove , setOpenRemove ] = useState ( false )
74
73
75
- const removeVideoFolder = async ( ) => {
76
- await removeDir ( bvPath , { recursive : true } )
77
- setOpenRemove ( false )
78
- queryClient . invalidateQueries ( { queryKey : [ 'bv' , 'all' ] } )
79
- navigate ( '/home/space' )
80
- }
74
+ const removeMutation = useMutation ( {
75
+ mutationFn : ( ) => removeDir ( bvPath , { recursive : true } ) ,
76
+ onSuccess ( ) {
77
+ message . success ( '视频删除成功' )
78
+ setOpenRemove ( false )
79
+ queryClient . invalidateQueries ( { queryKey : ALL_BV_DATA_KEY } )
80
+ }
81
+ } )
81
82
82
83
const pageCount = children ?. filter ( ( v ) => v . name ?. endsWith ( '.mp4' ) ) . length || 0
83
84
84
- // 优化功能
85
- // 对应 videoInfo 进行压缩
86
- const infoCompressed = hasSameKeys ( videoInfo )
87
- const compressInfo = async ( ) => {
88
- // 重新获取最新的视频信息
89
- const latestInfo = await mediaService . info ( bvid || '' )
90
-
91
- const compressed = pickVideoInfo ( latestInfo )
92
- const jsonFilePath = children ?. find ( ( v ) => v . name ?. endsWith ( '.json' ) ) ?. path
93
- if ( jsonFilePath ) {
94
- await writeTextFile ( jsonFilePath , JSON . stringify ( compressed ) )
95
- queryClient . invalidateQueries ( { queryKey : [ 'bv' , 'all' ] } )
96
- }
97
- }
98
-
99
85
return (
100
86
< >
101
87
< article className = { cls ( props . className ) } >
@@ -142,27 +128,21 @@ export default function BVListItem(props: BVListItemProps) {
142
128
label : '从B站打开' ,
143
129
onClick : openInBrowser
144
130
} ,
145
- { key : 'remove' , icon : < DeleteOutlined /> , label : '删除文件夹' , onClick : ( ) => setOpenRemove ( true ) } ,
146
- {
147
- key : 'compress' ,
148
- icon : < DatabaseOutlined /> ,
149
- disabled : infoCompressed ,
150
- label : '压缩视频信息' ,
151
- onClick : compressInfo
152
- }
131
+ { key : 'remove' , icon : < DeleteOutlined /> , label : '删除文件夹' , onClick : ( ) => setOpenRemove ( true ) }
153
132
]
154
133
} }
155
134
>
156
- < Button
157
- shape = 'circle'
158
- type = 'text'
159
- icon = { < MoreOutlined className = { cls ( ! infoCompressed && 'text-red-500' ) } /> }
160
- />
135
+ < Button shape = 'circle' type = 'text' icon = { < MoreOutlined /> } />
161
136
</ Dropdown >
162
137
</ div >
163
138
</ article >
164
139
165
- < Modal title = '删除文件夹' open = { openRemove } onCancel = { ( ) => setOpenRemove ( false ) } onOk = { removeVideoFolder } >
140
+ < Modal
141
+ title = '删除文件夹'
142
+ open = { openRemove }
143
+ onCancel = { ( ) => setOpenRemove ( false ) }
144
+ onOk = { ( ) => removeMutation . mutateAsync ( ) }
145
+ >
166
146
< p > 当前的 BV 视频文件夹中的所有文件都会被删除噢</ p >
167
147
< p > 确定要删除文件夹吗?</ p >
168
148
</ Modal >
0 commit comments