From dcc156c629e7a27fcc6990371eef440d1c41b866 Mon Sep 17 00:00:00 2001 From: Ethan McElroy Date: Mon, 9 Dec 2024 22:45:04 -0500 Subject: [PATCH] chore: minor refactoring, clean up --- src/app-config-provider.tsx | 4 ++-- src/components/App.tsx | 2 +- src/hooks/use-chat-transcript-store.ts | 4 ++-- src/models/app-config-model.ts | 4 ++-- src/test-utils/mock-app-config.ts | 4 ++-- src/types.ts | 7 ++++--- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/app-config-provider.tsx b/src/app-config-provider.tsx index ec37276..b6b10d2 100644 --- a/src/app-config-provider.tsx +++ b/src/app-config-provider.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { AppConfig, isMode } from "./types"; +import { AppConfig, isAppMode } from "./types"; import appConfigJson from "./app-config.json"; import { AppConfigModel, AppConfigModelSnapshot } from "./models/app-config-model"; import { getUrlParam } from "./utils/utils"; @@ -9,7 +9,7 @@ export const loadAppConfig = (): AppConfig => { const defaultConfig = appConfigJson as AppConfig; const urlParamMode = getUrlParam("mode"); const configOverrides: Partial = { - mode: isMode(urlParamMode) ? urlParamMode : defaultConfig.mode + mode: isAppMode(urlParamMode) ? urlParamMode : defaultConfig.mode }; return { diff --git a/src/components/App.tsx b/src/components/App.tsx index 97961b6..6455c67 100755 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -68,7 +68,7 @@ export const App = observer(() => { }; const handleCreateThread = async () => { - const confirmCreate = window.confirm("Are you sure you want to create a new thread? If you do, you will not be able to continue this chat and will lose its history."); + const confirmCreate = window.confirm("Are you sure you want to create a new thread? If you do, you will lose any existing chat history."); if (!confirmCreate) return; transcriptStore.clearTranscript(); diff --git a/src/hooks/use-chat-transcript-store.ts b/src/hooks/use-chat-transcript-store.ts index f83ed88..70fa1e7 100644 --- a/src/hooks/use-chat-transcript-store.ts +++ b/src/hooks/use-chat-transcript-store.ts @@ -1,7 +1,7 @@ import { useMemo } from "react"; import { ChatTranscriptModel } from "../models/chat-transcript-model"; import { timeStamp } from "../utils/utils"; -import { DAVAI_SPEAKER } from "../constants"; +import { DAVAI_SPEAKER, GREETING } from "../constants"; export const useChatTranscriptStore = () => { const chatTranscriptStore = useMemo(() => { @@ -9,7 +9,7 @@ export const useChatTranscriptStore = () => { messages: [ { speaker: DAVAI_SPEAKER, - content: "Hello! I'm DAVAI, your Data Analysis through Voice and Artificial Intelligence partner.", + content: GREETING, timestamp: timeStamp(), }, ], diff --git a/src/models/app-config-model.ts b/src/models/app-config-model.ts index 09706f2..4527078 100644 --- a/src/models/app-config-model.ts +++ b/src/models/app-config-model.ts @@ -1,5 +1,5 @@ import { types, Instance, SnapshotIn } from "mobx-state-tree"; -import { Mode } from "../types"; +import { AppMode, AppModeValues } from "../types"; export const AppConfigModel = types.model("AppConfigModel", { accessibility: types.model({ @@ -16,7 +16,7 @@ export const AppConfigModel = types.model("AppConfigModel", { height: types.number, }), mockAssistant: types.maybe(types.boolean), - mode: types.enumeration("Mode", ["development", "production", "test"]), + mode: types.enumeration("Mode", AppModeValues), }) .volatile((self) => ({ isAssistantMocked: self.mode === "development" && self.mockAssistant, diff --git a/src/test-utils/mock-app-config.ts b/src/test-utils/mock-app-config.ts index 4cf0ccb..dfaef1f 100644 --- a/src/test-utils/mock-app-config.ts +++ b/src/test-utils/mock-app-config.ts @@ -1,4 +1,4 @@ -import { Mode } from "../types"; +import { AppMode } from "../types"; export const mockAppConfig = { accessibility: { @@ -15,5 +15,5 @@ export const mockAppConfig = { width: 380 }, mockAssistant: false, - mode: "test" as Mode, + mode: "test" as AppMode, }; diff --git a/src/types.ts b/src/types.ts index dfa894c..bc3de0a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,6 @@ -export type Mode = "development" | "production" | "test"; -export const isMode = (value: unknown): value is Mode => { +export const AppModeValues = ["development", "production", "test"] as const; +export type AppMode = typeof AppModeValues[number]; +export const isAppMode = (value: unknown): value is AppMode => { return value === "development" || value === "production" || value === "test"; }; @@ -18,7 +19,7 @@ export type AppConfig = { width: number; }; mockAssistant?: boolean; - mode: Mode; + mode: AppMode; }; export type ChatMessage = {