move commit code into one file

This commit is contained in:
Abi Raja 2024-08-22 16:27:42 -04:00
parent 637f75b93e
commit 30d5cd2b65
5 changed files with 22 additions and 25 deletions

View File

@ -22,7 +22,8 @@ import DeprecationMessage from "./components/messages/DeprecationMessage";
import { GenerationSettings } from "./components/settings/GenerationSettings"; import { GenerationSettings } from "./components/settings/GenerationSettings";
import StartPane from "./components/start-pane/StartPane"; import StartPane from "./components/start-pane/StartPane";
import { takeScreenshot } from "./lib/takeScreenshot"; 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() { function App() {
const { const {

View File

@ -1,5 +1,3 @@
export type CommitType = "ai_create" | "ai_edit" | "code_create";
export type CommitHash = string; export type CommitHash = string;
export type Variant = { export type Variant = {
@ -14,19 +12,7 @@ export type BaseCommit = {
selectedVariantIndex: number; selectedVariantIndex: number;
}; };
import { nanoid } from "nanoid"; export type CommitType = "ai_create" | "ai_edit" | "code_create";
// TODO: Move to a different file
// TODO: Fix the type to be better
export function createCommit(
commit:
| Omit<AiCreateCommit, "hash">
| Omit<AiEditCommit, "hash">
| Omit<CodeCreateCommit, "hash">
): Commit {
const hash = nanoid();
return { ...commit, hash };
}
export type AiCreateCommit = BaseCommit & { export type AiCreateCommit = BaseCommit & {
type: "ai_create"; type: "ai_create";
@ -48,10 +34,3 @@ export type CodeCreateCommit = BaseCommit & {
}; };
export type Commit = AiCreateCommit | AiEditCommit | CodeCreateCommit; export type Commit = AiCreateCommit | AiEditCommit | CodeCreateCommit;
export type RenderedHistoryItem = {
type: string;
summary: string;
parentVersion: string | null;
isActive: boolean;
};

View File

@ -0,0 +1,17 @@
import { nanoid } from "nanoid";
import {
AiCreateCommit,
AiEditCommit,
CodeCreateCommit,
Commit,
} from "./types";
export function createCommit(
commit:
| Omit<AiCreateCommit, "hash">
| Omit<AiEditCommit, "hash">
| Omit<CodeCreateCommit, "hash">
): Commit {
const hash = nanoid();
return { ...commit, hash };
}

View File

@ -1,4 +1,4 @@
import { Commit, CommitHash, CommitType } from "./history_types"; import { Commit, CommitHash, CommitType } from "../commits/types";
export function extractHistory( export function extractHistory(
hash: CommitHash, hash: CommitHash,

View File

@ -1,5 +1,5 @@
import { create } from "zustand"; import { create } from "zustand";
import { Commit, CommitHash } from "../components/history/history_types"; import { Commit, CommitHash } from "../components/commits/types";
// Store for app-wide state // Store for app-wide state
interface ProjectStore { interface ProjectStore {