feat: add keyboard-based mouse action helper with Zustand integration

- Implemented `mouseActionHelper.ts` to track modifier keys (e.g. CONTROL, SHIFT)
- Dynamically constructs mouse+modifier combos (e.g. left+CONTROL)
- Updates Zustand store (`useMouseNoteStore`) with appropriate notes
- Supports multi-key combinations and cleans up listeners on unmount
This commit is contained in:
2025-07-11 13:06:17 +05:30
parent 24ff130d82
commit 646028f39f
3 changed files with 45 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react"; import React, { useEffect } from "react";
import { HelpIcon } from "../icons/DashboardIcon"; import { HelpIcon } from "../icons/DashboardIcon";
import { useLogger } from "../ui/log/LoggerContext"; import { useLogger } from "../ui/log/LoggerContext";
import { GetLogIcon } from "./getLogIcons"; import { GetLogIcon } from "./getLogIcons";
@@ -15,6 +15,7 @@ import { usePlayButtonStore } from "../../store/usePlayButtonStore";
import useModuleStore, { useSubModuleStore } from "../../store/useModuleStore"; import useModuleStore, { useSubModuleStore } from "../../store/useModuleStore";
import { useVersionContext } from "../../modules/builder/version/versionContext"; import { useVersionContext } from "../../modules/builder/version/versionContext";
import { mouseActionHelper } from "../../utils/mouseUtils/mouseHelper"; import { mouseActionHelper } from "../../utils/mouseUtils/mouseHelper";
import { useMouseNoteStore } from "../../store/useUIToggleStore";
const Footer: React.FC = () => { const Footer: React.FC = () => {
const { logs, setIsLogListVisible } = useLogger(); const { logs, setIsLogListVisible } = useLogger();
@@ -28,35 +29,31 @@ const Footer: React.FC = () => {
const { selectedVersionStore } = useVersionContext(); const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore(); const { selectedVersion } = selectedVersionStore();
const [notes, setNotes] = useState({ const { Leftnote, Middlenote, Rightnote } = useMouseNoteStore();
Leftnote: "",
Middlenote: "",
Rightnote: "",
});
useEffect(() => {
const cleanup = mouseActionHelper(setNotes);
return () => cleanup();
}, []);
const mouseButtons = [ const mouseButtons = [
{ {
icon: <CurserLeftIcon />, icon: <CurserLeftIcon />,
label: notes.Leftnote !== "" ? notes.Leftnote : "Pan", label: Leftnote !== "" ? Leftnote : "Pan",
mouse: "left", mouse: "left",
}, },
{ {
icon: <CurserMiddleIcon />, icon: <CurserMiddleIcon />,
label: notes.Middlenote !== "" ? notes.Middlenote : "Scroll Zoom", label: Middlenote !== "" ? Middlenote : "Scroll Zoom",
mouse: "middle", mouse: "middle",
}, },
{ {
icon: <CurserRightIcon />, icon: <CurserRightIcon />,
label: notes.Rightnote !== "" ? notes.Rightnote : "Orbit / Cancel action", label: Rightnote !== "" ? Rightnote : "Orbit / Cancel action",
mouse: "right", mouse: "right",
}, },
]; ];
useEffect(() => {
const cleanup = mouseActionHelper();
return () => cleanup();
}, []);
return ( return (
<div className="footer-container"> <div className="footer-container">
<div className="footer-wrapper"> <div className="footer-wrapper">

View File

@@ -24,3 +24,30 @@ export const usePlayerStore = create<PlayerState>((set) => ({
hidePlayer: false, // initial state hidePlayer: false, // initial state
setHidePlayer: (hide) => set({ hidePlayer: hide }), // state updater setHidePlayer: (hide) => set({ hidePlayer: hide }), // state updater
})); }));
interface MouseNoteState {
Leftnote: string;
Middlenote: string;
Rightnote: string;
setNotes: (notes: {
Leftnote: string;
Middlenote: string;
Rightnote: string;
}) => void;
setLeftnote: (note: string) => void;
setMiddlenote: (note: string) => void;
setRightnote: (note: string) => void;
resetNotes: () => void;
}
export const useMouseNoteStore = create<MouseNoteState>((set) => ({
Leftnote: '',
Middlenote: '',
Rightnote: '',
setNotes: (notes) => set(notes),
setLeftnote: (note) => set({ Leftnote: note }),
setMiddlenote: (note) => set({ Middlenote: note }),
setRightnote: (note) => set({ Rightnote: note }),
resetNotes: () =>
set({ Leftnote: '', Middlenote: '', Rightnote: '' }),
}));

View File

@@ -1,16 +1,15 @@
import { useMouseNoteStore } from "../../store/useUIToggleStore";
const actionNotes: Record<string, string> = { const actionNotes: Record<string, string> = {
'left+CONTROL': 'Box Select', 'left+CONTROL': 'Box Select',
'left+SHIFT': 'Multi Select', 'left+SHIFT': 'Multi Select',
'middle+CONTROL': 'Zoom In', 'middle+CONTROL': 'Zoom In',
}; };
export function mouseActionHelper(
onUpdate: (notes: { export function mouseActionHelper() {
Leftnote: string; const setNotes = useMouseNoteStore.getState().setNotes;
Middlenote: string;
Rightnote: string;
}) => void
) {
const activeKeys = new Set<string>(); const activeKeys = new Set<string>();
function updateNotesFromKeys() { function updateNotesFromKeys() {
@@ -19,7 +18,7 @@ export function mouseActionHelper(
const middleKey = ['middle', ...sortedKeys].join('+'); const middleKey = ['middle', ...sortedKeys].join('+');
const rightKey = ['right', ...sortedKeys].join('+'); const rightKey = ['right', ...sortedKeys].join('+');
onUpdate({ setNotes({
Leftnote: actionNotes[leftKey] || '', Leftnote: actionNotes[leftKey] || '',
Middlenote: actionNotes[middleKey] || '', Middlenote: actionNotes[middleKey] || '',
Rightnote: actionNotes[rightKey] || '', Rightnote: actionNotes[rightKey] || '',