mirror of
https://github.com/trafficlunar/blockmatic.git
synced 2026-08-12 12:29:42 +00:00
feat: place back blocks when canceling selection and create history entry
This commit is contained in:
parent
0fc7497f10
commit
a68f995699
4 changed files with 62 additions and 25 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import { createContext, ReactNode, useContext, useState } from "react";
|
||||
import { CanvasContext } from "./Canvas";
|
||||
import { createContext, ReactNode, useState } from "react";
|
||||
|
||||
interface Context {
|
||||
selectionCoords: CoordinateArray;
|
||||
|
|
@ -7,7 +6,6 @@ interface Context {
|
|||
setSelectionCoords: React.Dispatch<React.SetStateAction<CoordinateArray>>;
|
||||
setSelectionLayerBlocks: React.Dispatch<React.SetStateAction<Block[]>>;
|
||||
isInSelection: (x: number, y: number) => boolean;
|
||||
confirmSelection: () => void;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
|
|
@ -17,8 +15,6 @@ interface Props {
|
|||
export const SelectionContext = createContext<Context>({} as Context);
|
||||
|
||||
export const SelectionProvider = ({ children }: Props) => {
|
||||
const { blocks, setBlocks } = useContext(CanvasContext);
|
||||
|
||||
const [selectionCoords, setSelectionCoords] = useState<CoordinateArray>([]);
|
||||
const [selectionLayerBlocks, setSelectionLayerBlocks] = useState<Block[]>([]);
|
||||
|
||||
|
|
@ -29,14 +25,6 @@ export const SelectionProvider = ({ children }: Props) => {
|
|||
return true;
|
||||
};
|
||||
|
||||
const confirmSelection = () => {
|
||||
const combinedBlocks = [...blocks, ...selectionLayerBlocks];
|
||||
const uniqueBlocks = Array.from(new Map(combinedBlocks.map((block) => [`${block.x},${block.y}`, block])).values());
|
||||
|
||||
setBlocks(uniqueBlocks);
|
||||
setSelectionLayerBlocks([]);
|
||||
};
|
||||
|
||||
return (
|
||||
<SelectionContext.Provider
|
||||
value={{
|
||||
|
|
@ -45,7 +33,6 @@ export const SelectionProvider = ({ children }: Props) => {
|
|||
setSelectionCoords,
|
||||
setSelectionLayerBlocks,
|
||||
isInSelection,
|
||||
confirmSelection,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue