forked from MapComplete/MapComplete
Refactoring: properly handle the hash
This commit is contained in:
parent
d6d9438bc7
commit
1ec76b66b5
8 changed files with 230 additions and 89 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import LayerConfig from "./ThemeConfig/LayerConfig"
|
||||
import { UIEventSource } from "../Logic/UIEventSource"
|
||||
import {UIEventSource} from "../Logic/UIEventSource"
|
||||
import UserRelatedState from "../Logic/State/UserRelatedState"
|
||||
import { Utils } from "../Utils"
|
||||
import { LocalStorageSource } from "../Logic/Web/LocalStorageSource"
|
||||
import {Utils} from "../Utils"
|
||||
import {LocalStorageSource} from "../Logic/Web/LocalStorageSource"
|
||||
|
||||
export type ThemeViewTabStates = typeof MenuState._themeviewTabs[number]
|
||||
export type MenuViewTabStates = typeof MenuState._menuviewTabs[number]
|
||||
|
|
@ -14,22 +14,28 @@ export type MenuViewTabStates = typeof MenuState._menuviewTabs[number]
|
|||
* Some convenience methods are provided for this as well
|
||||
*/
|
||||
export class MenuState {
|
||||
public static readonly _themeviewTabs = ["intro", "filters", "download", "copyright"] as const
|
||||
public static readonly _themeviewTabs = ["intro", "filters", "download", "copyright","share"] as const
|
||||
public static readonly _menuviewTabs = ["about", "settings", "community", "privacy","advanced"] as const
|
||||
public readonly themeIsOpened: UIEventSource<boolean>
|
||||
public readonly themeViewTabIndex: UIEventSource<number>
|
||||
public readonly themeViewTab: UIEventSource<ThemeViewTabStates>
|
||||
|
||||
public static readonly _menuviewTabs = ["about", "settings", "community", "privacy"] as const
|
||||
public readonly menuIsOpened: UIEventSource<boolean>
|
||||
public readonly menuViewTabIndex: UIEventSource<number>
|
||||
public readonly menuViewTab: UIEventSource<MenuViewTabStates>
|
||||
|
||||
public readonly backgroundLayerSelectionIsOpened: UIEventSource<boolean> = new UIEventSource<boolean>(false)
|
||||
|
||||
public readonly allToggles: {
|
||||
toggle: UIEventSource<boolean>, name: string,
|
||||
submenu?: UIEventSource<string>,
|
||||
showOverOthers?: boolean
|
||||
}[]
|
||||
|
||||
public readonly highlightedLayerInFilters: UIEventSource<string> = new UIEventSource<string>(
|
||||
undefined
|
||||
)
|
||||
public highlightedUserSetting: UIEventSource<string> = new UIEventSource<string>(undefined)
|
||||
|
||||
constructor(themeid: string = "") {
|
||||
if (themeid) {
|
||||
themeid += "-"
|
||||
|
|
@ -49,6 +55,7 @@ export class MenuState {
|
|||
[],
|
||||
(str) => MenuState._menuviewTabs.indexOf(<any>str)
|
||||
)
|
||||
this.menuViewTab.addCallbackAndRunD(s => console.trace("Menu view tab state is", s, this.menuIsOpened.data))
|
||||
this.menuIsOpened.addCallbackAndRun((isOpen) => {
|
||||
if (!isOpen) {
|
||||
this.highlightedUserSetting.setData(undefined)
|
||||
|
|
@ -70,7 +77,23 @@ export class MenuState {
|
|||
this.menuIsOpened.setData(false)
|
||||
}
|
||||
})
|
||||
|
||||
this.allToggles = [
|
||||
{
|
||||
toggle: this.menuIsOpened,
|
||||
name: "menu",
|
||||
submenu: this.menuViewTab
|
||||
}, {
|
||||
toggle: this.themeIsOpened,
|
||||
name: "theme-menu",
|
||||
submenu: this.themeViewTab
|
||||
}, {
|
||||
toggle: this.backgroundLayerSelectionIsOpened,
|
||||
name: "background",
|
||||
showOverOthers: true
|
||||
}]
|
||||
}
|
||||
|
||||
public openFilterView(highlightLayer?: LayerConfig | string) {
|
||||
this.themeIsOpened.setData(true)
|
||||
this.themeViewTab.setData("filters")
|
||||
|
|
@ -101,10 +124,15 @@ export class MenuState {
|
|||
this.highlightedUserSetting.setData(highlightTagRendering)
|
||||
}
|
||||
|
||||
public closeAll() {
|
||||
this.menuIsOpened.setData(false)
|
||||
this.themeIsOpened.setData(false)
|
||||
this.backgroundLayerSelectionIsOpened.setData(false)
|
||||
/**
|
||||
* Close all floatOvers.
|
||||
* Returns 'true' if at least one menu was opened
|
||||
*/
|
||||
public closeAll(): boolean {
|
||||
const toggles = [this.menuIsOpened, this.themeIsOpened, this.backgroundLayerSelectionIsOpened]
|
||||
const somethingIsOpen = toggles.some(t => t.data)
|
||||
toggles.forEach(t => t.setData(false))
|
||||
return somethingIsOpen
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ import {Utils} from "../Utils"
|
|||
import {EliCategory} from "./RasterLayerProperties"
|
||||
import BackgroundLayerResetter from "../Logic/Actors/BackgroundLayerResetter"
|
||||
import SaveFeatureSourceToLocalStorage from "../Logic/FeatureSource/Actors/SaveFeatureSourceToLocalStorage"
|
||||
import Hash from "../Logic/Web/Hash"
|
||||
import BBoxFeatureSource from "../Logic/FeatureSource/Sources/TouchesBboxFeatureSource"
|
||||
import NavigatorBackButtonHandler from "../Logic/Web/NavigatorBackButtonHandler";
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -523,43 +523,6 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
|||
* Setup various services for which no reference are needed
|
||||
*/
|
||||
private initActors() {
|
||||
{
|
||||
// Set the hash based on the selected element...
|
||||
this.selectedElement.addCallback((selected) => {
|
||||
Hash.hash.setData(selected?.properties?.id)
|
||||
})
|
||||
// ... search and select an element based on the hash
|
||||
Hash.hash.mapD(
|
||||
(hash) => {
|
||||
if (this.selectedElement.data?.properties?.id === hash) {
|
||||
// We already have the correct hash
|
||||
return
|
||||
}
|
||||
|
||||
const found = this.indexedFeatures.featuresById.data?.get(hash)
|
||||
if (!found) {
|
||||
return
|
||||
}
|
||||
if (found.properties.id === "last_click") {
|
||||
return
|
||||
}
|
||||
const layer = this.layout.getMatchingLayer(found.properties)
|
||||
console.log(
|
||||
"Setting selected element based on hash",
|
||||
hash,
|
||||
"; found",
|
||||
found,
|
||||
"got matching layer",
|
||||
layer.id,
|
||||
""
|
||||
)
|
||||
this.selectedElement.setData(found)
|
||||
this.selectedLayer.setData(layer)
|
||||
},
|
||||
[this.indexedFeatures.featuresById.stabilized(250)]
|
||||
)
|
||||
}
|
||||
|
||||
{
|
||||
// Unselect the selected element if it is panned out of view
|
||||
this.mapProperties.bounds.stabilized(250).addCallbackD((bounds) => {
|
||||
|
|
@ -582,6 +545,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
|||
}
|
||||
})
|
||||
}
|
||||
new NavigatorBackButtonHandler(this)
|
||||
new MetaTagging(this)
|
||||
new TitleHandler(this.selectedElement, this.selectedLayer, this.featureProperties, this)
|
||||
new ChangeToElementsActor(this.changes, this.featureProperties)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue