From eb40d098ff9cbc1c0365f47eaba4b170a2e018dd Mon Sep 17 00:00:00 2001 From: somnetsak123 Date: Tue, 12 Dec 2023 14:54:57 +0700 Subject: [PATCH] fix: socket CreateFolder folder doubly --- Services/client/src/stores/storage.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Services/client/src/stores/storage.ts b/Services/client/src/stores/storage.ts index 88df8df..38b2ed9 100644 --- a/Services/client/src/stores/storage.ts +++ b/Services/client/src/stores/storage.ts @@ -2,6 +2,7 @@ import { computed, reactive, ref } from 'vue' import { defineStore } from 'pinia' import { io } from 'socket.io-client' import axios from 'axios' +import { useErrorStore } from '@/stores/error' import api from '@/services/HttpService' @@ -69,6 +70,7 @@ function consistantPath(path: string | string[]) { } const useStorage = defineStore('storageStore', () => { + const error = useErrorStore() const loader = useLoader() const init = ref(false) const folder = ref>({}) @@ -201,12 +203,19 @@ const useStorage = defineStore('storageStore', () => { const path = consistantPath(arr.slice(0, -1)) if (folder.value[path]) { - folder.value[path].push({ - pathname: data.pathname, - name: data.name, - createdAt: data.createdAt, - createdBy: data.createdBy, - }) + const idx = folder.value[path].findIndex( + (v) => v.pathname === currentInfo.path, + ) + + if (idx !== -1) { + folder.value[path].push({ + pathname: data.pathname, + name: data.name, + createdAt: data.createdAt, + createdBy: data.createdBy, + }) + } + folder.value[path].sort((a, b) => a.pathname.localeCompare(b.pathname)) } }, @@ -271,6 +280,11 @@ const useStorage = defineStore('storageStore', () => { (v) => v.pathname !== data.pathname, ) } + + const idx = folder.value[path].findIndex( + (v) => v.pathname === currentInfo.path, + ) + console.log(idx) }) socket.on('FileUpload', (data: StorageFile) => { const arr = data.pathname.split('/').filter(Boolean)