refactor: replace local state with usePlayerStore for hidePlayer in ControlsPlayer, SimulationPlayer, and KeyPressListener

This commit is contained in:
Vishnu 2025-05-21 17:50:15 +05:30
parent 69a7f28d71
commit fb63519853
3 changed files with 15 additions and 21 deletions

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react"; import React, { useEffect } from "react";
import useCameraModeStore, { import useCameraModeStore, {
usePlayButtonStore, usePlayButtonStore,
} from "../../../store/usePlayButtonStore"; } from "../../../store/usePlayButtonStore";
@ -8,12 +8,13 @@ import InputToggle from "../../ui/inputs/InputToggle";
import { EyeCloseIcon, WalkIcon } from "../../icons/ExportCommonIcons"; import { EyeCloseIcon, WalkIcon } from "../../icons/ExportCommonIcons";
import { ExitIcon } from "../../icons/SimulationIcons"; import { ExitIcon } from "../../icons/SimulationIcons";
import { useCamMode } from "../../../store/builder/store"; import { useCamMode } from "../../../store/builder/store";
import { usePlayerStore } from "../../../store/useUIToggleStore";
const ControlsPlayer: React.FC = () => { const ControlsPlayer: React.FC = () => {
const { setIsPlaying } = usePlayButtonStore(); const { setIsPlaying } = usePlayButtonStore();
const { activeModule } = useModuleStore(); const { activeModule } = useModuleStore();
const { walkMode, toggleWalkMode } = useCameraModeStore(); const { walkMode, toggleWalkMode } = useCameraModeStore();
const [hidePlayer, setHidePlayer] = useState(false); const { hidePlayer, setHidePlayer } = usePlayerStore();
const { camMode } = useCamMode(); const { camMode } = useCamMode();
const changeCamMode = () => { const changeCamMode = () => {

View File

@ -23,6 +23,7 @@ import { useSubModuleStore } from "../../../store/useModuleStore";
import ProductionCapacity from "../analysis/ThroughputSummary"; import ProductionCapacity from "../analysis/ThroughputSummary";
import ThroughputSummary from "../analysis/ProductionCapacity"; import ThroughputSummary from "../analysis/ProductionCapacity";
import ROISummary from "../analysis/ROISummary"; import ROISummary from "../analysis/ROISummary";
import { usePlayerStore } from "../../../store/useUIToggleStore";
const SimulationPlayer: React.FC = () => { const SimulationPlayer: React.FC = () => {
const MAX_SPEED = 4; // Maximum speed const MAX_SPEED = 4; // Maximum speed
@ -31,7 +32,7 @@ const SimulationPlayer: React.FC = () => {
const sliderRef = useRef<HTMLDivElement>(null); const sliderRef = useRef<HTMLDivElement>(null);
const [expand, setExpand] = useState(true); const [expand, setExpand] = useState(true);
const [playSimulation, setPlaySimulation] = useState(false); const [playSimulation, setPlaySimulation] = useState(false);
const [hidePlayer, setHidePlayer] = useState(false); const { hidePlayer, setHidePlayer } = usePlayerStore();
const { speed, setSpeed } = useAnimationPlaySpeed(); const { speed, setSpeed } = useAnimationPlaySpeed();
const { setIsPlaying } = usePlayButtonStore(); const { setIsPlaying } = usePlayButtonStore();
@ -111,22 +112,9 @@ const SimulationPlayer: React.FC = () => {
const hourlySimulation = 25; const hourlySimulation = 25;
const dailyProduction = 75; const dailyProduction = 75;
const monthlyROI = 50; const monthlyROI = 50;
const { processBar, setProcessBar } = useProcessBar(); const { processBar } = useProcessBar();
// const process = [
// { name: "process 1", completed: 0 }, // 0% completed
// { name: "process 2", completed: 20 }, // 20% completed
// { name: "process 3", completed: 40 }, // 40% completed
// { name: "process 4", completed: 60 }, // 60% completed
// { name: "process 5", completed: 80 }, // 80% completed
// { name: "process 6", completed: 100 }, // 100% completed
// { name: "process 7", completed: 0 }, // 0% completed
// { name: "process 8", completed: 50 }, // 50% completed
// { name: "process 9", completed: 90 }, // 90% completed
// { name: "process 10", completed: 30 }, // 30% completed
// ];
useEffect(() => { useEffect(() => {
// console.log('processBar: ', processBar);
}, [processBar]) }, [processBar])
const intervals = [50, 20, 30, 40, 50, 60]; // in minutes const intervals = [50, 20, 30, 40, 50, 60]; // in minutes

View File

@ -1,6 +1,6 @@
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import useModuleStore, { useThreeDStore } from "../../store/useModuleStore"; import useModuleStore, { useThreeDStore } from "../../store/useModuleStore";
import {useToggleStore} from "../../store/useUIToggleStore"; import { usePlayerStore, useToggleStore } from "../../store/useUIToggleStore";
import { import {
useActiveSubTool, useActiveSubTool,
useActiveTool, useActiveTool,
@ -36,7 +36,7 @@ const KeyPressListener: React.FC = () => {
const { setWalkMode } = useCameraModeStore(); const { setWalkMode } = useCameraModeStore();
const { setIsVersionSaved } = useSaveVersion(); const { setIsVersionSaved } = useSaveVersion();
const { isLogListVisible, setIsLogListVisible } = useLogger(); const { isLogListVisible, setIsLogListVisible } = useLogger();
const { hidePlayer, setHidePlayer } = usePlayerStore();
const isTextInput = (element: Element | null): boolean => const isTextInput = (element: Element | null): boolean =>
element instanceof HTMLInputElement || element instanceof HTMLInputElement ||
@ -182,6 +182,10 @@ const KeyPressListener: React.FC = () => {
setIsLogListVisible(!isLogListVisible); setIsLogListVisible(!isLogListVisible);
} }
if (keyCombination === "H") {
setHidePlayer(!hidePlayer);
}
if (keyCombination === "ESCAPE") { if (keyCombination === "ESCAPE") {
setWalkMode(false); setWalkMode(false);
setActiveTool("cursor"); setActiveTool("cursor");
@ -198,7 +202,7 @@ const KeyPressListener: React.FC = () => {
// Placeholder for future implementation // Placeholder for future implementation
if ( if (
["Ctrl+Z", "Ctrl+Y", "Ctrl+Shift+Z", "Ctrl+H", "Ctrl+F"].includes( ["Ctrl+Z", "Ctrl+Y", "Ctrl+Shift+Z", "Ctrl+F"].includes(
keyCombination keyCombination
) )
) { ) {
@ -217,7 +221,8 @@ const KeyPressListener: React.FC = () => {
toggleView, toggleView,
showShortcuts, showShortcuts,
isPlaying, isPlaying,
isLogListVisible isLogListVisible,
hidePlayer
]); ]);
return null; return null;