@@ -24,6 +24,7 @@ interface ISearchSnippetState {
2424
2525interface ISearchSnippetProps {
2626 selectedSearchOptions : string [ ] ;
27+ setSearchOptions : ( options : string [ ] ) => void ;
2728}
2829
2930class OptionsHandler extends Widget {
@@ -54,26 +55,35 @@ export class SearchMultiOption extends React.Component<
5455 }
5556
5657 // duplicate code between this and parent clickhandler, potentially combine
57- // STATUS: state updates are a bit weird, when unchecked, adding to state. When checked removing.
58+ // STATUS: state updates are a bit weird, when unchecked, adding to state. When checked removing. Delay in update.
5859 handleClick ( selectedOption : string , selected : boolean ) : void {
5960 if ( selected ) {
6061 // select option
61- this . setState ( state => ( {
62- currSelected : [ ...state . currSelected , selectedOption ]
63- } ) ) ;
62+ this . setState (
63+ state => ( {
64+ currSelected : [ ...state . currSelected , selectedOption ]
65+ } ) ,
66+ ( ) => {
67+ //callback
68+ this . props . handleOptionClick ( this . state . currSelected ) ;
69+ }
70+ ) ;
6471 } else {
6572 // unselect option
6673 const array = [ ...this . state . currSelected ] ;
6774 const index = array . indexOf ( selectedOption ) ;
6875 if ( index !== - 1 ) {
6976 array . splice ( index , 1 ) ;
70- this . setState ( {
71- currSelected : array
72- } ) ;
77+ this . setState (
78+ {
79+ currSelected : array
80+ } ,
81+ ( ) => {
82+ this . props . handleOptionClick ( this . state . currSelected ) ;
83+ }
84+ ) ;
7385 }
7486 }
75- this . props . handleOptionClick ( this . state . currSelected ) ;
76- console . log ( this . state ) ;
7787 }
7888
7989 render ( ) : JSX . Element {
@@ -150,6 +160,7 @@ export class SearchTools extends React.Component<
150160 this . setState ( {
151161 currSelected : selectedOptions
152162 } ) ;
163+ this . props . setSearchOptions ( selectedOptions ) ;
153164 }
154165
155166 handleClick ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > ) : void {
0 commit comments