-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSpellBook.jsx
More file actions
105 lines (95 loc) · 2.71 KB
/
SpellBook.jsx
File metadata and controls
105 lines (95 loc) · 2.71 KB
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
import React from "react";
import SpellList from "./SpellList";
import FilterWidget from "./FilterWidget";
import FilterState from "./FilterState";
import { DSAGrid, DSAGridRow } from '../controls/DSAGrid';
import DSAInfoBox from '../controls/DSAInfoBox';
export default class SpellBook extends React.Component {
state = {
filter: new FilterState()
};
handleFavoriteChange = (name) => {
this.setState(function(prevState) {
var newFilter = prevState.filter;
var newFavoriteSpells = newFilter.favoriteSpells;
var i = newFavoriteSpells.indexOf(name);
if (i === -1)
newFavoriteSpells.push(name);
else
newFavoriteSpells.splice(i, 1);
newFilter.favoriteSpells = newFavoriteSpells;
return {
filter: newFilter
};
});
}
handleFavoriteInput = () => {
this.setState(function(prevState) {
let newFilter = prevState.filter;
newFilter.favorite = !prevState.filter.favorite;
return {
filter: newFilter
};
});
}
handleSearchInput = (searchTerm) => {
this.setState(function(prevState) {
let newFilter = prevState.filter;
newFilter.name = searchTerm;
return {
filter: newFilter
};
});
}
handlePropertiesInput = (propFilter) => {
this.setState(function(prevState) {
let newFilter = prevState.filter;
let newProperties = newFilter.properties;
for (let k in propFilter) {
newProperties[k] = propFilter[k];
}
newFilter.properties = newProperties;
return {
filter: newFilter
};
});
}
handleClassInput = (usedClasses) => {
this.setState(function(prevState) {
let newFilter = prevState.filter;
newFilter.spellClasses = usedClasses;
return {
filter: newFilter
};
});
}
render() {
const spells = this.props.spells.filter(
(spell) => { return !this.state.filter.filterSpell(spell); }
);
return (
<DSAGrid>
<DSAGridRow>
<DSAInfoBox
title="Zaubersprüche"
text="Suche und Finde Zaubersprüche aller Art">
<FilterWidget
filter={this.state.filter}
spells={spells}
onSearchInput={this.handleSearchInput}
onClassInput={this.handleClassInput}
onPropertiesInput={this.handlePropertiesInput}
onFavoriteInput={this.handleFavoriteInput}
/>
</DSAInfoBox>
</DSAGridRow>
<DSAGridRow>
<SpellList
spells={spells}
favoriteSpells={this.state.filter.favoriteSpells}
onFavoriteChange={this.handleFavoriteChange}/>
</DSAGridRow>
</DSAGrid>
);
}
}