From 171cccda72c87595d04fd7813a6603e9e97edfd6 Mon Sep 17 00:00:00 2001 From: Justin Chung <20733699+justin13888@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:08:13 -0700 Subject: [PATCH] Make tab group updates update date --- shiba/utils/db.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/shiba/utils/db.ts b/shiba/utils/db.ts index ddfe908..713547f 100644 --- a/shiba/utils/db.ts +++ b/shiba/utils/db.ts @@ -60,6 +60,7 @@ export const updateTabGroup = async (id: string, updates: Partial) => const tabGroup = await store.get(id); if (tabGroup) { Object.assign(tabGroup, updates); + tabGroup.timeModified = Date.now(); store.put(tabGroup); } else { return false; @@ -222,6 +223,28 @@ export const getTabGroupById = async ( return db.get("tabGroups", tabGroupId); }; +/** + * Get tab group IDs by workspace ID. + * @param workspaceId Workspace ID + * @returns Array of tab group IDs if workspace exists. Otherwise, undefined. + */ +export const getTabGroupIdsByWorkspaceId = async (workspaceId: string): Promise => { + // Check if workspace ID exists + const db = await dbPromise; + const workspace = await db.get("workspace", workspaceId); + + if (workspace) { + const tx = db.transaction("tabGroups", "readonly"); + const store = tx.objectStore("tabGroups"); + const index = store.index("byTimeCreated"); + const tabGroups = await index.getAll(); + + return tabGroups.map((tabGroup) => tabGroup.id); + } + + return undefined; +} + /** * @returns List of all tab groups */