Skip to content

Commit 764d71e

Browse files
committed
Add "mark as read on open" setting (#50)
1 parent 3504bc5 commit 764d71e

File tree

7 files changed

+80
-39
lines changed

7 files changed

+80
-39
lines changed

src/assets/main.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $colors: (
44
text-faded: rgb(190, 190, 190) rgb(190, 190, 190),
55
text: rgb(255, 255, 255) rgb(255, 255, 255),
66
gray-bright: rgb(150, 150, 150) rgb(150, 150, 150),
7-
switch-dot: rgb(200, 200, 200) rgb(200, 200, 200),
7+
switch-dot: rgb(255, 255, 255) rgb(255, 255, 255),
88
gray: rgb(95, 95, 95) rgb(95, 95, 95),
99
switch-bg: var(--gray) var(--gray),
1010
content-bg: rgba(30, 30, 30, 8) rgb(30, 30, 30),
@@ -25,7 +25,7 @@ $colors: (
2525
gray-bright: rgb(105, 105, 105) rgb(115, 115, 115),
2626
gray: rgb(160, 160, 160) rgb(160, 160, 160),
2727
switch-bg: rgb(145, 145, 145) rgb(168, 168, 168),
28-
switch-dot: rgb(160, 160, 160) rgb(255, 255, 255),
28+
switch-dot: rgb(255, 255, 255) rgb(255, 255, 255),
2929
content-bg: rgba(220, 220, 220, .75) rgb(220, 220, 220),
3030
page-header-bg: rgba(212, 212, 212, .6) rgb(212, 212, 212),
3131
popover-bg: rgba(210, 210, 210, .8) rgb(240, 240, 240),

src/components/SettingItem.vue

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<script lang="ts" setup>
2+
import { Icons } from './Icons'
3+
import SlotRef from './SlotRef.vue'
4+
import Tooltip from './Tooltip.vue'
5+
26
interface Props {
37
title: string
8+
description?: string
49
}
510
611
defineProps<Props>()
@@ -10,6 +15,23 @@ defineProps<Props>()
1015
<div class="setting-item">
1116
<div class="setting-item-title">
1217
{{ title }}
18+
19+
<SlotRef v-if="typeof description === 'string' && description.trim().length > 0">
20+
<template #default>
21+
<div class="setting-item-title-description">
22+
<Icons.Question />
23+
</div>
24+
</template>
25+
26+
<template #ref="{ el }">
27+
<Tooltip
28+
style="width: 275px; text-align: left"
29+
:text="description"
30+
:target="el"
31+
position="top"
32+
/>
33+
</template>
34+
</SlotRef>
1335
</div>
1436
<div class="setting-item-right">
1537
<slot />
@@ -37,6 +59,15 @@ defineProps<Props>()
3759
color: var(--text);
3860
font-size: 14px;
3961
padding-left: 15px;
62+
position: relative;
63+
display: inline-flex;
64+
align-items: center;
65+
66+
&-description {
67+
display: inline-flex;
68+
margin-left: 5px;
69+
color: var(--accent-color);
70+
}
4071
}
4172
4273
&-right {

src/components/Switch.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function handleClick() {
4646
background-color: var(--accent-color);
4747
4848
.switch-dot {
49-
background-color: #fff;
5049
transform: translateX(11px);
5150
}
5251
}

src/pages/HomePage.vue

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,28 @@ const store = useStore()
2626
if (store.currentPageState.fetchOnEnter)
2727
store.fetchNotifications(true)
2828
29-
function handleNotificationClick(notification: Thread) {
30-
const url = toGithubWebURL({ notification, userId: AppStorage.get('user')!.id })
29+
function handleOpenNotification(thread: Thread) {
30+
const url = toGithubWebURL({ notification: thread, userId: AppStorage.get('user')!.id })
3131
open(url)
3232
}
3333
34+
function handleClickNotification(thread: Thread) {
35+
handleOpenNotification(thread)
36+
37+
if (AppStorage.get('markAsReadOnOpen')) {
38+
const snapshot = store.notifications.slice(0)
39+
40+
try {
41+
notificationApiMutex.runExclusive(() => markNotificationAsRead(thread.id, AppStorage.get('accessToken')!))
42+
store.removeNotificationById(thread.id)
43+
}
44+
catch (error) {
45+
console.log(error)
46+
store.notifications = snapshot
47+
}
48+
}
49+
}
50+
3451
function handleRepoClick(repoFullName: string) {
3552
open(`https://github.com/${repoFullName}`)
3653
}
@@ -158,29 +175,23 @@ async function handleSelectMarkAsRead(triggeredByKeyboard = false) {
158175
}
159176
}
160177
161-
function handleSelectOpen(triggeredByKeyboard = false) {
162-
if (triggeredByKeyboard) {
163-
if (store.checkedItems.length > 0) {
164-
store.checkedItems.forEach(handleNotificationClick)
165-
store.checkedItems = []
166-
return
167-
}
178+
async function handleSelectOpen(triggeredByKeyboard = false) {
179+
if (
180+
(triggeredByKeyboard && store.checkedItems.length > 0)
181+
|| (contextMenuThread.value && isChecked(contextMenuThread.value))) {
182+
store.checkedItems.forEach(handleOpenNotification)
168183
169-
if (contextMenuThread.value) {
170-
handleNotificationClick(contextMenuThread.value)
171-
return
172-
}
184+
if (AppStorage.get('markAsReadOnOpen'))
185+
store.markCheckedNotificationsAsRead(AppStorage.get('accessToken')!)
186+
187+
store.checkedItems = []
188+
return
173189
}
174190
175191
if (!contextMenuThread.value)
176192
return
177193
178-
if (isChecked(contextMenuThread.value))
179-
store.checkedItems.forEach(handleNotificationClick)
180-
else
181-
handleNotificationClick(contextMenuThread.value)
182-
183-
store.checkedItems = []
194+
handleClickNotification(contextMenuThread.value)
184195
}
185196
186197
async function handleSelectUnsubscribe(triggeredByKeyboard = false) {
@@ -358,7 +369,7 @@ whenever(() => store.skeletonVisible, () => {
358369
:indeterminate="isIndeterminate(item)"
359370
:checkboxVisible="store.checkedItems.length > 0"
360371
@contextmenu="handleThreadContextmenu"
361-
@click:notification="handleNotificationClick"
372+
@click:notification="handleClickNotification"
362373
@click:repo="handleRepoClick"
363374
@update:checked="(value) => handleUpdateChecked(item, value)"
364375
/>

src/pages/SettingsPage.vue

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const soundsEnabled = AppStorage.asRef('soundsEnabled')
3333
const openAtStartup = AppStorage.asRef('openAtStartup')
3434
const showOnlyParticipating = AppStorage.asRef('showOnlyParticipating')
3535
const showReadNotifications = AppStorage.asRef('showReadNotifications')
36+
const markAsReadOnOpen = AppStorage.asRef('markAsReadOnOpen')
3637
3738
const accessToken = AppStorage.asComputed('accessToken')
3839
@@ -211,19 +212,13 @@ function handleScroll(e: Event) {
211212
</PageHeader>
212213

213214
<SettingItem title="Sounds">
214-
<Switch
215-
:modelValue="soundsEnabled"
216-
@update:modelValue="soundsEnabled = $event"
217-
/>
215+
<Switch v-model="soundsEnabled" />
218216
</SettingItem>
219217

220218
<Separator style="margin: 2px auto" />
221219

222220
<SettingItem title="Open at startup">
223-
<Switch
224-
:modelValue="openAtStartup"
225-
@update:modelValue="openAtStartup = $event"
226-
/>
221+
<Switch v-model="openAtStartup" />
227222
</SettingItem>
228223

229224
<Separator style="margin: 2px auto" />
@@ -243,19 +238,22 @@ function handleScroll(e: Event) {
243238
</PageHeader>
244239

245240
<SettingItem title="Show only participating">
246-
<Switch
247-
:modelValue="showOnlyParticipating"
248-
@update:modelValue="showOnlyParticipating = $event"
249-
/>
241+
<Switch v-model="showOnlyParticipating" />
250242
</SettingItem>
251243

252244
<Separator style="margin: 2px auto" />
253245

254246
<SettingItem title="Show read notifications">
255-
<Switch
256-
:modelValue="showReadNotifications"
257-
@update:modelValue="showReadNotifications = $event"
258-
/>
247+
<Switch v-model="showReadNotifications" />
248+
</SettingItem>
249+
250+
<Separator style="margin: 2px auto" />
251+
252+
<SettingItem
253+
title="Mark as read on open"
254+
description="When you open some notifications, Github marks them as read automatically, but for some it doesn't."
255+
>
256+
<Switch v-model="markAsReadOnOpen" />
259257
</SettingItem>
260258
</div>
261259
</div>

src/storage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const storage = shallowReactive<AppStorageContext>({
1414
soundsEnabled: true,
1515
showReadNotifications: false,
1616
showSystemNotifications: false,
17+
markAsReadOnOpen: false,
1718
colorPreference: ColorPreference.System,
1819
})
1920

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface AppStorageContext {
1616
soundsEnabled: boolean
1717
showReadNotifications: boolean
1818
showSystemNotifications: boolean
19+
markAsReadOnOpen: boolean
1920
colorPreference: ColorPreference
2021
}
2122

0 commit comments

Comments
 (0)