streamline createCommit helper
This commit is contained in:
parent
30d5cd2b65
commit
a243480d78
@ -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);
|
||||||
|
|||||||
@ -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;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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 };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user