From 8008513a6c64dc85c56fc9703da5cc7716d4daf8 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Wed, 6 Dec 2023 15:42:33 -0500 Subject: [PATCH] handle coding state correctly --- frontend/src/App.tsx | 1 + frontend/src/components/HistoryDisplay.tsx | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 248e1ff..d4b772e 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -366,6 +366,7 @@ function App() { return; setGeneratedCode(appHistory[index].code); }} + shouldDisableReverts={appState === AppState.CODING} /> } diff --git a/frontend/src/components/HistoryDisplay.tsx b/frontend/src/components/HistoryDisplay.tsx index 0306cf1..58908f2 100644 --- a/frontend/src/components/HistoryDisplay.tsx +++ b/frontend/src/components/HistoryDisplay.tsx @@ -1,9 +1,11 @@ import { ScrollArea } from "@/components/ui/scroll-area"; import { History, HistoryItemType } from "../history_types"; +import toast from "react-hot-toast"; interface Props { history: History; revertToVersion: (version: number) => void; + shouldDisableReverts: boolean; } function displayHistoryItemType(itemType: HistoryItemType) { @@ -24,7 +26,11 @@ function displayHistoryItemType(itemType: HistoryItemType) { } } -export default function HistoryDisplay({ history, revertToVersion }: Props) { +export default function HistoryDisplay({ + history, + revertToVersion, + shouldDisableReverts, +}: Props) { return history.length === 0 ? null : (

History

@@ -35,7 +41,13 @@ export default function HistoryDisplay({ history, revertToVersion }: Props) { key={index} className="flex items-center space-x-2 justify-between p-2 border-b cursor-pointer hover:bg-black hover:text-white" - onClick={() => revertToVersion(index)} + onClick={() => + shouldDisableReverts + ? toast.error( + "Please wait for code generation to complete before viewing an older version" + ) + : revertToVersion(index) + } >

{displayHistoryItemType(item.type)}

v{history.length - index}