mirror of
https://github.com/trafficlunar/blockmatic.git
synced 2026-06-28 06:34:13 +00:00
refactor: move cssCursor from context to canvas component
This commit is contained in:
parent
8dd7fa684e
commit
fd8f4aaca1
2 changed files with 16 additions and 17 deletions
|
|
@ -1,14 +1,12 @@
|
|||
import { createContext, ReactNode, useEffect, useState } from "react";
|
||||
import { createContext, ReactNode, useState } from "react";
|
||||
|
||||
interface Context {
|
||||
tool: Tool;
|
||||
radius: number;
|
||||
selectedBlock: string;
|
||||
cssCursor: string;
|
||||
setTool: React.Dispatch<React.SetStateAction<Tool>>;
|
||||
setRadius: React.Dispatch<React.SetStateAction<number>>;
|
||||
setSelectedBlock: React.Dispatch<React.SetStateAction<string>>;
|
||||
setCssCursor: React.Dispatch<React.SetStateAction<string>>;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
|
|
@ -21,17 +19,6 @@ export const ToolProvider = ({ children }: Props) => {
|
|||
const [tool, setTool] = useState<Tool>("hand");
|
||||
const [radius, setRadius] = useState(1);
|
||||
const [selectedBlock, setSelectedBlock] = useState("stone");
|
||||
const [cssCursor, setCssCursor] = useState("crosshair");
|
||||
|
||||
useEffect(() => {
|
||||
const cursorMapping: Partial<Record<Tool, string>> = {
|
||||
hand: "grab",
|
||||
move: "move",
|
||||
zoom: "zoom-in",
|
||||
};
|
||||
|
||||
setCssCursor(cursorMapping[tool] || "crosshair");
|
||||
}, [tool]);
|
||||
|
||||
return (
|
||||
<ToolContext.Provider
|
||||
|
|
@ -39,11 +26,9 @@ export const ToolProvider = ({ children }: Props) => {
|
|||
tool,
|
||||
radius,
|
||||
selectedBlock,
|
||||
cssCursor,
|
||||
setTool,
|
||||
setRadius,
|
||||
setSelectedBlock,
|
||||
setCssCursor,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue