Skip to content

Commit

Permalink
refactor: use getStrokeThickness to retrieve thickness from props
Browse files Browse the repository at this point in the history
discussed here: #1 (comment)
  • Loading branch information
mustafacagri committed Oct 18, 2024
1 parent 8d2042d commit 97ff682
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const Canvas: React.FC = () => {

const toggleViewMode = () => setIs3DMode(!is3DMode)

const getStrokeThickness = (thickness?: number) => thickness ?? pathThickness

// Function to handle shape creation
const createShape = useCallback(
(props: ShapeInterface) => {
Expand All @@ -48,13 +50,13 @@ const Canvas: React.FC = () => {
if (props.endX === undefined || props.endY === undefined) return

g.beginStroke(props.strokeColor)
.setStrokeStyle(props?.thickness ?? pathThickness)
.setStrokeStyle(getStrokeThickness(props?.thickness))
.moveTo(0, 0)
.lineTo(props.endX - props.x, props.endY - props.y)
break
case 'path':
if (props?.points && props.points?.length > 1) {
g.beginStroke(props.strokeColor).setStrokeStyle(props?.thickness ?? pathThickness)
g.beginStroke(props.strokeColor).setStrokeStyle(getStrokeThickness(props?.thickness))
g.moveTo(props.points[0].x, props.points[0].y)

props.points.forEach((point: { x: number; y: number }, index: number) => {
Expand Down Expand Up @@ -102,7 +104,7 @@ const Canvas: React.FC = () => {
const g = this.graphics
g.clear()
.beginStroke(props.strokeColor)
.setStrokeStyle(props?.thickness ?? pathThickness)
.setStrokeStyle(getStrokeThickness(props?.thickness))
.moveTo(0, 0)
.lineTo(props.endX - props.x, props.endY - props.y)
} else if (props.type === 'path' && props.points) {
Expand Down

0 comments on commit 97ff682

Please sign in to comment.