@@ -9,13 +9,15 @@ export interface HistoryProps {
9
9
format : FormatState ,
10
10
size : SizeState ,
11
11
activities : Activity [ ] ,
12
- isFromMe : ( activity : Activity ) => boolean ,
13
- isSelected : ( activity : Activity ) => boolean ,
14
- doCardAction : ( sendMessage : ( text : string , from : User , locale : string ) => void ) => ( type : string , value : string ) => void ;
12
+
15
13
sendMessage : ( text : string , from : User , locale : string ) => void ,
16
- onClickActivity : ( activity : Activity ) => ( ) => void ,
17
14
setMeasurements : ( carouselMargin : number ) => void ,
18
- onClickRetry : ( activity : Activity ) => void
15
+ onClickRetry : ( activity : Activity ) => void ,
16
+
17
+ isFromMe : ( activity : Activity ) => boolean ,
18
+ isSelected : ( activity : Activity ) => boolean ,
19
+ onClickActivity : ( activity : Activity ) => React . MouseEventHandler < HTMLDivElement > ,
20
+ doCardAction : ( type : string , value : string ) => void
19
21
}
20
22
21
23
export class HistoryView extends React . Component < HistoryProps , { } > {
@@ -114,7 +116,7 @@ export class HistoryView extends React.Component<HistoryProps, {}> {
114
116
showTimestamp = { index === this . props . activities . length - 1 || ( index + 1 < this . props . activities . length && suitableInterval ( activity , this . props . activities [ index + 1 ] ) ) }
115
117
selected = { this . props . isSelected ( activity ) }
116
118
fromMe = { this . props . isFromMe ( activity ) }
117
- onCardAction = { this . props . doCardAction ( this . props . sendMessage ) }
119
+ onCardAction = { this . props . doCardAction }
118
120
onClickActivity = { this . props . onClickActivity ( activity ) }
119
121
onClickRetry = { e => {
120
122
// Since this is a click on an anchor, we need to stop it
@@ -140,19 +142,35 @@ export class HistoryView extends React.Component<HistoryProps, {}> {
140
142
}
141
143
142
144
export const History = connect (
143
- ( state : ChatState ) : Partial < HistoryProps > => ( {
145
+ ( state : ChatState ) => ( {
146
+ // passed down to HistoryView
144
147
format : state . format ,
145
148
size : state . size ,
146
149
activities : state . history . activities ,
147
- isFromMe : ( activity : Activity ) => activity . from . id === state . connection . user . id ,
148
- isSelected : ( activity : Activity ) => activity === state . history . selectedActivity ,
149
- onClickActivity : ( activity : Activity ) => state . connection . selectedActivity && ( ( ) => state . connection . selectedActivity . next ( { activity } ) ) ,
150
- doCardAction : doCardAction ( state . connection . botConnection , state . connection . user , state . format . locale ) ,
150
+ // only used to create helper functions below
151
+ connectionSelectedActivity : state . connection . selectedActivity ,
152
+ selectedActivity : state . history . selectedActivity ,
153
+ botConnection : state . connection . botConnection ,
154
+ user : state . connection . user
151
155
} ) , {
152
156
setMeasurements : ( carouselMargin : number ) => ( { type : 'Set_Measurements' , carouselMargin } ) ,
153
157
onClickRetry : ( activity : Activity ) => ( { type : 'Send_Message_Retry' , clientActivityId : activity . channelData . clientActivityId } ) ,
158
+ // only used to create helper functions below
154
159
sendMessage
155
- }
160
+ } , ( stateProps : any , dispatchProps : any ) => ( {
161
+ // from stateProps
162
+ format : stateProps . format ,
163
+ size : stateProps . size ,
164
+ activities : stateProps . activities ,
165
+ // from dispatchProps
166
+ setMeasurements : dispatchProps . setMeasurements ,
167
+ onClickRetry : dispatchProps . onClickRetry ,
168
+ // helper functions
169
+ doCardAction : doCardAction ( stateProps . botConnection , stateProps . user , stateProps . format . locale , dispatchProps . sendMessage ) ,
170
+ isFromMe : ( activity : Activity ) => activity . from . id === stateProps . user . id ,
171
+ isSelected : ( activity : Activity ) => activity === stateProps . selectedActivity ,
172
+ onClickActivity : ( activity : Activity ) => stateProps . connectionSelectedActivity && ( ( ) => stateProps . connectionSelectedActivity . next ( { activity } ) )
173
+ } )
156
174
) ( HistoryView ) ;
157
175
158
176
const getComputedStyleValues = ( el : HTMLElement , stylePropertyNames : string [ ] ) => {
0 commit comments