Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

streamline createCommit helper

Abi Rajaa243480d7875
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 4de93c00..d6c05d80 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -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);
diff --git a/frontend/src/components/commits/types.ts b/frontend/src/components/commits/types.ts
index 68c97ff0..173663a6 100644
--- a/frontend/src/components/commits/types.ts
+++ b/frontend/src/components/commits/types.ts
@@ -7,7 +7,7 @@ export type Variant = {
export type BaseCommit = {
hash: CommitHash;
parentHash: CommitHash | null;
- date_created: Date;
+ dateCreated: Date;
variants: Variant[];
selectedVariantIndex: number;
};
diff --git a/frontend/src/components/commits/utils.ts b/frontend/src/components/commits/utils.ts
index 9a208098..874f67ea 100644
--- a/frontend/src/components/commits/utils.ts
+++ b/frontend/src/components/commits/utils.ts
@@ -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 };
}
diff --git a/frontend/src/components/history/HistoryDisplay.tsx b/frontend/src/components/history/HistoryDisplay.tsx
index b0a02e5f..e08c8a24 100644
--- a/frontend/src/components/history/HistoryDisplay.tsx
+++ b/frontend/src/components/history/HistoryDisplay.tsx
@@ -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.