Skip to content

Commit

Permalink
chore: minor refactoring, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
emcelroy committed Dec 10, 2024
1 parent ee552d9 commit dcc156c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/app-config-provider.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -9,7 +9,7 @@ export const loadAppConfig = (): AppConfig => {
const defaultConfig = appConfigJson as AppConfig;
const urlParamMode = getUrlParam("mode");
const configOverrides: Partial<AppConfig> = {
mode: isMode(urlParamMode) ? urlParamMode : defaultConfig.mode
mode: isAppMode(urlParamMode) ? urlParamMode : defaultConfig.mode
};

return {
Expand Down
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/use-chat-transcript-store.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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(() => {
return ChatTranscriptModel.create({
messages: [
{
speaker: DAVAI_SPEAKER,
content: "Hello! I'm DAVAI, your Data Analysis through Voice and Artificial Intelligence partner.",
content: GREETING,
timestamp: timeStamp(),
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/models/app-config-model.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -16,7 +16,7 @@ export const AppConfigModel = types.model("AppConfigModel", {
height: types.number,
}),
mockAssistant: types.maybe(types.boolean),
mode: types.enumeration<Mode>("Mode", ["development", "production", "test"]),
mode: types.enumeration<AppMode>("Mode", AppModeValues),
})
.volatile((self) => ({
isAssistantMocked: self.mode === "development" && self.mockAssistant,
Expand Down
4 changes: 2 additions & 2 deletions src/test-utils/mock-app-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mode } from "../types";
import { AppMode } from "../types";

export const mockAppConfig = {
accessibility: {
Expand All @@ -15,5 +15,5 @@ export const mockAppConfig = {
width: 380
},
mockAssistant: false,
mode: "test" as Mode,
mode: "test" as AppMode,
};
7 changes: 4 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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";
};

Expand All @@ -18,7 +19,7 @@ export type AppConfig = {
width: number;
};
mockAssistant?: boolean;
mode: Mode;
mode: AppMode;
};

export type ChatMessage = {
Expand Down

0 comments on commit dcc156c

Please sign in to comment.