isolate history component by using projectStore directly
This commit is contained in:
parent
dcef298dba
commit
deb2375146
@ -593,18 +593,6 @@ function App() {
|
|||||||
)}
|
)}
|
||||||
{
|
{
|
||||||
<HistoryDisplay
|
<HistoryDisplay
|
||||||
history={appHistory}
|
|
||||||
currentVersion={currentVersion}
|
|
||||||
revertToVersion={(index) => {
|
|
||||||
if (
|
|
||||||
index < 0 ||
|
|
||||||
index >= appHistory.length ||
|
|
||||||
!appHistory[index]
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
setCurrentVersion(index);
|
|
||||||
setGeneratedCode(appHistory[index].code);
|
|
||||||
}}
|
|
||||||
shouldDisableReverts={appState === AppState.CODING}
|
shouldDisableReverts={appState === AppState.CODING}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { History } from "./history_types";
|
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
|
||||||
@ -11,22 +10,27 @@ import {
|
|||||||
} from "../ui/collapsible";
|
} from "../ui/collapsible";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { CaretSortIcon } from "@radix-ui/react-icons";
|
import { CaretSortIcon } from "@radix-ui/react-icons";
|
||||||
|
import { useProjectStore } from "../../store/project-store";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
history: History;
|
|
||||||
currentVersion: number | null;
|
|
||||||
revertToVersion: (version: number) => void;
|
|
||||||
shouldDisableReverts: boolean;
|
shouldDisableReverts: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function HistoryDisplay({
|
export default function HistoryDisplay({ shouldDisableReverts }: Props) {
|
||||||
history,
|
const {
|
||||||
|
appHistory: history,
|
||||||
currentVersion,
|
currentVersion,
|
||||||
revertToVersion,
|
setCurrentVersion,
|
||||||
shouldDisableReverts,
|
setGeneratedCode,
|
||||||
}: Props) {
|
} = useProjectStore();
|
||||||
const renderedHistory = renderHistory(history, currentVersion);
|
const renderedHistory = renderHistory(history, currentVersion);
|
||||||
|
|
||||||
|
const revertToVersion = (index: number) => {
|
||||||
|
if (index < 0 || index >= history.length || !history[index]) return;
|
||||||
|
setCurrentVersion(index);
|
||||||
|
setGeneratedCode(history[index].code);
|
||||||
|
};
|
||||||
|
|
||||||
return renderedHistory.length === 0 ? null : (
|
return renderedHistory.length === 0 ? null : (
|
||||||
<div className="flex flex-col h-screen">
|
<div className="flex flex-col h-screen">
|
||||||
<h1 className="font-bold mb-2">Versions</h1>
|
<h1 className="font-bold mb-2">Versions</h1>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user