Skip to content

Commit f93abc3

Browse files
committed
Refactor eraser tool to use drawing logic
The eraser tool now uses the same drawing logic as the pen, creating white strokes instead of removing elements by proximity. This simplifies the eraser implementation and improves consistency between tools.
1 parent 3cc4bf3 commit f93abc3

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

app/dashboard/whiteboard/[id]/page.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ export default function WhiteboardEditorPage() {
163163
setIsDrawing(true)
164164
setStartPoint(point)
165165

166-
if (state.currentTool === "pen") {
166+
if (state.currentTool === "pen" || state.currentTool === "eraser") {
167167
const element = createDrawingElement(state.currentTool, currentUser, currentUser, {
168168
points: [point],
169-
color: state.currentColor,
169+
color: state.currentTool === "eraser" ? "#ffffff" : state.currentColor,
170170
strokeWidth: state.currentStrokeWidth,
171171
})
172172
setCurrentElement(element)
@@ -192,6 +192,7 @@ export default function WhiteboardEditorPage() {
192192

193193
switch (state.currentTool) {
194194
case "pen":
195+
case "eraser":
195196
if (currentElement) {
196197
setCurrentElement({
197198
...currentElement,
@@ -240,18 +241,9 @@ export default function WhiteboardEditorPage() {
240241
setCurrentElement(circleElement)
241242
break
242243

243-
case "eraser":
244-
// Find and remove elements at this point
245-
setState((prev) => ({
246-
...prev,
247-
elements: prev.elements.filter((el) => {
248-
// Simple proximity-based erasing
249-
return !el.points.some(
250-
(p) => Math.abs(p.x - point.x) < 10 && Math.abs(p.y - point.y) < 10
251-
)
252-
}),
253-
}))
254-
break
244+
// Eraser handled in pen/eraser case above
245+
// case "eraser":
246+
// break
255247
}
256248
}
257249

0 commit comments

Comments
 (0)