From deb2375146768bd0cdf1efd3e8b5c7f6e7665113 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Thu, 25 Jul 2024 12:45:03 -0400 Subject: [PATCH] isolate history component by using projectStore directly --- frontend/src/App.tsx | 12 ---------- .../src/components/history/HistoryDisplay.tsx | 24 +++++++++++-------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8c397e9..ae58b89 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -593,18 +593,6 @@ function App() { )} { { - if ( - index < 0 || - index >= appHistory.length || - !appHistory[index] - ) - return; - setCurrentVersion(index); - setGeneratedCode(appHistory[index].code); - }} shouldDisableReverts={appState === AppState.CODING} /> } diff --git a/frontend/src/components/history/HistoryDisplay.tsx b/frontend/src/components/history/HistoryDisplay.tsx index ce00db4..a3dcdb1 100644 --- a/frontend/src/components/history/HistoryDisplay.tsx +++ b/frontend/src/components/history/HistoryDisplay.tsx @@ -1,4 +1,3 @@ -import { History } from "./history_types"; import toast from "react-hot-toast"; import classNames from "classnames"; @@ -11,22 +10,27 @@ import { } from "../ui/collapsible"; import { Button } from "../ui/button"; import { CaretSortIcon } from "@radix-ui/react-icons"; +import { useProjectStore } from "../../store/project-store"; interface Props { - history: History; - currentVersion: number | null; - revertToVersion: (version: number) => void; shouldDisableReverts: boolean; } -export default function HistoryDisplay({ - history, - currentVersion, - revertToVersion, - shouldDisableReverts, -}: Props) { +export default function HistoryDisplay({ shouldDisableReverts }: Props) { + const { + appHistory: history, + currentVersion, + setCurrentVersion, + setGeneratedCode, + } = useProjectStore(); 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 : (

Versions