@@ -41,7 +41,10 @@ useElementNavigation({
41
41
targetQuery: ' .notification-item, .notification-title' ,
42
42
})
43
43
44
- function isChecked(item : MinimalRepository | Thread ) {
44
+ function isChecked(item : MinimalRepository | Thread | null ) {
45
+ if (item == null )
46
+ return false
47
+
45
48
if (isRepository (item )) {
46
49
return store .notifications
47
50
.filter (isThread )
@@ -94,52 +97,98 @@ function isCheckable(item: MinimalRepository | Thread) {
94
97
.filter (thread => thread .repository .id === item .id )
95
98
.some (thread => thread .unread )
96
99
}
100
+ onScopeDispose (() => {
101
+ store .checkedItems .length = 0
102
+ })
97
103
98
104
useKey (' esc' , () => {
99
105
store .checkedItems = []
100
106
}, { prevent: true })
101
107
102
- onScopeDispose (() => {
103
- store .checkedItems .length = 0
108
+ const contextMenuThread = ref <Thread | null >(null )
109
+ const popoverTarget = ref <ReferenceElement | null >(null )
110
+ const popoverRef = ref <InstanceType <typeof Popover > | null >(null )
111
+
112
+ async function handleSelectMarkAsRead(triggeredByKeyboard = false ) {
113
+ if (triggeredByKeyboard ) {
114
+ if (store .checkedItems .length > 0 ) {
115
+ store .markCheckedNotificationsAsRead (AppStorage .get (' accessToken' )! )
116
+ store .checkedItems = []
117
+ return
118
+ }
119
+
120
+ if (contextMenuThread .value ) {
121
+ const thread = contextMenuThread .value
122
+ markNotificationAsRead (contextMenuThread .value .id , AppStorage .get (' accessToken' )! )
123
+ .then (() => {
124
+ store .removeNotificationById (thread .id )
125
+ })
126
+
127
+ return
128
+ }
129
+ }
130
+
131
+ if (! contextMenuThread .value )
132
+ return
133
+
134
+ if (isChecked (contextMenuThread .value )) {
135
+ store .markCheckedNotificationsAsRead (AppStorage .get (' accessToken' )! )
136
+ store .checkedItems = []
137
+ return
138
+ }
139
+
140
+ const thread = contextMenuThread .value
141
+ markNotificationAsRead (thread .id , AppStorage .get (' accessToken' )! )
142
+ .then (() => {
143
+ store .removeNotificationById (thread .id )
144
+ })
145
+ }
146
+
147
+ useKey (' m' , () => {
148
+ handleSelectMarkAsRead (true )
149
+ popoverRef .value ?.hide ()
150
+ })
151
+
152
+ function handleSelectOpen(triggeredByKeyboard = false ) {
153
+ if (triggeredByKeyboard ) {
154
+ if (store .checkedItems .length > 0 ) {
155
+ store .checkedItems .forEach (handleNotificationClick )
156
+ store .checkedItems = []
157
+ return
158
+ }
159
+
160
+ if (contextMenuThread .value ) {
161
+ handleNotificationClick (contextMenuThread .value )
162
+ return
163
+ }
164
+ }
165
+
166
+ if (! contextMenuThread .value )
167
+ return
168
+
169
+ if (isChecked (contextMenuThread .value ))
170
+ store .checkedItems .forEach (handleNotificationClick )
171
+ else
172
+ handleNotificationClick (contextMenuThread .value )
173
+
174
+ store .checkedItems = []
175
+ }
176
+
177
+ useKey (' o' , () => {
178
+ handleSelectOpen (true )
179
+ popoverRef .value ?.hide ()
104
180
})
105
181
106
- const contextMenuThread = ref <Thread | null >(null )
107
182
const contextMenuItems = computed (() => [
108
183
menuItem ({
109
184
key: ' read' ,
110
185
meta: { text: ' Mark as read' , icon: Icons .Check16 , key: ' M' },
111
- async onSelect() {
112
- if (! contextMenuThread .value )
113
- return
114
-
115
- if (isChecked (contextMenuThread .value )) {
116
- store .markCheckedNotificationsAsRead (AppStorage .get (' accessToken' )! )
117
- store .checkedItems = []
118
- return
119
- }
120
-
121
- markNotificationAsRead (contextMenuThread .value .id , AppStorage .get (' accessToken' )! )
122
- .then (() => {
123
- store .notifications = store .notifications .filter (notification => (
124
- notification .id !== contextMenuThread .value ! .id
125
- ))
126
- })
127
- },
186
+ onSelect : () => handleSelectMarkAsRead (),
128
187
}),
129
188
menuItem ({
130
189
key: ' open' ,
131
190
meta: { text: ' Open' , icon: Icons .LinkExternal16 , key: ' O' },
132
- onSelect() {
133
- if (! contextMenuThread .value )
134
- return
135
-
136
- if (isChecked (contextMenuThread .value ))
137
- store .checkedItems .forEach (handleNotificationClick )
138
- else
139
- handleNotificationClick (contextMenuThread .value )
140
-
141
- store .checkedItems = []
142
- },
191
+ onSelect : () => handleSelectOpen (),
143
192
}),
144
193
// menuItem({
145
194
// key: 'unsubscribe',
@@ -148,16 +197,13 @@ const contextMenuItems = computed(() => [
148
197
// }),
149
198
isChecked (contextMenuThread .value ! ) && menuItem ({
150
199
key: ' clear' ,
151
- meta: { text: ' Clear selections' , icon: Icons .Circle16 , key: ' ESC' },
200
+ meta: { text: ' Clear selections' , icon: Icons .Circle , key: ' ESC' },
152
201
onSelect : () => {
153
202
store .checkedItems = []
154
203
},
155
204
}),
156
205
])
157
206
158
- const popoverTarget = ref <ReferenceElement | null >(null )
159
- const popoverRef = ref <InstanceType <typeof Popover > | null >(null )
160
-
161
207
function handleThreadContextmenu(thread : Thread , event : MouseEvent ) {
162
208
if (! isChecked (thread ))
163
209
store .checkedItems = []
0 commit comments