Skip to content

Commit 52ad15d

Browse files
committed
feat: update toolbar title based on the current active view
1 parent ffbaa24 commit 52ad15d

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/extensionsIntegrated/CustomSnippets/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ define(function (require, exports, module) {
3939
_registerHandlers();
4040

4141
$("#filter-snippets-input").val("");
42+
UIHelper.initializeListViewToolbarTitle();
4243
SnippetsList.showSnippetsList(); // to show the snippets list in the snippets panel
4344
}
4445

@@ -54,6 +55,7 @@ define(function (require, exports, module) {
5455
customSnippetsPanel.show();
5556

5657
$("#filter-snippets-input").val("");
58+
UIHelper.initializeListViewToolbarTitle();
5759
SnippetsList.showSnippetsList(); // we just remake the snippets list UI to make sure it is always on point
5860
}
5961
}

src/extensionsIntegrated/CustomSnippets/src/UIHelper.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable no-invalid-this */
22
define(function (require, exports, module) {
3+
const Global = require("./global");
4+
35
/**
46
* This function is called when there are no available snippets to display
57
* this is called inside the 'showSnippetsList' function inside the snippetsList.js file
@@ -48,19 +50,22 @@ define(function (require, exports, module) {
4850
const $backToListMenuBtn = $("#back-to-list-menu-btn");
4951
const $addNewSnippetBtn = $("#add-new-snippet-btn");
5052
const $filterSnippetsPanel = $("#filter-snippets-panel");
53+
const $toolbarTitle = $(".toolbar-title");
5154

5255
$addSnippetMenu.removeClass("hidden");
5356
$snippetListMenu.addClass("hidden");
5457

5558
$backToListMenuBtn.removeClass("hidden");
5659
$addNewSnippetBtn.addClass("hidden");
5760
$filterSnippetsPanel.addClass("hidden");
61+
62+
$toolbarTitle.html('Add Snippet <span id="snippets-count" class="snippets-count"></span>');
5863
}
5964

6065
/**
61-
* This function is to show the snippets list menu
62-
* this menu is loaded by default when user opens up the panel
63-
* it displays the list of all the snippets available
66+
* This function is responsible to show the snippet list menu
67+
* snippet list menu is the menu which shows the list of all the snippets
68+
* this is called when user clicks on the back button from add snippet menu
6469
*/
6570
function showSnippetListMenu() {
6671
const $addSnippetMenu = $("#custom-snippets-add-new");
@@ -69,6 +74,7 @@ define(function (require, exports, module) {
6974
const $backToListMenuBtn = $("#back-to-list-menu-btn");
7075
const $addNewSnippetBtn = $("#add-new-snippet-btn");
7176
const $filterSnippetsPanel = $("#filter-snippets-panel");
77+
const $toolbarTitle = $(".toolbar-title");
7278

7379
$addSnippetMenu.addClass("hidden");
7480
$editSnippetMenu.addClass("hidden");
@@ -78,29 +84,34 @@ define(function (require, exports, module) {
7884
$addNewSnippetBtn.removeClass("hidden");
7985
$filterSnippetsPanel.removeClass("hidden");
8086

87+
// add the snippet count in the toolbar (the no. of snippets added)
88+
const snippetCount = Global.SnippetHintsList.length;
89+
$toolbarTitle.html(`Custom Snippets <span id="snippets-count" class="snippets-count">(${snippetCount})</span>`);
90+
8191
$("#filter-snippets-input").val("");
8292
}
8393

8494
/**
8595
* This function is responsible to show the edit snippet menu
8696
* edit snippet menu is the menu which allows users to edit an existing snippet
87-
* this is called when user clicks on a snippet item (excluding delete button)
8897
*/
8998
function showEditSnippetMenu() {
90-
const $addSnippetMenu = $("#custom-snippets-add-new");
9199
const $editSnippetMenu = $("#custom-snippets-edit");
92100
const $snippetListMenu = $("#custom-snippets-list");
93101
const $backToListMenuBtn = $("#back-to-list-menu-btn");
94102
const $addNewSnippetBtn = $("#add-new-snippet-btn");
95103
const $filterSnippetsPanel = $("#filter-snippets-panel");
104+
const $toolbarTitle = $(".toolbar-title");
96105

97-
$addSnippetMenu.addClass("hidden");
98106
$editSnippetMenu.removeClass("hidden");
99107
$snippetListMenu.addClass("hidden");
100108

101109
$backToListMenuBtn.removeClass("hidden");
102110
$addNewSnippetBtn.addClass("hidden");
103111
$filterSnippetsPanel.addClass("hidden");
112+
113+
// Update toolbar title
114+
$toolbarTitle.html('Edit Snippet <span id="snippets-count" class="snippets-count"></span>');
104115
}
105116

106117
/**
@@ -154,6 +165,16 @@ define(function (require, exports, module) {
154165
$snippetsListHeader.addClass("hidden");
155166
}
156167

168+
/**
169+
* Initializes the toolbar title for the list view
170+
* This is called when the panel is first opened to ensure the snippet count is displayed
171+
*/
172+
function initializeListViewToolbarTitle() {
173+
const $toolbarTitle = $(".toolbar-title");
174+
const snippetCount = Global.SnippetHintsList.length;
175+
$toolbarTitle.html(`Custom Snippets <span id="snippets-count" class="snippets-count">(${snippetCount})</span>`);
176+
}
177+
157178
exports.showEmptySnippetMessage = showEmptySnippetMessage;
158179
exports.showSnippetsList = showSnippetsList;
159180
exports.clearSnippetsList = clearSnippetsList;
@@ -163,4 +184,5 @@ define(function (require, exports, module) {
163184
exports.showDuplicateAbbreviationError = showDuplicateAbbreviationError;
164185
exports.showSnippetsListHeader = showSnippetsListHeader;
165186
exports.hideSnippetsListHeader = hideSnippetsListHeader;
187+
exports.initializeListViewToolbarTitle = initializeListViewToolbarTitle;
166188
});

src/extensionsIntegrated/CustomSnippets/src/snippetsList.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ define(function (require, exports, module) {
112112
UIHelper.clearSnippetsList(); // clear existing snippets list, as we'll rebuild it
113113
const snippetList = Global.SnippetHintsList; // get the list of snippets
114114

115-
Helper.updateSnippetsCount();
116-
117115
// handle empty snippets case
118116
if (snippetList.length === 0) {
119117
_showEmptyState();

0 commit comments

Comments
 (0)