From 8e01bd5856f6c22929707bad7da755b4bf6e9fb2 Mon Sep 17 00:00:00 2001 From: Meichen Dong Date: Mon, 18 Jul 2022 11:57:38 -0400 Subject: [PATCH 1/3] change text when context --- codex-vscode/src/helpers/notifications.helper.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codex-vscode/src/helpers/notifications.helper.ts b/codex-vscode/src/helpers/notifications.helper.ts index 903c78fa..597f22ac 100644 --- a/codex-vscode/src/helpers/notifications.helper.ts +++ b/codex-vscode/src/helpers/notifications.helper.ts @@ -25,7 +25,8 @@ function formatStatusBarMessage(notifications: Array) { } function displayInformationMessage(notification: Notification) { - const acknowledgement = ["Ok"]; + const action = notification.codexNotificationObject?.contextId ? "Open" : "Ok"; + const acknowledgement = [action]; const description = getNotificationDetails(notification).title; description && vscode.window.showInformationMessage(description, ...acknowledgement); } From 1302ed338ab7d6f975f08b8fcf13125eb1a86b2c Mon Sep 17 00:00:00 2001 From: Meichen Dong Date: Mon, 18 Jul 2022 15:06:15 -0400 Subject: [PATCH 2/3] Open context when there is one --- .../src/helpers/notifications.helper.ts | 22 +++++++++++++++---- .../src/views/pages/ContextItemPage.svelte | 7 +++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/codex-vscode/src/helpers/notifications.helper.ts b/codex-vscode/src/helpers/notifications.helper.ts index 597f22ac..7c1f423b 100644 --- a/codex-vscode/src/helpers/notifications.helper.ts +++ b/codex-vscode/src/helpers/notifications.helper.ts @@ -1,9 +1,14 @@ 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"; + +const OPEN = "Open"; +const OK = "Ok"; async function handleStatusBarUpdate(): Promise { const notifications = await UserService.getInstance().getNotifications(); @@ -25,10 +30,19 @@ function formatStatusBarMessage(notifications: Array) { } function displayInformationMessage(notification: Notification) { - const action = notification.codexNotificationObject?.contextId ? "Open" : "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"); + const codexService = new CodexService(notification.codexNotificationObject.codexId, UserService.getInstance()); + const context: Context = ((await codexService.getContextService().getOneById(contextId)) as Context[])[0]; + openContext(context); + } + }); } 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); + }); }); From 2d130e968a36fbf90569ce8020ca48335b6ec816 Mon Sep 17 00:00:00 2001 From: Meichen Dong Date: Tue, 19 Jul 2022 16:52:02 -0400 Subject: [PATCH 3/3] handle error --- codex-vscode/src/helpers/notifications.helper.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/codex-vscode/src/helpers/notifications.helper.ts b/codex-vscode/src/helpers/notifications.helper.ts index 7c1f423b..5f05835d 100644 --- a/codex-vscode/src/helpers/notifications.helper.ts +++ b/codex-vscode/src/helpers/notifications.helper.ts @@ -6,6 +6,8 @@ import { UserService } from "../services/user.service"; import { getNotificationDetails } from "./format.helper"; import { openContext } from "./goto.helper"; import { updateStatusBar } from "./misc.helper"; +import { SidebarService } from "../services/sidebar.service"; +import { MESSAGE_TYPES } from "../globals"; const OPEN = "Open"; const OK = "Ok"; @@ -38,9 +40,16 @@ function displayInformationMessage(notification: Notification) { vscode.window.showInformationMessage(description, ...acknowledgement).then(async (selection) => { if (selection == OPEN) { await vscode.commands.executeCommand("workbench.view.extension.codex-sidebar-view"); - const codexService = new CodexService(notification.codexNotificationObject.codexId, UserService.getInstance()); - const context: Context = ((await codexService.getContextService().getOneById(contextId)) as Context[])[0]; - openContext(context); + 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." }); + } } }); }