Fix many eslint warnings

This commit is contained in:
uwap 2018-07-10 18:08:13 +02:00
parent f7972afcd4
commit b1bf5efd11
7 changed files with 46 additions and 39 deletions

View file

@ -57,7 +57,7 @@ class App extends React.PureComponent<AppProps & Classes, AppState> {
Object.assign({}, ...this.props.config.topics) : this.props.config.topics;
}
static styles(_theme: Object) {
static styles() {
return {
drawerPaper: {
width: 320
@ -83,10 +83,9 @@ class App extends React.PureComponent<AppProps & Classes, AppState> {
return;
}
for (let i in topics) {
// TODO: Remove FlowFixMe
const topic = topics[i];
// $FlowFixMe
const parseValue = this.topics[topic].state.type;
const stateTopic = this.topics[topic].state;
const parseValue = stateTopic ? stateTopic.type : null;
const val = parseValue == null ? message.toString() : parseValue(message);
this.setState({mqttState: Object.assign({}, merge(this.state.mqttState,
{ [topic]: val}))});

View file

@ -31,7 +31,7 @@ class SideBar extends React.PureComponent<Props, SideBarState> {
super(props);
}
static styles(_theme: Object): Object {
static styles(): Object {
return {
drawerPaper: {
width: 340

View file

@ -3,6 +3,7 @@ import React from "react";
import keys from "lodash/keys";
import map from "lodash/map";
import debounce from "lodash/debounce";
import { renderIcon } from "config/icon";
import ListItemSecondaryAction from "@material-ui/core/ListItemSecondaryAction";
import ListItemText from "@material-ui/core/ListItemText";
import ListSubheader from "@material-ui/core/ListSubheader";
@ -77,9 +78,9 @@ export class UiControl<I: UIControl> extends UiItem<I> {
debouncedChange = debounce((next: string) =>
this.props.onChangeState(this.props.item.topic, next), 50, {
leading: true,
trailing: true
});
leading: true,
trailing: true
});
getValue() {
const control = this.props.item;
@ -216,6 +217,8 @@ export class Link extends UiItem<UILink> {
color="primary"
disabled={!this.isEnabled()}
>
{this.props.item.icon == null ? ""
: renderIcon(this.props.item.icon(this.props.state), "mdi-24px")}
{this.props.item.text}
</Button>
);

View file

@ -32,7 +32,7 @@ export default class UiItemList extends React.PureComponent<UiItemListProps> {
}
return (
<ListItem key={key}>
{control.icon == null ||
{control.icon == null || control.type === "link" ||
<ListItemIcon>
{renderIcon(control.icon(this.props.state), "mdi-24px")}
</ListItemIcon>}

View file

@ -68,8 +68,6 @@ export type UILink = $ReadOnly<{|
text: string,
link: string,
enableCondition?: (s: State) => boolean,
// TODO: check if both the following options are implemented
icon?: Icon
|}>;

View file

@ -5,37 +5,37 @@ export opaque type RawIcon: string = string;
export type Icon = (State) => RawIcon;
export const raw_mdi = (name: string): RawIcon => {
export const rawMdi = (name: string): RawIcon => {
return `mdi ${name.split(" ").map((icon) => "mdi-".concat(icon)).join(" ")}`;
};
export const mdi = (icon: string) => () => raw_mdi(icon);
export const mdi = (icon: string) => () => rawMdi(icon);
export const mdi_battery = (topic: string) => (state: State) => {
export const mdiBattery = (topic: string) => (state: State) => {
const rawval = state[topic];
const val = parseInt(rawval);
const val = parseInt(rawval, 10);
if (isNaN(val)) {
return raw_mdi("battery-unknown");
return rawMdi("battery-unknown");
} else if (val > 95) {
return raw_mdi("battery");
return rawMdi("battery");
} else if (val > 85) {
return raw_mdi("battery-90");
return rawMdi("battery-90");
} else if (val > 75) {
return raw_mdi("battery-80");
return rawMdi("battery-80");
} else if (val > 65) {
return raw_mdi("battery-70");
return rawMdi("battery-70");
} else if (val > 55) {
return raw_mdi("battery-60");
return rawMdi("battery-60");
} else if (val > 45) {
return raw_mdi("battery-50");
return rawMdi("battery-50");
} else if (val > 35) {
return raw_mdi("battery-40");
return rawMdi("battery-40");
} else if (val > 25) {
return raw_mdi("battery-30");
return rawMdi("battery-30");
} else if (val > 15) {
return raw_mdi("battery-20");
return rawMdi("battery-20");
} else {
return raw_mdi("battery-10");
return rawMdi("battery-10");
}
};