diff --git a/codex-vscode/src/helpers/notifications.helper.ts b/codex-vscode/src/helpers/notifications.helper.ts index 903c78fa..5f05835d 100644 --- a/codex-vscode/src/helpers/notifications.helper.ts +++ b/codex-vscode/src/helpers/notifications.helper.ts @@ -1,9 +1,16 @@ import * as vscode from "vscode"; -import { Notification } from "@usecodex/common-library"; +import { Context, Notification } from "@usecodex/common-library"; +import { CodexService } from "../services/codex.service"; +import { UserService } from "../services/user.service"; import { getNotificationDetails } from "./format.helper"; +import { openContext } from "./goto.helper"; import { updateStatusBar } from "./misc.helper"; -import { UserService } from "../services/user.service"; +import { SidebarService } from "../services/sidebar.service"; +import { MESSAGE_TYPES } from "../globals"; + +const OPEN = "Open"; +const OK = "Ok"; async function handleStatusBarUpdate(): Promise { const notifications = await UserService.getInstance().getNotifications(); @@ -25,9 +32,26 @@ function formatStatusBarMessage(notifications: Array) { } function displayInformationMessage(notification: Notification) { - const acknowledgement = ["Ok"]; + const contextId = notification.codexNotificationObject?.contextId; + const action = contextId ? OPEN : OK; + const acknowledgement = [action]; const description = getNotificationDetails(notification).title; - description && vscode.window.showInformationMessage(description, ...acknowledgement); + description && + vscode.window.showInformationMessage(description, ...acknowledgement).then(async (selection) => { + if (selection == OPEN) { + await vscode.commands.executeCommand("workbench.view.extension.codex-sidebar-view"); + try { + const codexService = new CodexService( + notification.codexNotificationObject.codexId, + UserService.getInstance() + ); + const context: Context = ((await codexService.getContextService().getOneById(contextId)) as Context[])[0]; + openContext(context); + } catch { + SidebarService.getInstance().postMessage(MESSAGE_TYPES.notFound, { message: "Context is not found." }); + } + } + }); } export { handleStatusBarUpdate, handleSetStatusBarMessage, formatStatusBarMessage, displayInformationMessage }; diff --git a/codex-webview/src/views/pages/ContextItemPage.svelte b/codex-webview/src/views/pages/ContextItemPage.svelte index 6c2b3396..aaae40de 100644 --- a/codex-webview/src/views/pages/ContextItemPage.svelte +++ b/codex-webview/src/views/pages/ContextItemPage.svelte @@ -18,12 +18,11 @@ $: contextId = parseInt($params.contextId); $: context = $contextStore.contexts.get(contextId); - defaultCodicesStore.subscribe((defaultCodices: Codex[]) => { - codex = defaultCodices.find((codex) => context?.codexId === codex.id); - }); - onMount(() => { // TODO: Fetch context data here - COD-982 + defaultCodicesStore.subscribe((defaultCodices: Codex[]) => { + codex = defaultCodices.find((codex) => context?.codexId === codex.id); + }); });