mapcomplete/UI/BigComponents/FilterView.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-07-27 17:00:05 +02:00
import { VariableUiElement } from "../Base/VariableUIElement"
2023-03-28 05:13:48 +02:00
import Toggle from "../Input/Toggle"
2021-07-20 15:14:51 +02:00
import Combine from "../Base/Combine"
import Translations from "../i18n/Translations"
2021-07-27 17:00:05 +02:00
import { Translation } from "../i18n/Translation"
2021-07-20 16:29:48 +02:00
import Svg from "../../Svg"
import { ImmutableStore, Store, UIEventSource } from "../../Logic/UIEventSource"
2023-03-28 05:13:48 +02:00
import FilteredLayer from "../../Models/FilteredLayer"
import TilesourceConfig from "../../Models/ThemeConfig/TilesourceConfig"
2022-08-20 12:46:33 +02:00
import Loc from "../../Models/Loc"
2021-07-27 19:39:57 +02:00
2021-07-26 12:26:41 +02:00
export default class FilterView extends VariableUiElement {
2022-08-20 12:46:33 +02:00
constructor(
filteredLayer: Store<FilteredLayer[]>,
tileLayers: { config: TilesourceConfig; isDisplayed: UIEventSource<boolean> }[],
state: {
2023-01-11 05:01:48 +01:00
readonly availableBackgroundLayers?: Store<BaseLayer[]>
readonly featureSwitchBackgroundSelection?: UIEventSource<boolean>
readonly featureSwitchIsDebugging?: UIEventSource<boolean>
readonly locationControl?: UIEventSource<Loc>
readonly featureSwitchMoreQuests: Store<boolean>
2022-08-20 12:46:33 +02:00
}
) {
2021-07-27 17:00:05 +02:00
super(
filteredLayer.map((filteredLayers) => {
// Create the views which toggle layers (and filters them) ...
2022-02-02 01:51:19 +01:00
let elements = filteredLayers
2022-08-20 12:46:33 +02:00
?.map((l) =>
FilterView.createOneFilteredLayerElement(l, state)?.SetClass("filter-panel")
2022-09-08 21:40:48 +02:00
)
2022-02-02 01:51:19 +01:00
?.filter((l) => l !== undefined)
elements[0].SetClass("first-filter-panel")
2022-09-08 21:40:48 +02:00
// ... create views for non-interactive layers ...
2022-08-20 12:46:33 +02:00
elements = elements.concat(
tileLayers.map((tl) => FilterView.createOverlayToggle(state, tl))
2022-09-08 21:40:48 +02:00
)
2023-01-11 05:01:48 +01:00
return elements
})
)
}
2022-08-20 12:46:33 +02:00
private static createOverlayToggle(
state: { locationControl?: UIEventSource<Loc> },
config: { config: TilesourceConfig; isDisplayed: UIEventSource<boolean> }
) {
const iconStyle = "width:1.5rem;height:1.5rem;margin-left:1.25rem;flex-shrink: 0;"
const icon = new Combine([Svg.checkbox_filled]).SetStyle(iconStyle)
const iconUnselected = new Combine([Svg.checkbox_empty]).SetStyle(iconStyle)
const name: Translation = config.config.name
2021-10-30 02:34:16 +02:00
const styledNameChecked = name.Clone().SetStyle("font-size:large").SetClass("ml-2")
const styledNameUnChecked = name.Clone().SetStyle("font-size:large").SetClass("ml-2")
const style = "display:flex;align-items:center;padding:0.5rem 0;"
const layerChecked = new Combine([icon, styledNameChecked])
.SetStyle(style)
.onClick(() => config.isDisplayed.setData(false))
const layerNotChecked = new Combine([iconUnselected, styledNameUnChecked])
.SetStyle(style)
.onClick(() => config.isDisplayed.setData(true))
return new Toggle(layerChecked, layerNotChecked, config.isDisplayed)
2021-07-26 12:26:41 +02:00
}
2021-07-20 15:14:51 +02:00
}