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

View File

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

View File

@ -8,10 +8,10 @@ import {
export function createCommit( export function createCommit(
commit: commit:
| Omit<AiCreateCommit, "hash"> | Omit<AiCreateCommit, "hash" | "dateCreated" | "selectedVariantIndex">
| Omit<AiEditCommit, "hash"> | Omit<AiEditCommit, "hash" | "dateCreated" | "selectedVariantIndex">
| Omit<CodeCreateCommit, "hash"> | Omit<CodeCreateCommit, "hash" | "dateCreated" | "selectedVariantIndex">
): Commit { ): Commit {
const hash = nanoid(); 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) // Put all commits into an array and sort by created date (oldest first)
const flatHistory = Object.values(commits).sort( const flatHistory = Object.values(commits).sort(
(a, b) => (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. // Annotate history items with a summary, parent version, etc.