Skip to content

Commit

Permalink
ULMS-2995 Fixed problem with timers (toolbar)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkonst committed Jun 6, 2024
1 parent f42542c commit 335bbfa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/drawing-toolbar/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulms/ui-drawing-toolbar",
"version": "2.5.0",
"version": "2.5.1",
"license": "MIT",
"main": "index.js",
"module": "es/index.js",
Expand Down
19 changes: 18 additions & 1 deletion packages/drawing-toolbar/src/drawing-toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class _DrawingToolbarComponent extends React.Component {
this.state = { opened: '' }

this.mounted = false
this.timeoutId = undefined
}

componentDidMount() {
Expand All @@ -53,7 +54,13 @@ class _DrawingToolbarComponent extends React.Component {
const { opened } = this.state

if (tool !== prevProps.tool || brushMode !== prevProps.brushMode) {
setTimeout(() => {
// this.setState({ opened: tool })

this.clearTimeoutId()

this.timeoutId = setTimeout(() => {
this.clearTimeoutId()

// Чтобы успели примениться значения для getOptions
if (!this.mounted) return

Expand Down Expand Up @@ -117,6 +124,8 @@ class _DrawingToolbarComponent extends React.Component {
componentWillUnmount() {
this.mounted = false

this.clearTimeoutId()

document.removeEventListener(eventName, this.handleDocumentClickEvent)
}

Expand Down Expand Up @@ -176,6 +185,14 @@ class _DrawingToolbarComponent extends React.Component {
}
}

clearTimeoutId() {
if (this.timeoutId) {
clearTimeout(this.timeoutId)

this.timeoutId = undefined
}
}

render() {
const {
brushColor,
Expand Down

0 comments on commit 335bbfa

Please sign in to comment.