streamline createCommit helper

This commit is contained in:
Abi Raja 2024-08-22 16:38:39 -04:00
parent 30d5cd2b65
commit a243480d78
4 changed files with 6 additions and 10 deletions

View File

@ -184,9 +184,7 @@ function App() {
const updatedParams = { ...params, ...settings };
const baseCommitObject = {
date_created: new Date(),
variants: [{ code: "" }, { code: "" }],
selectedVariantIndex: 0,
};
const commitInputObject =
@ -345,9 +343,7 @@ function App() {
const commit = createCommit({
type: "code_create",
parentHash: null,
date_created: new Date(),
variants: [{ code }],
selectedVariantIndex: 0,
inputs: null,
});
addCommit(commit);

View File

@ -7,7 +7,7 @@ export type Variant = {
export type BaseCommit = {
hash: CommitHash;
parentHash: CommitHash | null;
date_created: Date;
dateCreated: Date;
variants: Variant[];
selectedVariantIndex: number;
};

View File

@ -8,10 +8,10 @@ import {
export function createCommit(
commit:
| Omit<AiCreateCommit, "hash">
| Omit<AiEditCommit, "hash">
| Omit<CodeCreateCommit, "hash">
| Omit<AiCreateCommit, "hash" | "dateCreated" | "selectedVariantIndex">
| Omit<AiEditCommit, "hash" | "dateCreated" | "selectedVariantIndex">
| Omit<CodeCreateCommit, "hash" | "dateCreated" | "selectedVariantIndex">
): Commit {
const hash = nanoid();
return { ...commit, hash };
return { ...commit, hash, dateCreated: new Date(), selectedVariantIndex: 0 };
}

View File

@ -22,7 +22,7 @@ export default function HistoryDisplay({ shouldDisableReverts }: Props) {
// Put all commits into an array and sort by created date (oldest first)
const flatHistory = Object.values(commits).sort(
(a, b) =>
new Date(a.date_created).getTime() - new Date(b.date_created).getTime()
new Date(a.dateCreated).getTime() - new Date(b.dateCreated).getTime()
);
// Annotate history items with a summary, parent version, etc.