1111 * or submit itself to any jurisdiction.
1212 */
1313import { h } from '/js/src/index.js' ;
14+ import { iconMinus , iconPlus } from '/js/src/icons.js' ;
1415
15- const FILTERS_LIMITS = 5 ;
16+ const FILTERS_LIMIT = 5 ;
1617
1718/**
1819 * Checkbox filter
@@ -21,33 +22,34 @@ const FILTERS_LIMITS = 5;
2122 * @return {vnode } Return the form to be shown
2223 */
2324const checkboxFilter = ( model , tags ) => {
24- const checkboxes = Object . entries ( tags ) . map ( ( [ tag , count ] , index ) =>
25- h ( '.form-check' , [
25+ const checkboxes = Object . entries ( tags ) . map ( ( [ tag , count ] , index ) => {
26+ const isChecked = model . logs . isTagInFilterCriteria ( tag ) ;
27+ return h ( '.form-check' , [
2628 h ( 'input.form-check-input' , {
27- onclick : ( e ) => {
28- const isChecked = e . target . checked ;
29- ! isChecked
30- ? model . logs . removeFilter ( tag )
31- : model . logs . addFilter ( tag ) ;
32- } ,
29+ onclick : ( ) => isChecked ? model . logs . removeFilter ( tag ) : model . logs . addFilter ( tag ) ,
3330 id : `filtersCheckbox${ index + 1 } ` ,
3431 type : 'checkbox' ,
32+ checked : isChecked ,
3533 } ) ,
3634 h ( 'label.flex-row.items-center.form-check-label' , {
3735 for : `filtersCheckbox${ index + 1 } ` ,
3836 } , tag , h ( '.f7.mh1.gray-darker' , `(${ count } )` ) ) ,
39- ] ) ) ;
37+ ] ) ;
38+ } ) ;
4039
41- return checkboxes . length > FILTERS_LIMITS
42- ? h ( '.form-group' , [
43- ...checkboxes . slice ( 0 , FILTERS_LIMITS ) ,
44- h ( 'button.btn.btn-primary.mv1' , {
45- // eslint-disable-next-line no-console
46- onclick : ( ) => console . log ( 'TODO' ) ,
47- } , 'Meer opties' ) ,
48- ...checkboxes . slice ( FILTERS_LIMITS ) ,
49- ] )
50- : h ( '.form-group' , checkboxes ) ;
40+ if ( checkboxes . length <= FILTERS_LIMIT ) {
41+ return checkboxes ;
42+ } else {
43+ const showMoreFilters = model . logs . shouldShowMoreFilters ( ) ;
44+ const toggleFilters = h ( 'button.btn.btn-primary.mv1#toggleMoreFilters' , {
45+ onclick : ( ) => model . logs . toggleMoreFilters ( ) ,
46+ } , ...showMoreFilters ? [ iconMinus ( ) , ' Less filters' ] : [ iconPlus ( ) , ' More filters' ] ) ;
47+
48+ const slicedCheckboxes = showMoreFilters ? checkboxes : checkboxes . slice ( 0 , FILTERS_LIMIT ) ;
49+ slicedCheckboxes . splice ( FILTERS_LIMIT , 0 , toggleFilters ) ;
50+
51+ return slicedCheckboxes ;
52+ }
5153} ;
5254
5355/**
0 commit comments