From 30d5cd2b65f49c81798564f47af47e41782eb8e5 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Thu, 22 Aug 2024 16:27:42 -0400 Subject: [PATCH] move commit code into one file --- frontend/src/App.tsx | 3 ++- .../history_types.ts => commits/types.ts} | 23 +------------------ frontend/src/components/commits/utils.ts | 17 ++++++++++++++ frontend/src/components/history/utils.ts | 2 +- frontend/src/store/project-store.ts | 2 +- 5 files changed, 22 insertions(+), 25 deletions(-) rename frontend/src/components/{history/history_types.ts => commits/types.ts} (60%) create mode 100644 frontend/src/components/commits/utils.ts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f32b284..4de93c0 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -22,7 +22,8 @@ import DeprecationMessage from "./components/messages/DeprecationMessage"; import { GenerationSettings } from "./components/settings/GenerationSettings"; import StartPane from "./components/start-pane/StartPane"; import { takeScreenshot } from "./lib/takeScreenshot"; -import { Commit, createCommit } from "./components/history/history_types"; +import { Commit } from "./components/commits/types"; +import { createCommit } from "./components/commits/utils"; function App() { const { diff --git a/frontend/src/components/history/history_types.ts b/frontend/src/components/commits/types.ts similarity index 60% rename from frontend/src/components/history/history_types.ts rename to frontend/src/components/commits/types.ts index e9171fc..68c97ff 100644 --- a/frontend/src/components/history/history_types.ts +++ b/frontend/src/components/commits/types.ts @@ -1,5 +1,3 @@ -export type CommitType = "ai_create" | "ai_edit" | "code_create"; - export type CommitHash = string; export type Variant = { @@ -14,19 +12,7 @@ export type BaseCommit = { selectedVariantIndex: number; }; -import { nanoid } from "nanoid"; - -// TODO: Move to a different file -// TODO: Fix the type to be better -export function createCommit( - commit: - | Omit - | Omit - | Omit -): Commit { - const hash = nanoid(); - return { ...commit, hash }; -} +export type CommitType = "ai_create" | "ai_edit" | "code_create"; export type AiCreateCommit = BaseCommit & { type: "ai_create"; @@ -48,10 +34,3 @@ export type CodeCreateCommit = BaseCommit & { }; export type Commit = AiCreateCommit | AiEditCommit | CodeCreateCommit; - -export type RenderedHistoryItem = { - type: string; - summary: string; - parentVersion: string | null; - isActive: boolean; -}; diff --git a/frontend/src/components/commits/utils.ts b/frontend/src/components/commits/utils.ts new file mode 100644 index 0000000..9a20809 --- /dev/null +++ b/frontend/src/components/commits/utils.ts @@ -0,0 +1,17 @@ +import { nanoid } from "nanoid"; +import { + AiCreateCommit, + AiEditCommit, + CodeCreateCommit, + Commit, +} from "./types"; + +export function createCommit( + commit: + | Omit + | Omit + | Omit +): Commit { + const hash = nanoid(); + return { ...commit, hash }; +} diff --git a/frontend/src/components/history/utils.ts b/frontend/src/components/history/utils.ts index aa4f183..b1e0552 100644 --- a/frontend/src/components/history/utils.ts +++ b/frontend/src/components/history/utils.ts @@ -1,4 +1,4 @@ -import { Commit, CommitHash, CommitType } from "./history_types"; +import { Commit, CommitHash, CommitType } from "../commits/types"; export function extractHistory( hash: CommitHash, diff --git a/frontend/src/store/project-store.ts b/frontend/src/store/project-store.ts index 5304edd..3830232 100644 --- a/frontend/src/store/project-store.ts +++ b/frontend/src/store/project-store.ts @@ -1,5 +1,5 @@ import { create } from "zustand"; -import { Commit, CommitHash } from "../components/history/history_types"; +import { Commit, CommitHash } from "../components/commits/types"; // Store for app-wide state interface ProjectStore {