Skip to content

Commit b3eb1f1

Browse files
authored
Show something useful when there are no notifications in the notifications view (#6896)
Fixes #6856
1 parent bbb5022 commit b3eb1f1

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@
16961696
},
16971697
{
16981698
"view": "notifications:github",
1699-
"when": "ReposManagerStateContext == RepositoriesLoaded && github:notificationCount == 0",
1699+
"when": "ReposManagerStateContext == RepositoriesLoaded && github:notificationCount == -1",
17001700
"contents": "%welcome.github.notifications.contents%"
17011701
}
17021702
],

src/notifications/notificationsManager.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import { commands, contexts } from '../common/executeCommands';
78
import { Disposable } from '../common/lifecycle';
89
import { EventType, TimelineEvent } from '../common/timelineEvent';
910
import { toNotificationUri } from '../common/uri';
@@ -172,6 +173,7 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
172173
}
173174

174175
const notifications = Array.from(this._notifications.values());
176+
this._updateContext();
175177
this._onDidChangeNotifications.fire(notifications);
176178

177179
return {
@@ -180,6 +182,12 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
180182
};
181183
}
182184

185+
private _updateContext(): void {
186+
const notificationCount = this._notifications.size;
187+
commands.setContext(contexts.NOTIFICATION_COUNT, notificationCount === 0 ? -1 : notificationCount);
188+
}
189+
190+
183191
public getNotification(key: string): NotificationTreeItem | undefined {
184192
return this._notifications.get(key);
185193
}
@@ -218,6 +226,7 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
218226

219227
this._onDidChangeNotifications.fire([notification]);
220228
this._notifications.delete(notificationIdentifier.notificationKey);
229+
this._updateContext();
221230

222231
this._refresh(false);
223232
}
@@ -230,6 +239,7 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
230239

231240
this._onDidChangeNotifications.fire([notification]);
232241
this._notifications.delete(notificationIdentifier.notificationKey);
242+
this._updateContext();
233243

234244
this._refresh(false);
235245
}

src/notifications/notificationsProvider.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as vscode from 'vscode';
77
import { AuthProvider } from '../common/authentication';
8-
import { commands, contexts } from '../common/executeCommands';
98
import { Disposable } from '../common/lifecycle';
109
import { EXPERIMENTAL_NOTIFICATIONS_PAGE_SIZE, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
1110
import { OctokitCommon } from '../github/common';
@@ -102,7 +101,6 @@ export class NotificationsProvider extends Disposable {
102101
.map((notification: OctokitCommon.Notification) => parseNotification(notification))
103102
.filter(notification => !!notification) as Notification[];
104103

105-
commands.setContext(contexts.NOTIFICATION_COUNT, notifications.length);
106104
return { notifications, hasNextPage: headers.link?.includes(`rel="next"`) === true };
107105
}
108106

0 commit comments

Comments
 (0)