From 09952c18946d467159487d76ed922e89d3bb4054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=9C=D0=B0?= =?UTF-8?q?=D0=BB=D1=8E=D0=B3=D0=B8=D0=BD?= Date: Thu, 8 Aug 2024 15:53:29 +0500 Subject: [PATCH 1/3] refactor entityText --- components.d.ts | 5 +- src/components/entities/TextItem.vue | 68 ++++++++++++++++++---------- src/helpers/index.ts | 11 +++++ src/modules/EntityItem.vue | 2 +- 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/components.d.ts b/components.d.ts index b5319bf..65ca4e7 100644 --- a/components.d.ts +++ b/components.d.ts @@ -2,7 +2,7 @@ // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 -export {}; +export {} /* prettier-ignore */ declare module 'vue' { @@ -13,14 +13,11 @@ declare module 'vue' { Divider: typeof import('primevue/divider')['default'] Drawer: typeof import('primevue/drawer')['default'] LogoAndLabel: typeof import('./src/components/LogoAndLabel.vue')['default'] - Popover: typeof import('primevue/popover')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] - ScrollPanel: typeof import('primevue/scrollpanel')['default'] SpeedDial: typeof import('primevue/speeddial')['default'] Splitter: typeof import('primevue/splitter')['default'] SplitterPanel: typeof import('primevue/splitterpanel')['default'] - Textarea: typeof import('primevue/textarea')['default'] TextItem: typeof import('./src/components/entities/TextItem.vue')['default'] Tree: typeof import('primevue/tree')['default'] UserInfoHeaderWithSettings: typeof import('./src/components/UserInfoHeaderWithSettings.vue')['default'] diff --git a/src/components/entities/TextItem.vue b/src/components/entities/TextItem.vue index dd3b61e..a0d923a 100644 --- a/src/components/entities/TextItem.vue +++ b/src/components/entities/TextItem.vue @@ -2,7 +2,8 @@ import type { IText } from '@/interfaces/entities'; import type { IEntity } from '@/interfaces/environment'; import { useDataStore } from '@/stores/data'; -import {useTextareaAutosize} from "@vueuse/core"; +import { useTextareaAutosize } from '@vueuse/core'; +import { editEntity } from '@/helpers'; interface Props { entityData: IText; @@ -12,53 +13,74 @@ const entityData = ref(props.entityData); const dataStore = useDataStore(); -const editEntity = (newState: IEntity) => { - let prevState = dataStore.homeEntities; - prevState = prevState.map((entity: IEntity) => { - if (entity.uuid !== entityData.value.uuid) return entity; - return newState; - }); - dataStore.editHomeEntities(prevState); -}; - const addTitle = () => { - editEntity({ ...entityData.value, title: 'Title' }); + editEntity({ ...entityData.value, title: 'Title' }, entityData.value.uuid); entityData.value = { ...entityData.value, title: 'Title' }; }; const editTitle = () => { - editEntity({ ...entityData.value, title: entityData.value.title }); + editEntity({ ...entityData.value, title: entityData.value.title }, entityData.value.uuid); }; const editText = () => { - editEntity({ ...entityData.value, text: entityData.value.text }); + editEntity({ ...entityData.value, text: entityData.value.text }, entityData.value.uuid); }; const deleteEntity = () => { let prevState = dataStore.homeEntities; prevState = prevState.filter((entity: IEntity) => entity.uuid !== entityData.value.uuid); dataStore.editHomeEntities(prevState); -} -const { textarea, triggerResize } = useTextareaAutosize(); +}; + +const deleteTitle = () => { + const newState = { ...entityData.value }; + delete newState.title; + editEntity({ ...newState }, entityData.value.uuid); + entityData.value = newState; +}; + +const { textarea, triggerResize } = useTextareaAutosize();