-
Notifications
You must be signed in to change notification settings - Fork 2
/
Filters.js
75 lines (60 loc) · 1.89 KB
/
Filters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Navigation from '../../components/Navigation/Navigation.js'
class Filters extends Component {
constructor(props) {
super(props)
let index = 0
if (this.props.options.der && this.props.options.der.filters && this.props.options.activeFilter) {
let filters = this.props.options.der.filters.filter
let activeFilter = this.props.options.activeFilter
index = filters.findIndex(filter => {
return filter.id === activeFilter.id
});
}
this.state = {
index
}
this.read = this.read.bind(this);
this.changeFilter = this.changeFilter.bind(this);
this.handleAction = this.handleAction.bind(this);
}
changeFilter(index) {
this.setState({index})
}
read(text) {
this.props.config.tts.speak(text)
}
handleAction() {
let {der} = this.props.options
let newFilter = der.filters.filter[this.state.index] ? der.filters.filter[this.state.index] : null
if (der.filters.filter[this.state.index].path !== 'back') {
this.props.actions.changeFilter(newFilter)
}
if (newFilter && newFilter.path !== 'back') {
this.props.actions.toggleMenu('filters', 'Filtre' + newFilter.name + 'sélectionné')
} else {
this.props.actions.toggleMenu('filters', 'Fermeture des filtres')
}
}
render() {
let {der} = this.props.options;
let filtersList = <h2>Ce document ne contient pas de filtre.</h2>
if (der && der.filters && der.filters.filter) {
filtersList = (
<Navigation
action={this.handleAction}
read={this.read}
index={this.state.index}
items={der.filters.filter}
changeIndex={this.changeFilter}>
</Navigation>
)
}
return filtersList
}
}
Filters.contextTypes = {
router: PropTypes.object.isRequired
}
export default Filters