fix: socket event

This commit is contained in:
Methapon2001 2023-12-15 10:26:11 +07:00
parent 51120ba49b
commit b83d2356e5
No known key found for this signature in database
GPG key ID: 849924FEF46BD132

View file

@ -43,15 +43,12 @@ const props = defineProps<{
}>()
const socket = io(import.meta.env.VITE_API_HOST)
socket.on('FileUpdate', (data: StorageFile) =>
replaceSearchItem(data.pathname, data),
)
socket.on('FileUpload', (data: StorageFile) =>
replaceSearchItem(data.pathname, data),
)
socket.on('FileUpdateMove', (data: { from: StorageFile; to: StorageFile }) =>
replaceSearchItem(data.from.pathname, data.to),
)
socket.on('FileUpload', (data: StorageFile) => {
replaceSearchItem(data.pathname, data)
})
socket.on('FileMove', (data: { from: StorageFile; to: StorageFile }) => {
replaceSearchItem(data.from.pathname, data.to)
})
function replaceSearchItem(pathname: string, data: StorageFile) {
const idx = foundFile.value.findIndex((v) => v.pathname === pathname)