mirror of
https://github.com/He4eT/tabswitcher.git
synced 2026-05-05 01:17:23 +00:00
pages/search: shaped tabs
This commit is contained in:
parent
8d91c80b8b
commit
5df95ea62c
6 changed files with 221 additions and 20 deletions
58
pages/search/modules/store.js
Normal file
58
pages/search/modules/store.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import * as labels from './labels.js'
|
||||
|
||||
export const init = ({
|
||||
tabs: browserTabs,
|
||||
onStateUpdate,
|
||||
}) => {
|
||||
/* Initial state */
|
||||
const state = {
|
||||
tabs: [],
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
const shapeTabs = (tabs) => tabs
|
||||
.map((tab) => ({
|
||||
label: labels.id2label(tab.id, tabs),
|
||||
...tab,
|
||||
}))
|
||||
.map((tab) => [
|
||||
'favIconUrl',
|
||||
'id',
|
||||
'label',
|
||||
'title',
|
||||
'url',
|
||||
].reduce((acc, x) => (acc[x] = tab[x], acc), {}))
|
||||
|
||||
const fetchTabs = () =>
|
||||
browserTabs.query({ currentWindow: true, active: false })
|
||||
.then(shapeTabs)
|
||||
.then((tabs) => tabs.reverse())
|
||||
.then((tabs) => void (state.tabs = tabs))
|
||||
|
||||
/* */
|
||||
|
||||
const updateState = () =>
|
||||
fetchTabs()
|
||||
.then(() => onStateUpdate(state))
|
||||
|
||||
updateState()
|
||||
|
||||
/* */
|
||||
|
||||
return {
|
||||
getCurrentState() {
|
||||
return state
|
||||
},
|
||||
actions: {
|
||||
goToTab(id) {
|
||||
browserTabs.update(id, { active: true })
|
||||
.then(updateState)
|
||||
},
|
||||
closeTab(id) {
|
||||
browserTabs.remove(id)
|
||||
.then(updateState)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue