Skip to content

Commit

Permalink
fix: update tab behavior to keep one open at all times (#205)
Browse files Browse the repository at this point in the history
fix #204
  • Loading branch information
mirkoperillo authored May 4, 2024
2 parents 5313dc2 + 95906f3 commit c0c6c5d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ <h4>❤️&nbsp;Support the project</h4>
<li role="presentation" data-bind="css: {active : $data.isActive}">
<a href="#" data-bind="click: $parent.activateTab">
<span data-bind="text: $data.name"></span>
<button
type="button"
class="btn btn-xs btn-danger"
data-bind="click: $parent.removeTab, clickBubble: false">
<span class="glyphicon glyphicon-remove"></span>
</button>
<span data-bind="visible: $data.showRemoveTabButton">
<button
type="button"
class="btn btn-xs btn-danger"
data-bind="click: $parent.removeTab, clickBubble: false">
<span class="glyphicon glyphicon-remove"></span>
</button>
</span>
</a>
</li>
<!-- /ko -->
Expand Down
12 changes: 12 additions & 0 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,13 @@ requirejs(

const newTab = () => {
const newTabContext = new TabContextVm(++tabCounter)
if (tabContexts().length === 0) {
newTabContext.showRemoveTabButton(false)
}
if (tabContexts().length === 1) {
const prevTabContext = tabContexts()[0]
prevTabContext.showRemoveTabButton(true)
}
tabContexts.push(newTabContext)
_activateTab(newTabContext)
}
Expand All @@ -855,6 +862,11 @@ requirejs(
_activateTab(tabContexts()[Math.abs(tabToRemoveIndex - 1)])
}
tabContexts.remove(tab)

if (tabContexts().length === 1) {
const lastTab = tabContexts()[0]
lastTab.showRemoveTabButton(false)
}
}

const enableSaveButton = () => {
Expand Down
1 change: 0 additions & 1 deletion src/js/app/components/bookmarks/bookmarks_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
Remove
<i class="glyphicon glyphicon-trash pull-right"></i>
</li>
<li class="list-group-item ctx-menu-item"></li>
</ul>
</div>

Expand Down
1 change: 1 addition & 0 deletions src/js/app/tabContextVm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define(['knockout', 'app/bookmarkSelectedVm'], function (
this.bookmarkSelected = new BookmarkSelectedVm()

this.isActive = ko.observable(false)
this.showRemoveTabButton = ko.observable(true)

this.reset = () => {
this.request = {}
Expand Down

0 comments on commit c0c6c5d

Please sign in to comment.