isolate history component by using projectStore directly

This commit is contained in:
Abi Raja 2024-07-25 12:45:03 -04:00
parent dcef298dba
commit deb2375146
2 changed files with 14 additions and 22 deletions

View File

@ -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}
/> />
} }

View File

@ -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 {
currentVersion, appHistory: history,
revertToVersion, currentVersion,
shouldDisableReverts, setCurrentVersion,
}: Props) { setGeneratedCode,
} = 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>