From 1d956be78370a5c6e5b3202cf6619f2c59fe7537 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Sat, 9 Dec 2023 12:09:19 +0700 Subject: [PATCH] fix: duplicate name on create with same name --- Services/client/src/stores/socket.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Services/client/src/stores/socket.ts b/Services/client/src/stores/socket.ts index 59d6692..92e2aab 100644 --- a/Services/client/src/stores/socket.ts +++ b/Services/client/src/stores/socket.ts @@ -1,6 +1,5 @@ import { defineStore } from 'pinia' import { reactive } from 'vue' -import { useFileInfoStore } from '@/stores/file-info-data' import { io } from 'socket.io-client' import { useTreeDataStore } from '@/stores/tree-data' import { storeToRefs } from 'pinia' @@ -53,15 +52,23 @@ export const useSocketStore = defineStore('socket', () => { }, ) - currentFolder.value.push({ - pathname: pathname, - name: pathArray[pathArray.length - 1], - status: true, - folder: [], - file: [], - }) + if ( + currentFolder.value.findIndex( + (v) => v.name === pathArray[pathArray.length - 1], + ) === -1 + ) { + currentFolder.value.push({ + pathname: pathname, + name: pathArray[pathArray.length - 1], + status: true, + folder: [], + file: [], + }) + } - listDataFolder.value = currentFolder.value + currentFolder.value.sort((a, b) => { + return a.name.localeCompare(b.name) + }) } })