track current version
This commit is contained in:
parent
c1d6236391
commit
286549f101
@ -61,6 +61,7 @@ function App() {
|
||||
|
||||
// App history
|
||||
const [appHistory, setAppHistory] = useState<History>([]);
|
||||
const [currentVersion, setCurrentVersion] = useState<number | null>(null);
|
||||
|
||||
const [shouldIncludeResultImage, setShouldIncludeResultImage] =
|
||||
useState<boolean>(false);
|
||||
@ -146,20 +147,25 @@ function App() {
|
||||
inputs: { image_url: referenceImages[0] },
|
||||
},
|
||||
]);
|
||||
setCurrentVersion(0);
|
||||
} else {
|
||||
setAppHistory((prev) => [
|
||||
{
|
||||
type: "ai_edit",
|
||||
code,
|
||||
// TODO: Doesn't typecheck correctly
|
||||
inputs: {
|
||||
// TODO: Fix this
|
||||
previous_commands: [],
|
||||
new_instruction: updateInstruction,
|
||||
setAppHistory((prev) => {
|
||||
const newHistory: History = [
|
||||
{
|
||||
type: "ai_edit",
|
||||
code,
|
||||
// TODO: Doesn't typecheck correctly
|
||||
inputs: {
|
||||
// TODO: Fix this
|
||||
previous_commands: [],
|
||||
new_instruction: updateInstruction,
|
||||
},
|
||||
},
|
||||
},
|
||||
...prev,
|
||||
]);
|
||||
...prev,
|
||||
];
|
||||
setCurrentVersion(0);
|
||||
return newHistory;
|
||||
});
|
||||
}
|
||||
},
|
||||
(line) => setExecutionConsole((prev) => [...prev, line]),
|
||||
@ -357,6 +363,7 @@ function App() {
|
||||
{
|
||||
<HistoryDisplay
|
||||
history={appHistory}
|
||||
currentVersion={currentVersion}
|
||||
revertToVersion={(index) => {
|
||||
if (
|
||||
index < 0 ||
|
||||
@ -364,6 +371,7 @@ function App() {
|
||||
!appHistory[index]
|
||||
)
|
||||
return;
|
||||
setCurrentVersion(index);
|
||||
setGeneratedCode(appHistory[index].code);
|
||||
}}
|
||||
shouldDisableReverts={appState === AppState.CODING}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { History, HistoryItemType } from "../history_types";
|
||||
import toast from "react-hot-toast";
|
||||
import classNames from "classnames";
|
||||
|
||||
interface Props {
|
||||
history: History;
|
||||
currentVersion: number | null;
|
||||
revertToVersion: (version: number) => void;
|
||||
shouldDisableReverts: boolean;
|
||||
}
|
||||
@ -28,6 +30,7 @@ function displayHistoryItemType(itemType: HistoryItemType) {
|
||||
|
||||
export default function HistoryDisplay({
|
||||
history,
|
||||
currentVersion,
|
||||
revertToVersion,
|
||||
shouldDisableReverts,
|
||||
}: Props) {
|
||||
@ -39,8 +42,14 @@ export default function HistoryDisplay({
|
||||
{history.map((item, index) => (
|
||||
<li
|
||||
key={index}
|
||||
className="flex items-center space-x-2 justify-between p-2
|
||||
border-b cursor-pointer hover:bg-black hover:text-white"
|
||||
className={classNames(
|
||||
"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={() =>
|
||||
shouldDisableReverts
|
||||
? toast.error(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user