snackbar 略改

This commit is contained in:
CrescentLeaf
2025-11-23 12:33:26 +08:00
parent 59191cc42e
commit 2cf9a20910

View File

@@ -199,15 +199,17 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
const cachedFiles = React.useRef({} as { [fileName: string]: ArrayBuffer }) const cachedFiles = React.useRef({} as { [fileName: string]: ArrayBuffer })
const cachedFileNamesCount = React.useRef({} as { [fileName: string]: number }) const cachedFileNamesCount = React.useRef({} as { [fileName: string]: number })
async function sendMessage() { async function sendMessage() {
let text = inputRef.current!.value
if (text.trim() == '') return
const sendingFilesSnackbar = snackbar({ const sendingFilesSnackbar = snackbar({
message: `上传文件到 [${chatInfo.title}]...`, message: `发送消息到 [${chatInfo.title}]...`,
placement: 'top', placement: 'top',
autoCloseDelay: 0, autoCloseDelay: 0,
}) })
let i = 1 let i = 1
let i2 = 0 let i2 = 0
const sendingFilesSnackbarId = setInterval(() => { const sendingFilesSnackbarId = setInterval(() => {
const len = Object.keys(cachedFiles.current).length const len = Object.keys(cachedFiles.current).filter((fileName) => text.indexOf(fileName)).length
sendingFilesSnackbar.textContent = i2 == len ? `发送消息到 [${chatInfo.title}]... (${i}s)` : `上传第 ${i2}/${len} 文件到 [${chatInfo.title}]... (${i}s)` sendingFilesSnackbar.textContent = i2 == len ? `发送消息到 [${chatInfo.title}]... (${i}s)` : `上传第 ${i2}/${len} 文件到 [${chatInfo.title}]... (${i}s)`
i++ i++
}, 1000) }, 1000)
@@ -216,8 +218,6 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
sendingFilesSnackbar.open = false sendingFilesSnackbar.open = false
} }
try { try {
let text = inputRef.current!.value
if (text.trim() == '') return
setIsMessageSending(true) setIsMessageSending(true)
for (const fileName of Object.keys(cachedFiles.current)) { for (const fileName of Object.keys(cachedFiles.current)) {
if (text.indexOf(fileName) != -1) { if (text.indexOf(fileName) != -1) {