diff --git a/.flowconfig b/.flowconfig index da47905..83cd117 100644 --- a/.flowconfig +++ b/.flowconfig @@ -9,6 +9,8 @@ types/types.js [options] esproposal.export_star_as=enable unsafe.enable_getters_and_setters=true +module.system.node.resolve_dirname=node_modules +module.system.node.resolve_dirname=src [lints] all=warn diff --git a/src/components/ControlMap.js b/src/components/ControlMap.js index ac418f4..81dafcd 100644 --- a/src/components/ControlMap.js +++ b/src/components/ControlMap.js @@ -7,7 +7,7 @@ import parseIconName, { controlGetIcon } from "utils/parseIconName"; export type Point = [number, number]; -const convertPoint = (p: Point) => [-p[1], p[0]]; +const convertPoint = ([y,x]: Point): Point => [-x, y]; export type ControlMapProps = { width: number, @@ -20,7 +20,7 @@ export type ControlMapProps = { }; export default class ControlMap extends React.Component { - constructor(props: SpaceMapProps) { + constructor(props: ControlMapProps) { super(props); } @@ -57,15 +57,15 @@ export default class ControlMap extends React.Component { }); } - iconColor(control: Control) { - if (control.iconColor == null) { - return "#000"; + iconColor(control: Control): string { + if (control.iconColor != null) { + return control.iconColor( + _.mapValues(this.props.state, (x) => x.internal || x.actual), + _.mapValues(this.props.state, (x) => x.actual), + this.props.state + ); } - return control.iconColor( - _.mapValues(this.props.state, (x) => x.internal || x.actual), - _.mapValues(this.props.state, (x) => x.actual), - this.props.state - ); + return "#000"; } renderMarker(control: Control, key: string) { @@ -97,7 +97,7 @@ export default class ControlMap extends React.Component { checked={layer.defaultVisibility === "visible"}> + opacity={layer.opacity || 1} /> ); } diff --git a/src/utils/parseIconName.js b/src/utils/parseIconName.js index 265d0a4..f4d172e 100644 --- a/src/utils/parseIconName.js +++ b/src/utils/parseIconName.js @@ -11,7 +11,7 @@ export const renderIcon = (name: string, extraClass?: string) => { }; export const controlGetIcon = (control: Control, state: State): string => { - return !_.isFunction(control.icon) ? control.icon + return typeof control.icon !== "function" ? control.icon : control.icon( _.mapValues(state, (x) => x.internal || x.actual), _.mapValues(state, (x) => x.actual), diff --git a/types/types.js b/types/types.js index cff9509..75b0f29 100644 --- a/types/types.js +++ b/types/types.js @@ -14,7 +14,7 @@ declare type Topic = { declare type Topics = Map; declare type ControlUI = { - type: "toggle" | "dropDown" | "slider" | "section", + type: "toggle" | "dropDown" | "slider" | "section" | "link", text: string, topic?: string, icon?: string, @@ -66,10 +66,15 @@ declare type Config = { declare type Space = { name: string, color: "red"|"pink"|"purple"|"deepPurple"|"indigo"|"blue"|"lightBlue"|"cyan"|"teal"| - "green"|"lightgreen"|"lime"|"yellow"|"amber"|"orange"|"deepOrange"|"brown"|"grey"|"blueGrey" + "green"|"lightGreen"|"lime"|"yellow"|"amber"|"orange"|"deepOrange"|"brown"|"grey"|"blueGrey", + mqtt: string }; -declare type State = Map; +declare type StateValue = { + internal: string, + actual: any +}; +declare type State = Map; //declare type State = { // mqtt: ?any, @@ -89,16 +94,11 @@ declare type Point = [number, number]; declare type Layer = { image: string, name: string, - baseLayer: boolean, + baseLayer?: boolean, defaultVisibility: "visible" | "hidden", - opacity: number, + opacity?: number, bounds: { topLeft: Point, bottomRight: Point } }; - -declare type StateAction = { - type: "DISCONNECT" | "CONNECT" | "MESSAGE" | "UI_POPUP", - payload?: any -};