fix: edit file info on search should change

This commit is contained in:
Methapon2001 2023-12-13 10:29:07 +07:00
parent 2c90d99338
commit b98f7d5980
No known key found for this signature in database
GPG key ID: 849924FEF46BD132

View file

@ -3,6 +3,7 @@ import { ref, watch } from 'vue'
import { storeToRefs } from 'pinia'
import axiosClient from '@/services/HttpService'
import mime from 'mime'
import io from 'socket.io-client'
import type { StorageFile } from '@/stores/storage'
import { useSearchDataStore } from '@/stores/searched-data'
@ -14,6 +15,7 @@ import AdvancedSearch from '@/modules/01_user/components/AdvancedSearch.vue'
const loaderStore = useLoader()
const { isFilePreview } = storeToRefs(useFileInfoStore())
const {
foundFile,
isSearch,
isAdvSearchCall,
isActFoundFile,
@ -39,6 +41,24 @@ const props = defineProps<{
mode: 'admin' | 'user'
}>()
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),
)
function replaceSearchItem(pathname: string, data: StorageFile) {
const idx = foundFile.value.findIndex((v) => v.pathname === pathname)
if (idx !== -1) foundFile.value[idx] = data
}
async function submitSearch() {
isFilePreview.value = false
if (searchData.value.value.trim() !== '') {