-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.jsx
executable file
·109 lines (94 loc) · 2.97 KB
/
index.jsx
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, { Component } from "react";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import classNames from "classnames";
import Immutable from "immutable";
import { loadCategories } from "/src/redux/actions/app";
import Map from "./Map";
import Sidebar from "./Sidebar";
// import Icon from 'components/Global/Icon';
class Dashboard extends Component {
static propTypes = {
children: PropTypes.object, // eslint-disable-line react/no-unused-prop-types
// from react-redux connect
dispatch: PropTypes.func,
activeFilters: PropTypes.object,
searchFilter: PropTypes.string,
categories: PropTypes.instanceOf(Immutable.List),
items: PropTypes.instanceOf(Immutable.List),
mobileView: PropTypes.string,
campaign: PropTypes.string,
};
componentDidMount() {
const { dispatch } = this.props;
dispatch(loadCategories());
}
render() {
const {
items,
categories,
activeFilters,
mobileView,
campaign,
searchFilter,
} = this.props;
const filteredItems = items.filter((item) => {
const itemCategories = categories.filter((c) =>
item.get("categories")
? item.get("categories").includes(c.get("name")) && c.get("show")
: true
); // check if category exists for saved legacy states
if (itemCategories.size === 0) {
return false;
}
// check if searchFilter is active and if the item qualifies
if (
searchFilter &&
!item.get("name").toLowerCase().includes(searchFilter.toLowerCase())
) {
return false;
}
// check which filter is active and if the item qualifies
let qualified = false;
if (activeFilters.size === 0) return true;
if (activeFilters.includes("incomplete") && !item.get("complete"))
qualified = true;
if (activeFilters.includes("missing_images") && !item.get("foto"))
qualified = true;
if (
activeFilters.includes("missing_description") &&
!item.get("beschreibung")
)
qualified = true;
return qualified;
});
const resultViewClasses = classNames("ResultView", {
"ResultView-Map": mobileView === "map",
"ResultView-List": mobileView === "list",
});
return (
<div className="Dashboard">
<div className="Dashboard-Content">
<div className={resultViewClasses}>
<Sidebar items={filteredItems} campaign={campaign} />
{categories.size > 0 ? (
<Map items={filteredItems} campaign={campaign} />
) : null}
</div>
</div>
</div>
);
}
}
export default connect(
(state) => ({
activeFilters: state.app.get("activeFilters"),
searchFilter: state.app.get("searchFilter"),
categories: state.app.get("categories"),
items: state.app.get("items"),
placeSelected: state.app.get("placeSelected"),
mobileView: state.app.get("mobileView"),
}),
null,
null
)(Dashboard);