-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.jsx
43 lines (38 loc) · 1.52 KB
/
Settings.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
const { React } = require("powercord/webpack")
const { TextInput } = require("powercord/components/settings")
const { Divider, Spinner } = require("powercord/components")
const Pair = require("./Pair.jsx")
module.exports = class Settings extends React.Component {
displayItems () {
let items = [];
if (this.props.getSetting("pairs", []).length > 0) {
for (let i = 0; i < this.props.getSetting("pairs", []).length; i++)
items.push(this.props.getSetting("pairs", [])[i]);
}
return (this.props.getSetting("pairs", []).length > 0
? items.map((p, i) => <Pair key={p[0] + i.toString()} pos={i} p={p} parentProps={this.getPropsToPass()}/>)
: <h2 className="powercord-alias-header">No aliases!<div class="powercord-alias-break"/></h2>);
}
getPropsToPass () {
return {
checkUnique: (v, k, i, plug) => this.checkUnique(v, k, i),
setPairs: (v) => {this.props.updateSetting("pairs", v); this.setState({"pairs": v})},
getPairs: () => this.props.getSetting("pairs", []),
reload: () => this.forceUpdate()
};
}
render () {
return (
<div>
{
this.displayItems()
}
<Divider/>
<Pair key={" " + this.props.getSetting("pairs", []).length} pos={-1} parentProps={this.getPropsToPass()}/>
</div>
);
}
checkUnique (val, key, indexed) {
return this.props.getSetting("pairs", []).filter(function(v, k, t) { return v[0] == val }).length <= (indexed ? 0 : 1);
}
};