track current version

This commit is contained in:
Abi Raja 2023-12-06 16:02:52 -05:00
parent c1d6236391
commit 286549f101
2 changed files with 31 additions and 14 deletions

View File

@ -61,6 +61,7 @@ function App() {
// App history // App history
const [appHistory, setAppHistory] = useState<History>([]); const [appHistory, setAppHistory] = useState<History>([]);
const [currentVersion, setCurrentVersion] = useState<number | null>(null);
const [shouldIncludeResultImage, setShouldIncludeResultImage] = const [shouldIncludeResultImage, setShouldIncludeResultImage] =
useState<boolean>(false); useState<boolean>(false);
@ -146,8 +147,10 @@ function App() {
inputs: { image_url: referenceImages[0] }, inputs: { image_url: referenceImages[0] },
}, },
]); ]);
setCurrentVersion(0);
} else { } else {
setAppHistory((prev) => [ setAppHistory((prev) => {
const newHistory: History = [
{ {
type: "ai_edit", type: "ai_edit",
code, code,
@ -159,7 +162,10 @@ function App() {
}, },
}, },
...prev, ...prev,
]); ];
setCurrentVersion(0);
return newHistory;
});
} }
}, },
(line) => setExecutionConsole((prev) => [...prev, line]), (line) => setExecutionConsole((prev) => [...prev, line]),
@ -357,6 +363,7 @@ function App() {
{ {
<HistoryDisplay <HistoryDisplay
history={appHistory} history={appHistory}
currentVersion={currentVersion}
revertToVersion={(index) => { revertToVersion={(index) => {
if ( if (
index < 0 || index < 0 ||
@ -364,6 +371,7 @@ function App() {
!appHistory[index] !appHistory[index]
) )
return; return;
setCurrentVersion(index);
setGeneratedCode(appHistory[index].code); setGeneratedCode(appHistory[index].code);
}} }}
shouldDisableReverts={appState === AppState.CODING} shouldDisableReverts={appState === AppState.CODING}

View File

@ -1,9 +1,11 @@
import { ScrollArea } from "@/components/ui/scroll-area"; import { ScrollArea } from "@/components/ui/scroll-area";
import { History, HistoryItemType } from "../history_types"; import { History, HistoryItemType } from "../history_types";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import classNames from "classnames";
interface Props { interface Props {
history: History; history: History;
currentVersion: number | null;
revertToVersion: (version: number) => void; revertToVersion: (version: number) => void;
shouldDisableReverts: boolean; shouldDisableReverts: boolean;
} }
@ -28,6 +30,7 @@ function displayHistoryItemType(itemType: HistoryItemType) {
export default function HistoryDisplay({ export default function HistoryDisplay({
history, history,
currentVersion,
revertToVersion, revertToVersion,
shouldDisableReverts, shouldDisableReverts,
}: Props) { }: Props) {
@ -39,8 +42,14 @@ export default function HistoryDisplay({
{history.map((item, index) => ( {history.map((item, index) => (
<li <li
key={index} key={index}
className="flex items-center space-x-2 justify-between p-2 className={classNames(
border-b cursor-pointer hover:bg-black hover:text-white" "flex items-center space-x-2 justify-between p-2",
"border-b cursor-pointer",
{
" hover:bg-black hover:text-white": index !== currentVersion,
"bg-slate-500 text-white": index === currentVersion,
}
)}
onClick={() => onClick={() =>
shouldDisableReverts shouldDisableReverts
? toast.error( ? toast.error(