44 class =" item"
55 :class =" {
66 'is-selected': !isFocused && isSelected,
7- 'is-focused': isFocused
7+ 'is-focused': isFocused,
8+ 'is-highlighted': isHighlighted
89 }"
910 @click =" isFocused = true"
11+ @contextmenu =" onClickContextMenu"
1012 >
1113 <div class =" header" >
1214 <div class =" name" >
2729</template >
2830
2931<script setup lang="ts">
32+ import { ipc } from ' @/electron'
33+ import { useFolderStore } from ' @/store/folders'
34+ import { useSnippetStore } from ' @/store/snippets'
35+ import type { ContextMenuPayload , ContextMenuResponse } from ' @@/types'
3036import { onClickOutside } from ' @vueuse/core'
3137import { computed , ref } from ' vue'
3238
3339interface Props {
40+ id: string
3441 name: string
3542 folder: string
3643 date: number
@@ -39,13 +46,52 @@ interface Props {
3946
4047const props = defineProps <Props >()
4148
49+ const snippetStore = useSnippetStore ()
50+ const folderStore = useFolderStore ()
51+
4252const itemRef = ref ()
4353const isFocused = ref (false )
54+ const isHighlighted = ref (false )
4455
4556onClickOutside (itemRef , () => {
4657 isFocused .value = false
58+ isHighlighted .value = false
4759})
4860
61+ const onClickContextMenu = async () => {
62+ isHighlighted .value = true
63+
64+ const { action } = await ipc .invoke <ContextMenuResponse , ContextMenuPayload >(
65+ ' context-menu:snippet' ,
66+ {
67+ name: props .name
68+ }
69+ )
70+
71+ if (action === ' delete' ) {
72+ snippetStore .patchSnippetsById (props .id , {
73+ isDeleted: true
74+ })
75+
76+ await snippetStore .getSnippetsByFolderIds (folderStore .selectedIds ! )
77+ snippetStore .snippet = snippetStore .snippetsNonDeleted [0 ]
78+ }
79+
80+ if (action === ' duplicate' ) {
81+ await snippetStore .duplicateSnippetById (props .id )
82+ await snippetStore .getSnippetsByFolderIds (folderStore .selectedIds ! )
83+ }
84+
85+ if (action === ' favorites' ) {
86+ snippetStore .patchSnippetsById (props .id , {
87+ isFavorites: true
88+ })
89+ await snippetStore .getSnippetsByFolderIds (folderStore .selectedIds ! )
90+ }
91+
92+ isHighlighted .value = false
93+ }
94+
4995const dateFormat = computed (() =>
5096 new Intl .DateTimeFormat (' ru' ).format (props .date )
5197)
@@ -56,6 +102,7 @@ const dateFormat = computed(() =>
56102 padding : var (--spacing-xs ) var (--spacing-sm );
57103 position : relative ;
58104 z-index : 2 ;
105+ user-select : none ;
59106 & ::after {
60107 content : ' ' ;
61108 height : 1px ;
@@ -65,11 +112,12 @@ const dateFormat = computed(() =>
65112 bottom : 1px ;
66113 }
67114 & .is-focused ,
68- & .is-selected {
115+ & .is-selected ,
116+ & .is-highlighted {
69117 & ::before {
70118 content : ' ' ;
71119 position : absolute ;
72- top : -2 px ;
120+ top : 0 px ;
73121 left : 8px ;
74122 right : 8px ;
75123 bottom : 0px ;
@@ -95,6 +143,17 @@ const dateFormat = computed(() =>
95143 color : var (--color-text );
96144 }
97145 }
146+ & .is-highlighted {
147+ & ::before {
148+ top : 0px ;
149+ left : 10px ;
150+ right : 10px ;
151+ bottom : 2px ;
152+ border-radius : 5px ;
153+ // z-index: 3;
154+ outline : 2px solid var (--color-primary );
155+ }
156+ }
98157}
99158.name {
100159 display : table ;
0 commit comments