Skip to content

Commit 6f3d787

Browse files
authored
feat: support mark all as read (#152)
1 parent dd00450 commit 6f3d787

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

source/github-notifications-preview.jsx

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,45 @@ async function openDropdown({currentTarget: indicator}) {
122122
if (!isOpen(dropdown) && list.length > 0) {
123123
const container = $('.NPG-dropdown', dropdown);
124124
empty(container);
125+
const dropdownHeader = (
126+
<div
127+
style={{
128+
backgroundColor: 'var(--bgColor-muted, var(--color-canvas-subtle))',
129+
}}
130+
>
131+
<div
132+
style={{
133+
cursor: 'pointer',
134+
width: 'fit-content',
135+
marginLeft: 'auto',
136+
padding: '4px 10px',
137+
color: 'var(--fgColor-accent, var(--color-accent-fg))',
138+
}}
139+
onClick={() => {
140+
for (const form of $$(
141+
'.NPG-dropdown .js-notifications-list-item form[action=\'/notifications/beta/archive\']',
142+
)) {
143+
form.querySelector('button[type=submit]').click();
144+
}
145+
}}
146+
>
147+
<svg
148+
className='octicon octicon-checklist'
149+
xmlns='http://www.w3.org/2000/svg'
150+
width={16}
151+
height={16}
152+
viewBox='0 0 16 16'
153+
role='img'
154+
aria-hidden='true'
155+
>
156+
<path d='M2.5 1.75v11.5c0 .138.112.25.25.25h3.17a.75.75 0 0 1 0 1.5H2.75A1.75 1.75 0 0 1 1 13.25V1.75C1 .784 1.784 0 2.75 0h8.5C12.216 0 13 .784 13 1.75v7.736a.75.75 0 0 1-1.5 0V1.75a.25.25 0 0 0-.25-.25h-8.5a.25.25 0 0 0-.25.25Zm13.274 9.537v-.001l-4.557 4.45a.75.75 0 0 1-1.055-.008l-1.943-1.95a.75.75 0 0 1 1.062-1.058l1.419 1.425 4.026-3.932a.75.75 0 1 1 1.048 1.074ZM4.75 4h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM4 7.75A.75.75 0 0 1 4.75 7h2a.75.75 0 0 1 0 1.5h-2A.75.75 0 0 1 4 7.75Z'/>
157+
</svg>
158+
&nbsp;&nbsp;
159+
<span>Mark all as read</span>
160+
</div>
161+
</div>
162+
);
163+
container.append(dropdownHeader);
125164
container.append(...list);
126165

127166
delegate('.NPG-dropdown button', 'click', async event => {
@@ -145,7 +184,7 @@ async function openDropdown({currentTarget: indicator}) {
145184

146185
// Remove group if last notification
147186
if ($$('.js-notifications-list-item', group).length === 0) {
148-
group.remove();
187+
group?.remove();
149188
}
150189
} else {
151190
form.classList.add('mark-all-as-read-confirmed');
@@ -156,6 +195,12 @@ async function openDropdown({currentTarget: indicator}) {
156195
item.remove();
157196
}
158197
}
198+
199+
// All notifications are read, remove the header
200+
if ($$('.js-notifications-list-item, .js-notifications-group').length === 0) {
201+
dropdownHeader.remove();
202+
closeDropdown();
203+
}
159204
});
160205

161206
// Improve style when they're grouped by repo

0 commit comments

Comments
 (0)