Skip to content

Commit

Permalink
Fixed: Update group page after dnd tabs to it
Browse files Browse the repository at this point in the history
  • Loading branch information
mbnuqw committed Aug 30, 2023
1 parent fd5e78e commit 8d1d730
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
82 changes: 38 additions & 44 deletions src/services/tabs.fg.groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,60 +228,54 @@ export function getGroupTab(tab?: Tab): Tab | undefined {
}
}

let updateGroupTabTimeout: number | undefined
export function resetUpdateGroupTabTimeout(): void {
clearTimeout(updateGroupTabTimeout)
}
export function updateGroupTab(groupTab: Tab): void {
clearTimeout(updateGroupTabTimeout)
updateGroupTabTimeout = setTimeout(() => {
const tabsCount = Tabs.list.length
const tabs: GroupedTabInfo[] = []
let subGroupLvl = null
let len = 0

for (let i = groupTab.index + 1; i < tabsCount; i++) {
const tab = Tabs.list[i]
if (tab.lvl <= groupTab.lvl) break
len++

if (subGroupLvl && tab.lvl > subGroupLvl) continue
else subGroupLvl = null
if (tab.isGroup) subGroupLvl = tab.lvl

tabs.push({
id: tab.id,
index: tab.index,
lvl: tab.lvl - groupTab.lvl - 1,
title: tab.customTitle ?? tab.title,
url: tab.url,
discarded: !!tab.discarded,
favIconUrl: tab.favIconUrl ?? '',
})
}
export function updateGroupTab(groupTab: Tab) {
const tabsCount = Tabs.list.length
const tabs: GroupedTabInfo[] = []
let subGroupLvl = null
let len = 0

const msg: GroupMsg = {
index: groupTab.index,
parentId: groupTab.parentId,
tabs,
len,
}
for (let i = groupTab.index + 1; i < tabsCount; i++) {
const tab = Tabs.list[i]
if (tab.lvl <= groupTab.lvl) break
len++

const parentTab = Tabs.byId[groupTab.parentId]
if (parentTab && parentTab.isGroup) {
msg.parentId = parentTab.id
}
if (subGroupLvl && tab.lvl > subGroupLvl) continue
else subGroupLvl = null
if (tab.isGroup) subGroupLvl = tab.lvl

tabs.push({
id: tab.id,
index: tab.index,
lvl: tab.lvl - groupTab.lvl - 1,
title: tab.customTitle ?? tab.title,
url: tab.url,
discarded: !!tab.discarded,
favIconUrl: tab.favIconUrl ?? '',
})
}

const msg: GroupMsg = {
index: groupTab.index,
parentId: groupTab.parentId,
tabs,
len,
}

const parentTab = Tabs.byId[groupTab.parentId]
if (parentTab && parentTab.isGroup) {
msg.parentId = parentTab.id
}

IPC.groupPage(groupTab.id, msg)
}, 256)
IPC.groupPage(groupTab.id, msg)
}
const updateGroupTabDebounced = Utils.debounce(updateGroupTab)

export function updateActiveGroupPage(): void {
let activeTab = Tabs.byId[Tabs.activeId]
if (!activeTab) activeTab = Tabs.list.find(t => t.active)
if (!activeTab) return
if (activeTab.isGroup) {
updateGroupTab(activeTab)
updateGroupTabDebounced(256, activeTab)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/services/tabs.fg.move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ export async function move(
Tabs.autoDiscardFolded(dstParent)
}

// Update group page
if (dstParent?.isGroup) Tabs.updateGroupTab(dstParent)

tabs.forEach(t => Tabs.saveTabData(t.id))
Tabs.cacheTabsData()

Expand Down

0 comments on commit 8d1d730

Please sign in to comment.