Skip to content

Commit

Permalink
Fix shape property update on select
Browse files Browse the repository at this point in the history
  • Loading branch information
low-earth-orbit committed Sep 30, 2024
1 parent 3fc4638 commit 28664af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
13 changes: 3 additions & 10 deletions components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ import {
} from "./text/textUtils";
import ShapePanel from "./toolbar/ShapePanel";
import TextPanel from "./toolbar/TextPanel";
import {
setFillColor,
setStrokeColor,
setStrokeWidth,
} from "@/redux/shapeSlice";
import { setStrokeColor, setStrokeWidth } from "@/redux/shapeSlice";

export interface StageSizeType {
width: number;
Expand Down Expand Up @@ -236,9 +232,9 @@ export default function Canvas() {
function updateStyle(property: keyof CanvasObjectType, value: any) {
// Dynamically update state
if (property === "strokeWidth") {
dispatch(setStrokeWidth(value));
dispatch(setStrokeWidth(value)); // TODO: Ink property should separate from shape/text
} else if (property === "stroke") {
dispatch(setStrokeColor(value));
dispatch(setStrokeColor(value)); // TODO: Ink property should separate from shape/text
}

// Update object property
Expand Down Expand Up @@ -471,9 +467,6 @@ export default function Canvas() {
objects={canvasObjects}
newObject={newObject}
onChange={updateSelectedObject}
setWidth={setStrokeWidth}
setBorderColor={setStrokeColor}
setFillColor={setFillColor}
selectedObjectId={selectedObjectId}
setSelectedObjectId={(newObjectId) =>
dispatch(selectCanvasObject(newObjectId))
Expand Down
21 changes: 11 additions & 10 deletions components/shapes/ShapeLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import RectangleShape from "./RectangleShape";
import OvalShape from "./OvalShape";
import TriangleShape from "./TriangleShape";
import StarShape from "./StarShape";
import { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { RootState } from "@/redux/store";
import {
setFillColor,
setStrokeColor,
setStrokeWidth,
} from "@/redux/shapeSlice";

type ShapesLayerProps = {
objects: CanvasObjectType[];
Expand All @@ -14,9 +19,6 @@ type ShapesLayerProps = {
newAttrs: Partial<CanvasObjectType>,
selectedObjectId: string,
) => void;
setWidth: (newWidth: number) => void;
setBorderColor: (newColor: string) => void;
setFillColor: (newColor: string) => void;
selectedObjectId: string;
setSelectedObjectId: (id: string) => void;
setSidePanelVisible: (isVisible: boolean) => void;
Expand All @@ -26,13 +28,12 @@ export default function ShapeLayer({
objects,
newObject,
onChange,
setWidth,
setBorderColor,
setFillColor,
selectedObjectId,
setSelectedObjectId,
setSidePanelVisible,
}: ShapesLayerProps) {
const dispatch = useDispatch();

const { selectedTool } = useSelector((state: RootState) => state.canvas);

const shapes = [
Expand All @@ -52,9 +53,9 @@ export default function ShapeLayer({
setSidePanelVisible(true);

// update settings to match selected shape's
setWidth(shape.strokeWidth as number);
setBorderColor(shape.stroke as string);
setFillColor(shape.fill as string);
dispatch(setStrokeWidth(shape.strokeWidth || 5));
dispatch(setStrokeColor(shape.stroke || "#2986cc"));
dispatch(setFillColor(shape.fill || "#FFFFFF"));

// Update cursor style
const stage = e.target.getStage();
Expand Down

0 comments on commit 28664af

Please sign in to comment.