diff --git a/components.d.ts b/components.d.ts index b5319bf7693e67fa4a592db7c18c4833b4d1f293..65ca4e7839ddb4c9e2f01e9d90f50076f24aec89 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 dd3b61ebbd0749d410ec67b46135912faf714183..a0d923ab01b1a2efc6b38589b5ee3c7068907fb2 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(); </script> <template> <div class="textContainer relative"> - <input ref="input" v-if="entityData?.title" type="text" v-model="entityData.title" @change="editTitle" @input="triggerResize" class="w-full mb-2 font-bold pl-2" /> - <textarea ref="textarea" v-model="entityData.text" class="w-full indent-5 resize-none pl-4 -ml-4 border-0 border-l-4 border-solid border-l-blue-400" @change="editText" @input="triggerResize" placeholder="Enter text..."/> + <input + ref="input" + v-if="entityData.title" + type="text" + v-model="entityData.title" + @change="editTitle" + @input="triggerResize" + class="w-full mb-2 font-bold pl-2" + /> + <textarea + ref="textarea" + v-model="entityData.text" + class="w-full indent-5 resize-none pl-4 -ml-4 border-0 border-l-4 border-solid border-l-blue-400" + @change="editText" + @input="triggerResize" + placeholder="Enter text..." + /> <button - v-if="!entityData.title" - @click.prevent="addTitle" - class="addTitleButton absolute top-0 left-4 bg-blue-500 py-0.5 px-2 rounded-md -translate-y-full border-2 border-solid border-black transition-all select-none" + v-if="!entityData?.title" + @click.prevent="addTitle" + class="addTitleButton absolute top-0 left-4 bg-blue-500 py-0.5 px-2 rounded-md -translate-y-full border-2 border-solid border-black transition-all select-none" > Add title </button> <button - @click.prevent="deleteEntity" - class="deleteEntityButton absolute top-0 right-4 bg-blue-500 py-0.5 px-2 rounded-md -translate-y-full border-2 border-solid border-black transition-all select-none" + @click.prevent="deleteEntity" + class="deleteEntityButton absolute top-0 right-4 bg-blue-500 py-0.5 px-2 rounded-md -translate-y-full border-2 border-solid border-black transition-all select-none" > <i class="pi pi-trash pr-2"></i>Delete </button> + <button + v-if="entityData?.title" + @click.prevent="deleteTitle" + class="deleteEntityButton absolute top-0 left-4 bg-blue-500 py-0.5 px-2 rounded-md -translate-y-full border-2 border-solid border-black transition-all select-none" + > + <i class="pi pi-trash pr-2"></i>Delete title + </button> </div> </template> @@ -76,7 +98,7 @@ textarea::-webkit-scrollbar { opacity: 0; } .textContainer:hover > .addTitleButton, -.textContainer:hover > .deleteEntityButton{ +.textContainer:hover > .deleteEntityButton { opacity: 100; } </style> diff --git a/src/helpers/index.ts b/src/helpers/index.ts index eb5badfc9a3fc44cbe6b582df3b6e8479680994e..b53eb64c71a4c2ff969f00c6fca278eb01fcf02b 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -1,5 +1,6 @@ import { useInterfaceStore } from '@/stores/interface'; import type { IEntity } from '@/interfaces/environment'; +import { useDataStore } from '@/stores/data'; export async function uploadFile($event: Event) { const target = $event.target as HTMLInputElement; @@ -23,3 +24,13 @@ export function setDefaultHomeBackground() { ); localStorage.removeItem('homeBackgroundUrl'); } + +export const editEntity = (newState: IEntity, entityUuid: string) => { + const dataStore = useDataStore(); + let prevState = dataStore.homeEntities; + prevState = prevState.map((entity: IEntity) => { + if (entity.uuid !== entityUuid) return entity; + return newState; + }); + dataStore.editHomeEntities(prevState); +}; diff --git a/src/modules/EntityItem.vue b/src/modules/EntityItem.vue index b2732984d98cb9a9c9e52fe192df1f71e3506c77..f485f616ced240558414dd1b054ab3d14c1c946c 100644 --- a/src/modules/EntityItem.vue +++ b/src/modules/EntityItem.vue @@ -10,7 +10,7 @@ defineProps<Props>(); <template> <div> - <TextItem v-if="entity.type === 'text'" :entityData="entity"/> + <TextItem v-if="entity.type === 'text'" :entityData="entity" /> </div> </template>