pages/search: store: closeCurrentTab

This commit is contained in:
He4eT 2024-01-21 20:36:39 +01:00
commit c6f4fda801
4 changed files with 12 additions and 13 deletions

View file

@ -31,8 +31,8 @@ function openHelp () {
location.href = helpLink
}
function closeCurrentTab () {
window.close()
function closeCurrentTab (store) {
store.actions.closeCurrentTab()
}
function reloadCurrentTab () {
@ -46,11 +46,12 @@ const getTabByLabel = (store, label) => {
return tabs.find(tab => tab.label === label)
}
function switchToTab (store, label) {
function switchToTab (store, label, flush) {
const tab = getTabByLabel(store, label)
if (tab) {
flush()
store.actions.goToTab(tab.id)
closeCurrentTab()
store.actions.closeCurrentTab()
}
}

View file

@ -38,12 +38,6 @@ export const attachInputHandlers = (store) => {
const actionbox = document.getElementById('actionbox')
actionbox.value = ''
/* Switch to tab */
const switchToTab = (tabId) => {
store.actions.goToTab(parseInt(tabId))
window.close()
}
/* Arrow keys */
document.addEventListener('keydown', (e) => {
focusButtonsWithArrows(e, () => {
@ -58,8 +52,8 @@ export const attachInputHandlers = (store) => {
/* Buttons */
document.addEventListener('click', (event) => {
if (event.target.classList.contains('tab')) {
const tabId = event.target.dataset.id
switchToTab(tabId)
const tabId = parseInt(event.target.dataset.id)
store.actions.goToTab(tabId)
}
})
@ -82,7 +76,7 @@ export const attachInputHandlers = (store) => {
let visibleTabs = store.getCurrentState().results
if (visibleTabs.length > 0) {
const tabId = visibleTabs[0].obj.id
switchToTab(tabId)
store.actions.goToTab(tabId)
}
}
})

View file

@ -4,6 +4,7 @@ const fuzzysort = window.fuzzysort
export const init = ({
tabs: browserTabs,
onStateUpdate,
closeCurrentTab,
}) => {
/* Initial state */
const state = {
@ -66,7 +67,9 @@ export const init = ({
goToTab(id) {
browserTabs.update(id, { active: true })
.then(updateState)
.then(closeCurrentTab)
},
closeCurrentTab,
closeTab(id) {
browserTabs.remove(id)
.then(updateState)