Skip to content

Commit e85969b

Browse files
committed
feat: mark as done on unsubscribe
Signed-off-by: Adam Setch <[email protected]>
1 parent add13a9 commit e85969b

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

src/__mocks__/state-mocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const mockNotificationSettings = {
8787
groupBy: GroupBy.REPOSITORY,
8888
participating: false,
8989
markAsDoneOnOpen: false,
90+
markAsDoneOnUnsubscribe: false,
9091
delayNotificationState: false,
9192
};
9293

src/components/settings/NotificationSettings.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,34 @@ describe('routes/components/settings/NotificationSettings.tsx', () => {
123123
expect(updateSetting).toHaveBeenCalledWith('markAsDoneOnOpen', false);
124124
});
125125

126+
it('should toggle the markAsDoneOnUnsubscribe checkbox', async () => {
127+
await act(async () => {
128+
render(
129+
<AppContext.Provider
130+
value={{
131+
auth: mockAuth,
132+
settings: mockSettings,
133+
updateSetting,
134+
}}
135+
>
136+
<MemoryRouter>
137+
<NotificationSettings />
138+
</MemoryRouter>
139+
</AppContext.Provider>,
140+
);
141+
});
142+
143+
fireEvent.click(screen.getByLabelText('Mark as done on unsubscribe'), {
144+
target: { checked: true },
145+
});
146+
147+
expect(updateSetting).toHaveBeenCalledTimes(1);
148+
expect(updateSetting).toHaveBeenCalledWith(
149+
'markAsDoneOnUnsubscribe',
150+
false,
151+
);
152+
});
153+
126154
it('should toggle the delayNotificationState checkbox', async () => {
127155
await act(async () => {
128156
render(

src/components/settings/NotificationSettings.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ export const NotificationSettings: FC = () => {
6363
</div>
6464
}
6565
/>
66+
<Checkbox
67+
name="markAsDoneOnUnsubscribe"
68+
label="Mark as done on unsubscribe"
69+
checked={settings.markAsDoneOnUnsubscribe}
70+
onChange={(evt) =>
71+
updateSetting('markAsDoneOnUnsubscribe', evt.target.checked)
72+
}
73+
tooltip={
74+
<div>
75+
<strong>Mark as Done</strong> feature is supported in GitHub Cloud
76+
and GitHub Enterprise Server 3.13 or later.
77+
</div>
78+
}
79+
/>
6680
<Checkbox
6781
name="delayNotificationState"
6882
label="Delay notification state"

src/context/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const defaultNotificationSettings = {
6767
groupBy: GroupBy.REPOSITORY,
6868
participating: false,
6969
markAsDoneOnOpen: false,
70+
markAsDoneOnUnsubscribe: false,
7071
delayNotificationState: false,
7172
};
7273

src/hooks/useNotifications.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ export const useNotifications = (): NotificationsState => {
176176
notification.account.hostname,
177177
notification.account.token,
178178
);
179-
await markNotificationRead(state, notification);
179+
180+
if (state.settings.markAsDoneOnUnsubscribe) {
181+
await markNotificationDone(state, notification);
182+
} else {
183+
await markNotificationRead(state, notification);
184+
}
180185
} catch (err) {
181186
log.error(
182187
'Error occurred while unsubscribing from notification thread',

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ interface NotificationSettingsState {
7878
participating: boolean;
7979
showNotifications: boolean;
8080
markAsDoneOnOpen: boolean;
81+
markAsDoneOnUnsubscribe: boolean;
8182
delayNotificationState: boolean;
8283
groupBy: GroupBy;
8384
}

0 commit comments

Comments
 (0)