Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wax-prosemirror
Manage
Activity
Members
Labels
Plan
Issues
34
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wax
wax-prosemirror
Commits
46e530a5
Commit
46e530a5
authored
4 years ago
by
chris
Browse files
Options
Downloads
Patches
Plain Diff
use memo to not rerender because of context
parent
cda7d479
No related branches found
No related tags found
1 merge request
!143
Track changes
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wax-prosemirror-components/src/components/comments/CommentBox.js
+64
-57
64 additions, 57 deletions
...semirror-components/src/components/comments/CommentBox.js
with
64 additions
and
57 deletions
wax-prosemirror-components/src/components/comments/CommentBox.js
+
64
−
57
View file @
46e530a5
import
React
,
{
useState
,
useEffect
,
useContext
}
from
'
react
'
;
import
React
,
{
useState
,
useEffect
,
useContext
,
memo
}
from
'
react
'
;
import
{
TextSelection
}
from
'
prosemirror-state
'
;
import
{
last
,
maxBy
}
from
'
lodash
'
;
...
...
@@ -32,77 +32,84 @@ const CommentBoxStyled = styled.div`
`
;
export
default
({
comment
,
top
,
dataBox
})
=>
{
const
{
view
,
view
:
{
main
:
{
props
:
{
user
},
},
},
app
,
activeView
,
}
=
useContext
(
WaxContext
);
console
.
log
(
'
rerender
'
);
const
[
animate
,
setAnimate
]
=
useState
(
false
);
const
{
attrs
:
{
id
},
}
=
comment
;
const
commentPlugin
=
app
.
PmPlugins
.
get
(
'
commentPlugin
'
);
const
activeComment
=
commentPlugin
.
getState
(
activeView
.
state
).
comment
;
let
active
=
false
;
if
(
activeComment
&&
id
===
activeComment
.
attrs
.
id
)
active
=
true
;
useEffect
(()
=>
{
setAnimate
(
true
);
},
[]);
const
setCommentActive
=
()
=>
{
const
viewId
=
comment
.
attrs
.
viewid
;
const
MemorizedComponent
=
memo
(()
=>
{
const
{
view
,
view
:
{
main
:
{
props
:
{
user
},
},
},
app
,
activeView
,
}
=
useContext
(
WaxContext
);
let
active
=
false
;
if
(
active
)
{
view
[
viewId
].
focus
();
return
false
;
}
const
commentPlugin
=
app
.
PmPlugins
.
get
(
'
commentPlugin
'
);
const
activeComment
=
commentPlugin
.
getState
(
activeView
.
state
).
comment
;
const
allCommentsWithSameId
=
DocumentHelpers
.
findAllMarksWithSameId
(
view
[
viewId
].
state
,
comment
,
);
if
(
activeComment
&&
id
===
activeComment
.
attrs
.
id
)
active
=
true
;
const
maxPos
=
maxBy
(
allCommentsWithSameId
,
'
pos
'
);
maxPos
.
pos
+=
last
(
allCommentsWithSameId
).
node
.
nodeSize
;
const
setCommentActive
=
()
=>
{
const
viewId
=
comment
.
attrs
.
viewid
;
view
[
viewId
].
dispatch
(
view
[
viewId
].
state
.
tr
.
setSelection
(
new
TextSelection
(
view
[
viewId
].
state
.
tr
.
doc
.
resolve
(
maxPos
.
pos
,
maxPos
.
pos
),
if
(
active
)
{
view
[
viewId
].
focus
();
return
false
;
}
const
allCommentsWithSameId
=
DocumentHelpers
.
findAllMarksWithSameId
(
view
[
viewId
].
state
,
comment
,
);
const
maxPos
=
maxBy
(
allCommentsWithSameId
,
'
pos
'
);
maxPos
.
pos
+=
last
(
allCommentsWithSameId
).
node
.
nodeSize
;
view
[
viewId
].
dispatch
(
view
[
viewId
].
state
.
tr
.
setSelection
(
new
TextSelection
(
view
[
viewId
].
state
.
tr
.
doc
.
resolve
(
maxPos
.
pos
,
maxPos
.
pos
),
),
),
),
);
);
view
[
viewId
].
focus
();
};
view
[
viewId
].
focus
();
};
return
(
<>
<
Transition
in
=
{
animate
}
timeout
=
{
1000
}
>
{
state
=>
(
<
CommentBoxStyled
top
=
{
top
}
state
=
{
state
}
data
-
box
=
{
dataBox
}
active
=
{
active
}
onClick
=
{
setCommentActive
}
>
<
Comment
comment
=
{
comment
}
return
(
<>
<
Transition
in
=
{
animate
}
timeout
=
{
1000
}
>
{
state
=>
(
<
CommentBoxStyled
top
=
{
top
}
state
=
{
state
}
data
-
box
=
{
dataBox
}
active
=
{
active
}
activeView
=
{
activeView
}
user
=
{
user
}
/
>
<
/CommentBoxStyled
>
)}
<
/Transition
>
<
/
>
);
onClick
=
{
setCommentActive
}
>
<
Comment
comment
=
{
comment
}
active
=
{
active
}
activeView
=
{
activeView
}
user
=
{
user
}
/
>
<
/CommentBoxStyled
>
)}
<
/Transition
>
<
/
>
);
});
return
<
MemorizedComponent
/>
;
};
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment