@@ -5,15 +5,32 @@ import memoize from 'memoize-one';
55import ItemCreator from './ItemCreator.jsx' ;
66import GeographicMap from './GeographicMap.jsx' ;
77import { Items } from '../../model.js' ;
8+ import Selection from '../../Selection.js' ;
89
910class Corpora extends Component {
1011
1112 state = {
12- criteria : 'name'
13+ criteria : 'name' ,
14+ listCorpus : [ ] ,
15+ firstReceive : false ,
1316 } ;
1417
1518 sort = memoize ( ( items , criteria ) => items . sort ( by ( `${ criteria } .0` ) ) ) ;
1619
20+ componentDidUpdate ( prevProps ) {
21+ if ( this . props . ids . length !== prevProps . ids . length ) {
22+ let listFormated = [ ...this . props . ids ] ;
23+ listFormated = listFormated . map ( corpus => {
24+ corpus = 'corpus : ' . concat ( corpus ) ;
25+ return corpus ;
26+ } ) ;
27+ this . setState ( {
28+ listCorpus : listFormated ,
29+ firstReceive : true ,
30+ } ) ;
31+ }
32+ }
33+
1734 render ( ) {
1835 let itemsData = this . sort ( this . props . items , this . state . criteria ) ;
1936 let items = itemsData . map ( x =>
@@ -23,8 +40,10 @@ class Corpora extends Component {
2340 let options = this . _getOptions ( attributes ) ;
2441 let count = this . props . items . length ;
2542 let total = this . props . from ;
26- let listIds = this . props . ids . map ( ( corpus ) =>
27- < div key = { corpus } > { corpus } < ItemCreator corpus = { corpus } conf = { this . props . conf } /> </ div >
43+ let listIds = this . props . ids . map ( ( corpus ) => {
44+ let corpusFormated = 'corpus : ' . concat ( corpus ) ;
45+ return < div key = { corpusFormated } > < input className = "corpus_checkbox" type = "checkbox" value = { corpusFormated } onChange = { this . handleChange } checked = { this . isChecked ( corpusFormated ) } /> { corpus } < ItemCreator corpus = { corpus } conf = { this . props . conf } /> </ div > ;
46+ }
2847 ) ;
2948 return (
3049 < div className = "col-md-8 p-4" >
@@ -63,12 +82,37 @@ class Corpora extends Component {
6382 < option key = { attribute } value = { attribute } > { attribute } </ option >
6483 ) ) ;
6584 }
85+
86+ handleChange = ( e ) => {
87+ let list = this . state . listCorpus ;
88+ let index = list . indexOf ( e . target . value ) ;
89+ if ( index !== - 1 ) {
90+ list . splice ( index , 1 ) ;
91+ } else {
92+ list . push ( e . target . value ) ;
93+ }
94+ this . setState ( {
95+ listCorpus : list
96+ } ) ;
97+ this . handleCorpusSelected ( e . target . value ) ;
98+ }
99+
100+ isChecked ( corpus ) {
101+ const selection = Selection . fromURI ( ) ;
102+ return selection . isSelectedOrExcluded ( corpus ) !== 'Excluded' ;
103+ }
104+
105+ handleCorpusSelected ( corpusId ) {
106+ const selection = Selection . fromURI ( ) ;
107+ selection . toggleCorpus ( corpusId ) ;
108+ this . props . history . push ( selection . toURI ( ) ) ;
109+ }
66110}
67111
68112function Item ( props ) {
69113 let uri = `/item/${ props . item . corpus } /${ props . item . id } ` ;
70114 let name = [ props . item . name ] . join ( ', ' ) ; //Name can be an array
71- let thumbnail = props . item . thumbnail && < img src = { props . item . thumbnail } alt = { name } /> ;
115+ let thumbnail = props . item . thumbnail && < img src = { props . item . thumbnail } alt = { name } /> ;
72116 let criteria = ( props . criteria !== 'name' )
73117 && < div className = "About" > { props . item [ props . criteria ] } </ div > ;
74118 return (
0 commit comments