Skip to content

Commit

Permalink
TAB-424 start group management for chrome tabs - test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
evandor committed Oct 12, 2023
1 parent 59bb2f3 commit 77af9e0
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions src/stores/groupsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ export const useGroupsStore = defineStore('groups', () => {
const {inBexMode} = useUtils()

/**
* the map of all 'ever used' chrome tab groups, even if they are not currently in use
* the map of all 'ever used' Chrome tab groups, even if they are not currently in use,
* using the title as key.
*/
const tabGroups = ref<Map<string, chrome.tabGroups.TabGroup>>(new Map())

/**
* the array all actually currently used chrome tab groups
* the array all actually currently used Chrome tab groups.
*/
const currentTabGroups = ref<chrome.tabGroups.TabGroup[]>([])

Expand Down Expand Up @@ -60,25 +61,23 @@ export const useGroupsStore = defineStore('groups', () => {
res.forEach(r => tabGroups.value.set(r.title || '', r))
})
})

})
}
}

function onCreated(group: chrome.tabGroups.TabGroup) {
console.debug("group: onCreated", group)
if (inBexMode() && chrome?.tabGroups && group.title) {
// update currentTabGroups
chrome.tabGroups.query({}, (groups) => {
currentTabGroups.value = groups
})
}
}

function onUpdated(group: chrome.tabGroups.TabGroup) {
console.log("group: onUpdated", group)
console.debug("group: onUpdated", group)
if (inBexMode() && chrome?.tabGroups) {
// update currentTabGroups

chrome.tabGroups.query({}, (groups) => {
currentTabGroups.value = groups

Expand Down Expand Up @@ -114,7 +113,6 @@ export const useGroupsStore = defineStore('groups', () => {
storage.updateGroup(g)
}
}

})
}
}
Expand Down Expand Up @@ -171,37 +169,25 @@ export const useGroupsStore = defineStore('groups', () => {
if (group.title) {
const existingGroups = await storage.getGroups()
if (existingGroups.findIndex(g => g.title === group.title) < 0) {
storage.addGroup(JSON.parse(JSON.stringify(group)) as chrome.tabGroups.TabGroup)
await storage.addGroup(JSON.parse(JSON.stringify(group)) as chrome.tabGroups.TabGroup)
} else {
console.debug("group '" + group.title + "' exists already")
}
}
}

function updateGroup(group: chrome.tabGroups.TabGroup) {
storage.updateGroup(group)
return storage.updateGroup(group)
}

function deleteGroupByTitle(title: string) {
// const groupFound = findGroup([...tabGroups.value.values()], undefined, title)
// console.log("found group to delete", groupFound)
//
// if (groupFound) {
// remove here in groupsStore
tabGroups.value.delete(title)
// delete in DB
return storage.deleteGroupByTitle(title)
// }

// delete in all tabs?

}


return {
initialize,
initListeners,
// groupFor,
groupForName,
currentGroupForName,
currentGroupForId,
Expand Down

0 comments on commit 77af9e0

Please sign in to comment.