diff --git a/Services/client/src/modules/01_user/components/SearchBar.vue b/Services/client/src/modules/01_user/components/SearchBar.vue index f76e1e8..c4b35dd 100644 --- a/Services/client/src/modules/01_user/components/SearchBar.vue +++ b/Services/client/src/modules/01_user/components/SearchBar.vue @@ -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() !== '') {