Fix back button behaviour, fix #523

This commit is contained in:
Pieter Vander Vennet 2021-10-25 20:50:59 +02:00
parent a6abbe45b8
commit 936cf1bf9f
6 changed files with 23 additions and 5 deletions

View file

@ -24,11 +24,16 @@ export default class ScrollableFullScreen extends UIElement {
private _fullscreencomponent: BaseUIElement; private _fullscreencomponent: BaseUIElement;
constructor(title: ((mode: string) => BaseUIElement), content: ((mode: string) => BaseUIElement), constructor(title: ((mode: string) => BaseUIElement), content: ((mode: string) => BaseUIElement),
hashToShow: string,
isShown: UIEventSource<boolean> = new UIEventSource<boolean>(false) isShown: UIEventSource<boolean> = new UIEventSource<boolean>(false)
) { ) {
super(); super();
this.isShown = isShown; this.isShown = isShown;
if (hashToShow === undefined) {
throw "HashToShow should be defined as it is vital for the 'back' key functionality"
}
this._component = this.BuildComponent(title("desktop"), content("desktop"), isShown) this._component = this.BuildComponent(title("desktop"), content("desktop"), isShown)
.SetClass("hidden md:block"); .SetClass("hidden md:block");
this._fullscreencomponent = this.BuildComponent(title("mobile"), content("mobile").SetClass("pb-20"), isShown); this._fullscreencomponent = this.BuildComponent(title("mobile"), content("mobile").SetClass("pb-20"), isShown);
@ -38,10 +43,18 @@ export default class ScrollableFullScreen extends UIElement {
isShown.addCallback(isShown => { isShown.addCallback(isShown => {
if (isShown) { if (isShown) {
self.Activate(); self.Activate();
Hash.hash.setData(hashToShow)
} else { } else {
ScrollableFullScreen.clear(); ScrollableFullScreen.clear();
} }
}) })
Hash.hash.addCallback(hash => {
if (hash === hashToShow) {
return
}
isShown.setData(false)
})
} }
private static clear() { private static clear() {
@ -67,10 +80,10 @@ export default class ScrollableFullScreen extends UIElement {
private BuildComponent(title: BaseUIElement, content: BaseUIElement, isShown: UIEventSource<boolean>) { private BuildComponent(title: BaseUIElement, content: BaseUIElement, isShown: UIEventSource<boolean>) {
const returnToTheMap = const returnToTheMap =
new Combine([ new Combine([
new Img(Svg.back.replace(/#000000/g,"#cccccc"),true) new Img(Svg.back.replace(/#000000/g, "#cccccc"), true)
.SetClass("block md:hidden w-12 h-12 p-2"), .SetClass("block md:hidden w-12 h-12 p-2"),
new Img(Svg.close.replace(/#000000/g,"#cccccc"),true) new Img(Svg.close.replace(/#000000/g, "#cccccc"), true)
.SetClass("hidden md:block w-12 h-12 p-3") .SetClass("hidden md:block w-12 h-12 p-3")
]).SetClass("rounded-full p-0 flex-shrink-0 self-center") ]).SetClass("rounded-full p-0 flex-shrink-0 self-center")
returnToTheMap.onClick(() => { returnToTheMap.onClick(() => {

View file

@ -13,7 +13,7 @@ import ExportPDF from "../ExportPDF";
export default class AllDownloads extends ScrollableFullScreen { export default class AllDownloads extends ScrollableFullScreen {
constructor(isShown: UIEventSource<boolean>) { constructor(isShown: UIEventSource<boolean>) {
super(AllDownloads.GenTitle, AllDownloads.GeneratePanel, isShown); super(AllDownloads.GenTitle, AllDownloads.GeneratePanel, "downloads", isShown);
} }
private static GenTitle(): BaseUIElement { private static GenTitle(): BaseUIElement {

View file

@ -30,6 +30,7 @@ export default class FullWelcomePaneWithTabs extends ScrollableFullScreen {
super( super(
() => layoutToUse.title.Clone(), () => layoutToUse.title.Clone(),
() => FullWelcomePaneWithTabs.GenerateContents(state, currentTab, isShown), () => FullWelcomePaneWithTabs.GenerateContents(state, currentTab, isShown),
"welcome",
isShown isShown
) )
} }

View file

@ -41,6 +41,7 @@ export default class LeftControls extends Combine {
state.layoutToUse, state.layoutToUse,
new ContributorCount(state).Contributors new ContributorCount(state).Contributors
), ),
"copyright",
guiState.copyrightViewIsOpened guiState.copyrightViewIsOpened
); );
@ -74,6 +75,7 @@ export default class LeftControls extends Combine {
new FilterView(state.filteredLayers, state.overlayToggles).SetClass( new FilterView(state.filteredLayers, state.overlayToggles).SetClass(
"block p-1" "block p-1"
), ),
"filters",
guiState.filterViewIsOpened guiState.filterViewIsOpened
).SetClass("rounded-lg"), ).SetClass("rounded-lg"),
new MapControlButton(Svg.filter_svg()) new MapControlButton(Svg.filter_svg())

View file

@ -254,6 +254,7 @@ export default class DefaultGUI {
const addNewPoint = new ScrollableFullScreen( const addNewPoint = new ScrollableFullScreen(
() => Translations.t.general.add.title.Clone(), () => Translations.t.general.add.title.Clone(),
() => new SimpleAddUI(newPointDialogIsShown, filterViewIsOpened, state), () => new SimpleAddUI(newPointDialogIsShown, filterViewIsOpened, state),
"new",
newPointDialogIsShown newPointDialogIsShown
); );
addNewPoint.isShown.addCallback((isShown) => { addNewPoint.isShown.addCallback((isShown) => {

View file

@ -26,7 +26,8 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
layerConfig: LayerConfig, layerConfig: LayerConfig,
) { ) {
super(() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig), super(() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig),
() => FeatureInfoBox.GenerateContent(tags, layerConfig)); () => FeatureInfoBox.GenerateContent(tags, layerConfig),
tags.data.id);
if (layerConfig === undefined) { if (layerConfig === undefined) {
throw "Undefined layerconfig"; throw "Undefined layerconfig";