@@ -3,15 +3,15 @@ import { createElement } from 'preact';
3
3
import propTypes from 'prop-types' ;
4
4
5
5
import { useStoreProxy } from '../store/use-store' ;
6
- import { isReply , quote } from '../helpers/annotation-metadata' ;
6
+ import { quote } from '../helpers/annotation-metadata' ;
7
7
import { withServices } from '../service-context' ;
8
8
9
9
import AnnotationActionBar from './AnnotationActionBar' ;
10
10
import AnnotationBody from './AnnotationBody' ;
11
11
import AnnotationEditor from './AnnotationEditor' ;
12
12
import AnnotationHeader from './AnnotationHeader' ;
13
13
import AnnotationQuote from './AnnotationQuote' ;
14
- import Button from './Button ' ;
14
+ import AnnotationReplyToggle from './AnnotationReplyToggle ' ;
15
15
16
16
/**
17
17
* @typedef {import("../../types/api").Annotation } Annotation
@@ -21,7 +21,10 @@ import Button from './Button';
21
21
/**
22
22
* @typedef AnnotationProps
23
23
* @prop {Annotation } annotation
24
- * @prop {number } replyCount - Number of replies to this annotation (thread)
24
+ * @prop {boolean } hasAppliedFilter - Is any filter applied currently?
25
+ * @prop {boolean } isReply
26
+ * @prop {VoidFunction } onToggleReplies - Callback to expand/collapse reply threads
27
+ * @prop {number } replyCount - Number of replies to this annotation's thread
25
28
* @prop {boolean } showDocumentInfo - Should extended document info be rendered (e.g. in non-sidebar contexts)?
26
29
* @prop {boolean } threadIsCollapsed - Is the thread to which this annotation belongs currently collapsed?
27
30
* @prop {Object } annotationsService - Injected service
@@ -34,10 +37,13 @@ import Button from './Button';
34
37
*/
35
38
function Annotation ( {
36
39
annotation,
37
- annotationsService,
40
+ hasAppliedFilter,
41
+ isReply,
42
+ onToggleReplies,
38
43
replyCount,
39
44
showDocumentInfo,
40
45
threadIsCollapsed,
46
+ annotationsService,
41
47
} ) {
42
48
const store = useStoreProxy ( ) ;
43
49
const isFocused = store . isAnnotationFocused ( annotation . $tag ) ;
@@ -47,32 +53,21 @@ function Annotation({
47
53
const userid = store . profile ( ) . userid ;
48
54
const isSaving = store . isSavingAnnotation ( annotation ) ;
49
55
50
- const isCollapsedReply = isReply ( annotation ) && threadIsCollapsed ;
56
+ const isCollapsedReply = isReply && threadIsCollapsed ;
51
57
52
58
const hasQuote = ! ! quote ( annotation ) ;
53
59
54
60
const isEditing = ! ! draft && ! isSaving ;
55
61
56
- const toggleAction = threadIsCollapsed ? 'Show replies' : 'Hide replies' ;
57
- const toggleText = `${ toggleAction } (${ replyCount } )` ;
58
-
59
- const shouldShowActions = ! isSaving && ! isEditing ;
60
- const shouldShowReplyToggle = replyCount > 0 && ! isReply ( annotation ) ;
62
+ const showActions = ! isSaving && ! isEditing ;
63
+ const showReplyToggle = ! isReply && ! hasAppliedFilter && replyCount > 0 ;
61
64
62
65
const onReply = ( ) => annotationsService . reply ( annotation , userid ) ;
63
66
64
- const onToggleReplies = ( ) =>
65
- // nb. We assume the annotation has an ID here because it is not possible
66
- // to create replies until the annotation has been saved.
67
- store . setExpanded (
68
- /** @type {string } */ ( annotation . id ) ,
69
- ! ! threadIsCollapsed
70
- ) ;
71
-
72
67
return (
73
68
< article
74
69
className = { classnames ( 'Annotation' , {
75
- 'Annotation--reply' : isReply ( annotation ) ,
70
+ 'Annotation--reply' : isReply ,
76
71
'is-collapsed' : threadIsCollapsed ,
77
72
'is-focused' : isFocused ,
78
73
} ) }
@@ -98,15 +93,15 @@ function Annotation({
98
93
{ ! isCollapsedReply && (
99
94
< footer className = "Annotation__footer" >
100
95
< div className = "Annotation__controls u-layout-row" >
101
- { shouldShowReplyToggle && (
102
- < Button
103
- className = "Annotation__reply-toggle"
104
- onClick = { onToggleReplies }
105
- buttonText = { toggleText }
96
+ { showReplyToggle && (
97
+ < AnnotationReplyToggle
98
+ onToggleReplies = { onToggleReplies }
99
+ replyCount = { replyCount }
100
+ threadIsCollapsed = { threadIsCollapsed }
106
101
/>
107
102
) }
108
103
{ isSaving && < div className = "Annotation__actions" > Saving...</ div > }
109
- { shouldShowActions && (
104
+ { showActions && (
110
105
< div className = "Annotation__actions" >
111
106
< AnnotationActionBar
112
107
annotation = { annotation }
@@ -123,6 +118,9 @@ function Annotation({
123
118
124
119
Annotation . propTypes = {
125
120
annotation : propTypes . object . isRequired ,
121
+ hasAppliedFilter : propTypes . bool . isRequired ,
122
+ isReply : propTypes . bool ,
123
+ onToggleReplies : propTypes . func ,
126
124
replyCount : propTypes . number . isRequired ,
127
125
showDocumentInfo : propTypes . bool . isRequired ,
128
126
threadIsCollapsed : propTypes . bool . isRequired ,
0 commit comments