track current version
This commit is contained in:
parent
c1d6236391
commit
286549f101
@ -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,20 +147,25 @@ 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",
|
{
|
||||||
code,
|
type: "ai_edit",
|
||||||
// TODO: Doesn't typecheck correctly
|
code,
|
||||||
inputs: {
|
// TODO: Doesn't typecheck correctly
|
||||||
// TODO: Fix this
|
inputs: {
|
||||||
previous_commands: [],
|
// TODO: Fix this
|
||||||
new_instruction: updateInstruction,
|
previous_commands: [],
|
||||||
|
new_instruction: updateInstruction,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
...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}
|
||||||
|
|||||||
@ -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(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user