feat: icons and remove button

This commit is contained in:
TaurusXin 2025-02-01 13:39:13 +08:00
parent 33d9b91c52
commit 4df7df678b
Signed by: taurusxin
GPG Key ID: C334DCA04AC2D2CC

View File

@ -1,4 +1,4 @@
import React, { useEffect } from 'react' import React, { useEffect, useMemo } from 'react'
import { useState } from 'react' import { useState } from 'react'
import { import {
Button, Button,
@ -35,6 +35,10 @@ import {
CheckmarkRegular, CheckmarkRegular,
DismissRegular, DismissRegular,
DocumentArrowRightRegular, DocumentArrowRightRegular,
DocumentAddRegular,
DeleteRegular,
DeleteDismissRegular,
WindowPlayRegular,
} from '@fluentui/react-icons' } from '@fluentui/react-icons'
import { Status, Item, SaveTo } from './types' import { Status, Item, SaveTo } from './types'
@ -51,6 +55,10 @@ const columnsDef: TableColumnDefinition<Item>[] = [
columnId: 'file', columnId: 'file',
renderHeaderCell: () => <></>, renderHeaderCell: () => <></>,
}), }),
createTableColumn<Item>({
columnId: 'operation',
renderHeaderCell: () => <></>,
}),
] ]
const useStyles = makeStyles({ const useStyles = makeStyles({
@ -69,10 +77,13 @@ export const App = () => {
const styles = useStyles() const styles = useStyles()
const [items, setItems] = useState<Item[]>([]) const [items, setItems] = useState<Item[]>([])
const [isProcessing, setIsProcessing] = useState(false) const isProcessing = useMemo(() => {
return items.some(item => item.status === 'processing')
}, [items])
const [totalFilesNeedToProcess, setTotalFilesNeedToProcess] = useState(0) const isProcessFinished = useMemo(() => {
const [finishedCount, setFinishedCount] = useState(0) return items.every(item => item.status === 'done' || item.status === 'error')
}, [items])
const [saveTo, setSaveTo] = useState<SaveTo>('original') const [saveTo, setSaveTo] = useState<SaveTo>('original')
const [savePath, setSavePath] = useState('') const [savePath, setSavePath] = useState('')
@ -87,9 +98,13 @@ export const App = () => {
minWidth: 100, minWidth: 100,
}, },
file: { file: {
idealWidth: 150, idealWidth: 1000,
minWidth: 150, minWidth: 150,
}, },
operation: {
idealWidth: 80,
minWidth: 80,
},
}) })
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
@ -135,7 +150,6 @@ export const App = () => {
for (const file of files) { for (const file of files) {
setItems(prev => [...prev, { file, status: 'pending' }]) setItems(prev => [...prev, { file, status: 'pending' }])
} }
setTotalFilesNeedToProcess(prev => prev + files.length)
}) })
} }
@ -162,7 +176,6 @@ export const App = () => {
showDialog('当前文件列表已全部处理完毕,请重新添加新的文件。') showDialog('当前文件列表已全部处理完毕,请重新添加新的文件。')
return return
} }
setIsProcessing(true)
const ncmFiles: main.NcmFile[] = [] const ncmFiles: main.NcmFile[] = []
items.forEach(item => { items.forEach(item => {
ncmFiles.push({ ncmFiles.push({
@ -175,9 +188,6 @@ export const App = () => {
useEffect(() => { useEffect(() => {
EventsOn('file-status-changed', (index: number, status: Status) => { EventsOn('file-status-changed', (index: number, status: Status) => {
if (status == 'done' || status === 'error') {
setFinishedCount(prev => prev + 1)
}
setItems(prev => { setItems(prev => {
const newItems = [...prev] const newItems = [...prev]
newItems[index].status = status newItems[index].status = status
@ -186,20 +196,16 @@ export const App = () => {
}) })
}, []) }, [])
useEffect(() => {
if (finishedCount === totalFilesNeedToProcess) {
setFinishedCount(0)
setTotalFilesNeedToProcess(0)
setIsProcessing(false)
}
}, [finishedCount])
OnFileDrop((_x, _y, paths) => { OnFileDrop((_x, _y, paths) => {
let length = paths.length
for (const path of paths) { for (const path of paths) {
// only end with ncm
if (!path.endsWith('.ncm')) {
length--
continue
}
setItems(prev => [...prev, { file: path, status: 'pending' }]) setItems(prev => [...prev, { file: path, status: 'pending' }])
} }
console.log(paths.length, paths)
setTotalFilesNeedToProcess(prev => prev + paths.length)
}, false) }, false)
return ( return (
@ -225,10 +231,15 @@ export const App = () => {
</DialogSurface> </DialogSurface>
</Dialog> </Dialog>
<div className="flex space-between gap-3"> <div className="flex space-between gap-3">
<Button onClick={selectFiles}></Button> <Button onClick={selectFiles} icon={<DocumentAddRegular />}>
<Button onClick={() => setItems([])}></Button>
</Button>
<Button onClick={() => setItems([])} icon={<DeleteDismissRegular />}>
</Button>
<Button <Button
appearance="primary" appearance="primary"
icon={<WindowPlayRegular />}
onClick={() => { onClick={() => {
startProcess() startProcess()
}} }}
@ -297,6 +308,18 @@ export const App = () => {
</TableCellLayout> </TableCellLayout>
</TableCell> </TableCell>
<TableCell>{file.file}</TableCell> <TableCell>{file.file}</TableCell>
<TableCell>
<Button
size="small"
icon={<DeleteRegular />}
appearance="transparent"
onClick={() => {
setItems(prev => prev.filter((_, i) => i !== index))
}}
>
</Button>
</TableCell>
</TableRow> </TableRow>
))} ))}
</TableBody> </TableBody>