Skip to content

Commit

Permalink
Fixed bug with isDrawing variable
Browse files Browse the repository at this point in the history
  • Loading branch information
bgonp committed Mar 9, 2021
1 parent 0386db0 commit eafeb46
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
build
.vscode
*.tgz
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-drawarea",
"version": "1.0.7",
"version": "1.0.8",
"description": "React components to draw with mouse or touch events",
"author": {
"name": "Borja González",
Expand Down
19 changes: 8 additions & 11 deletions src/DrawArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,22 @@ const DrawArea: FC<Props> = ({
children,
}) => {
const [lines, setLines] = useState<Lines>([])
const [currentLine, setCurrentLine] = useState<Line>([])
const [newLine, setNewLine] = useState<Line>([])
const allLines = newLine.length === 0 ? lines : [...lines, newLine]

const reset = () => setLines([])

const undo = () => setLines(lines.slice(0, -1))

const finishLine = () => {
if (currentLine.length > 1) setLines([...lines, currentLine])
setCurrentLine([])
if (newLine.length > 1) setLines(allLines)
setNewLine([])
}

const addPoint = (newPoint: Point) =>
setCurrentLine([...currentLine, newPoint])
const addPoint = (newPoint: Point) => setNewLine([...newLine, newPoint])

const content = hidden
? null
: (
<div className={className}>
<Drawed color={color} lines={[...lines, currentLine]} thickness={thickness} />
<Drawed color={color} lines={allLines} thickness={thickness} />
{disabled || <Drawable addPoint={addPoint} finishLine={finishLine} />}
</div>
)
Expand All @@ -51,8 +48,8 @@ const DrawArea: FC<Props> = ({

return (
<DrawContext.Provider value={{
lines,
isDrawing: currentLine.length > 0,
lines: allLines,
isDrawing: newLine.length > 0,
reset,
undo,
}}>
Expand Down

0 comments on commit eafeb46

Please sign in to comment.