From c9dde796519ce9e890b5dacc1d05c0bf9173bd1a Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Sat, 3 Jun 2023 06:53:03 +0300 Subject: [PATCH] increase the performance, remove unnecessary code and rename selectedItem to selectedPath --- app.vue | 38 ++++++++++++++++------------------ components/tree-view.vue | 6 +++--- composables/files-manager.ts | 2 +- composables/history-manager.ts | 19 ++++++++++------- composables/states.ts | 4 ++-- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/app.vue b/app.vue index 6e486e1..ceed2cf 100644 --- a/app.vue +++ b/app.vue @@ -5,25 +5,24 @@ import { useDisplay } from 'vuetify/lib/framework.mjs'; import { HistoryManager } from './composables/history-manager'; import { FilesManager } from './composables/files-manager'; - let display = useDisplay(); let drawer = ref(!display.mdAndDown.value); let loadingModel = ref(false); let files = ref([]); let filesList = ref([]); -let selectedItem = useSelectedItem(); +let selectedPath = useSelectedPath(); let filesGridList = ref([]) let selectedList = ref([]); -let history = new HistoryManager(selectedItem, filesList); -let fileManager = new FilesManager(filesList); +let filesManager = new FilesManager(filesList); +let history = new HistoryManager(filesManager); watchEffect(async () => { if (files.value?.[0]) { loadingModel.value = true; filesList.value = []; - fileManager.loadArchive(files.value?.[0]); + filesManager.loadArchive(files.value?.[0]); loadingModel.value = false; } @@ -32,7 +31,7 @@ watchEffect(async () => { function onDrop(e: any) { if (!e.dataTransfer.files.length) return; files.value = e.dataTransfer.files; - selectedItem.value = '/'; + selectedPath.value = '/'; } function preventDefaults(e: any) { @@ -54,14 +53,16 @@ onUnmounted(() => { }) watchEffect(() => { - filesGridList.value = fileManager.getFile(selectedItem.value)?.content || []; + const file = filesManager.getFile(selectedPath.value); + filesGridList.value = file?.isFolder ? file.content : []; + selectedList.value = []; for (const selectedElement of document.querySelectorAll(".selectable.selected")) { selectedElement.classList.remove("selected"); } }) -let dragContainer = document.querySelector(".select-area"); +const dragContainer = document.querySelector(".select-area"); function onSelectStart(e: any) { e.added.forEach((el: any) => { @@ -87,10 +88,7 @@ function onSelectEnd(e: any) { // step up from current path function stepUp(path: string) { - let pathArray = path.split("/"); - if (path.endsWith("/")) { - pathArray.pop(); - } + const pathArray = path.split("/"); pathArray.pop(); return (pathArray.join("/") || "/"); } @@ -105,7 +103,7 @@ function stepUp(path: string) { @@ -121,12 +119,12 @@ function stepUp(path: string) { @click="history.redo();"> - + + v-model="selectedPath"> @@ -136,7 +134,7 @@ function stepUp(path: string) { + @click="files = []; selectedPath = '/'; selectedList = []; filesGridList = []; filesList = []; history.reset()"> @@ -146,13 +144,13 @@ function stepUp(path: string) { -