Refactor version management: Replace useSaveVersion with useIsComparing across components
- Updated MainScene, SideBarLeft, SideBarRight, Simulations, and CompareLayOut to utilize isComparing state instead of isVersionSaved. - Adjusted conditional rendering and logic to reflect the new comparison state. - Introduced SyncCam component to synchronize camera state during comparisons. - Created useSceneStore to manage camera state with position and target vectors. - Cleaned up imports and ensured consistent formatting across affected files.
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
import { useParams } from "react-router-dom";
|
||||
import React, { useState, useRef, useEffect, Suspense } from "react";
|
||||
import { CompareLayoutIcon, LayoutIcon, ResizerIcon } from "../../icons/SimulationIcons";
|
||||
import { useLoadingProgress, useSaveVersion } from "../../../store/builder/store";
|
||||
import Search from "../inputs/Search";
|
||||
import OuterClick from "../../../utils/outerClick";
|
||||
import Scene from "../../../modules/scene/scene";
|
||||
import { useLoadingProgress, useIsComparing } from "../../../store/builder/store";
|
||||
import { useComparisonProduct } from "../../../store/simulation/useSimulationStore";
|
||||
import { usePlayButtonStore } from "../../../store/ui/usePlayButtonStore";
|
||||
import { useSceneContext } from "../../../modules/scene/sceneContext";
|
||||
import { getAllProductsApi } from "../../../services/simulation/products/getallProductsApi";
|
||||
import { useParams } from "react-router-dom";
|
||||
import Search from "../inputs/Search";
|
||||
import OuterClick from "../../../utils/outerClick";
|
||||
import Scene from "../../../modules/scene/scene";
|
||||
import useRestStates from "../../../hooks/useResetStates";
|
||||
|
||||
import { getVersionHistoryApi } from "../../../services/factoryBuilder/versionControl/getVersionHistoryApi";
|
||||
|
||||
const CompareLayOut = () => {
|
||||
const { clearComparisonProduct, comparisonProduct, setComparisonProduct } = useComparisonProduct();
|
||||
const { versionStore } = useSceneContext();
|
||||
const { versionHistory, selectedVersion, setSelectedVersion, clearSelectedVersion } = versionStore();
|
||||
const { versionHistory, selectedVersion, setSelectedVersion, clearSelectedVersion, setVersions } = versionStore();
|
||||
const { setLoadingProgress } = useLoadingProgress();
|
||||
const [width, setWidth] = useState("50vw");
|
||||
const [isResizing, setIsResizing] = useState(false);
|
||||
@@ -21,10 +24,43 @@ const CompareLayOut = () => {
|
||||
const wrapperRef = useRef<HTMLDivElement>(null);
|
||||
const startWidthRef = useRef<number>(0);
|
||||
const startXRef = useRef<number>(0);
|
||||
const { setIsVersionSaved } = useSaveVersion();
|
||||
const { setIsComparing } = useIsComparing();
|
||||
const { loadingProgress } = useLoadingProgress();
|
||||
const { setIsPlaying } = usePlayButtonStore();
|
||||
const { projectId } = useParams();
|
||||
const { resetStates } = useRestStates();
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (selectedVersion?.versionId) {
|
||||
resetStates();
|
||||
}
|
||||
};
|
||||
}, [selectedVersion?.versionId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectId) return;
|
||||
|
||||
getVersionHistoryApi(projectId)
|
||||
.then((data) => {
|
||||
const versions: VersionHistory = [];
|
||||
data.versions.forEach((version: any) => {
|
||||
versions.push({
|
||||
version: version.version,
|
||||
versionId: version.versionId,
|
||||
versionName: version.versionName,
|
||||
versionDescription: version.description,
|
||||
timeStamp: version.createdAt,
|
||||
createdBy: version.createdBy.userName,
|
||||
});
|
||||
});
|
||||
setVersions(versions);
|
||||
})
|
||||
.catch(() => {
|
||||
console.error("Error fetching version history");
|
||||
});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [projectId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!comparisonProduct) {
|
||||
@@ -71,7 +107,7 @@ const CompareLayOut = () => {
|
||||
|
||||
if (finalWidthVw <= 10) {
|
||||
setWidth("0px");
|
||||
setIsVersionSaved(false);
|
||||
setIsComparing(false);
|
||||
clearComparisonProduct();
|
||||
setIsPlaying(false);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user