@@ -9,13 +9,15 @@ export interface HistoryProps {
99 format : FormatState ,
1010 size : SizeState ,
1111 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+
1513 sendMessage : ( text : string , from : User , locale : string ) => void ,
16- onClickActivity : ( activity : Activity ) => ( ) => void ,
1714 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
1921}
2022
2123export class HistoryView extends React . Component < HistoryProps , { } > {
@@ -114,7 +116,7 @@ export class HistoryView extends React.Component<HistoryProps, {}> {
114116 showTimestamp = { index === this . props . activities . length - 1 || ( index + 1 < this . props . activities . length && suitableInterval ( activity , this . props . activities [ index + 1 ] ) ) }
115117 selected = { this . props . isSelected ( activity ) }
116118 fromMe = { this . props . isFromMe ( activity ) }
117- onCardAction = { this . props . doCardAction ( this . props . sendMessage ) }
119+ onCardAction = { this . props . doCardAction }
118120 onClickActivity = { this . props . onClickActivity ( activity ) }
119121 onClickRetry = { e => {
120122 // Since this is a click on an anchor, we need to stop it
@@ -140,19 +142,35 @@ export class HistoryView extends React.Component<HistoryProps, {}> {
140142}
141143
142144export const History = connect (
143- ( state : ChatState ) : Partial < HistoryProps > => ( {
145+ ( state : ChatState ) => ( {
146+ // passed down to HistoryView
144147 format : state . format ,
145148 size : state . size ,
146149 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
151155 } ) , {
152156 setMeasurements : ( carouselMargin : number ) => ( { type : 'Set_Measurements' , carouselMargin } ) ,
153157 onClickRetry : ( activity : Activity ) => ( { type : 'Send_Message_Retry' , clientActivityId : activity . channelData . clientActivityId } ) ,
158+ // only used to create helper functions below
154159 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+ } )
156174) ( HistoryView ) ;
157175
158176const getComputedStyleValues = ( el : HTMLElement , stylePropertyNames : string [ ] ) => {
0 commit comments