forked from MapComplete/MapComplete
Refactoring(menuState): PreviewedImage is now a static property
This commit is contained in:
parent
dbcbf2787d
commit
2b3e3257fd
7 changed files with 38 additions and 16 deletions
|
@ -14,6 +14,7 @@ export type PageType = (typeof MenuState.pageNames)[number]
|
||||||
* Some convenience methods are provided for this as well
|
* Some convenience methods are provided for this as well
|
||||||
*/
|
*/
|
||||||
export class MenuState {
|
export class MenuState {
|
||||||
|
|
||||||
public static readonly pageNames = [
|
public static readonly pageNames = [
|
||||||
"copyright",
|
"copyright",
|
||||||
"copyright_icons",
|
"copyright_icons",
|
||||||
|
@ -27,17 +28,25 @@ export class MenuState {
|
||||||
"favourites",
|
"favourites",
|
||||||
"usersettings",
|
"usersettings",
|
||||||
"share",
|
"share",
|
||||||
"menu",
|
"menu"
|
||||||
] as const
|
] as const
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains the 'providedImage' which is currently displayed on top of the UI
|
||||||
|
* This object merely acts as lock or as means to signal the need to close
|
||||||
|
*/
|
||||||
|
public static readonly previewedImage: UIEventSource<object> = new UIEventSource<object>(undefined)
|
||||||
|
|
||||||
public readonly pageStates: Record<PageType, UIEventSource<boolean>>
|
public readonly pageStates: Record<PageType, UIEventSource<boolean>>
|
||||||
|
|
||||||
public readonly highlightedLayerInFilters: UIEventSource<string> = new UIEventSource<string>(
|
public readonly highlightedLayerInFilters: UIEventSource<string> = new UIEventSource<string>(
|
||||||
undefined
|
undefined
|
||||||
)
|
)
|
||||||
public highlightedUserSetting: UIEventSource<string> = new UIEventSource<string>(undefined)
|
public highlightedUserSetting: UIEventSource<string> = new UIEventSource<string>(undefined)
|
||||||
|
private readonly _selectedElement: UIEventSource<any>
|
||||||
|
|
||||||
constructor(shouldShowWelcomeMessage: boolean, themeid: string) {
|
constructor(selectedElement: UIEventSource<any>) {
|
||||||
|
this._selectedElement = selectedElement
|
||||||
// Note: this class is _not_ responsible to update the Hash, @see ThemeViewStateHashActor for this
|
// Note: this class is _not_ responsible to update the Hash, @see ThemeViewStateHashActor for this
|
||||||
const states = {}
|
const states = {}
|
||||||
for (const pageName of MenuState.pageNames) {
|
for (const pageName of MenuState.pageNames) {
|
||||||
|
@ -56,7 +65,9 @@ export class MenuState {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public openMenuIfNeeded(shouldShowWelcomeMessage: boolean, themeid: string) {
|
||||||
const visitedBefore = LocalStorageSource.getParsed<boolean>(
|
const visitedBefore = LocalStorageSource.getParsed<boolean>(
|
||||||
themeid + "thememenuisopened",
|
themeid + "thememenuisopened",
|
||||||
false
|
false
|
||||||
|
@ -103,6 +114,12 @@ export class MenuState {
|
||||||
}
|
}
|
||||||
|
|
||||||
public isSomethingOpen(): boolean {
|
public isSomethingOpen(): boolean {
|
||||||
|
if (MenuState.previewedImage.data !== undefined) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (this._selectedElement.data) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return Object.values(this.pageStates).some((t) => t.data)
|
return Object.values(this.pageStates).some((t) => t.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +128,18 @@ export class MenuState {
|
||||||
* Returns 'true' if at least one menu was opened
|
* Returns 'true' if at least one menu was opened
|
||||||
*/
|
*/
|
||||||
public closeAll(): boolean {
|
public closeAll(): boolean {
|
||||||
|
console.log("Closing all")
|
||||||
const ps = this.pageStates
|
const ps = this.pageStates
|
||||||
|
if (ps.menu.data) {
|
||||||
|
ps.menu.set(false)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MenuState.previewedImage.data !== undefined) {
|
||||||
|
MenuState.previewedImage.setData(undefined)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
for (const key in ps) {
|
for (const key in ps) {
|
||||||
const toggle = ps[key]
|
const toggle = ps[key]
|
||||||
const wasOpen = toggle.data
|
const wasOpen = toggle.data
|
||||||
|
@ -120,9 +148,10 @@ export class MenuState {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ps.menu.data) {
|
if (this._selectedElement.data) {
|
||||||
ps.menu.set(false)
|
this._selectedElement.setData(undefined)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ImageUploadManager } from "../../Logic/ImageProviders/ImageUploadManager"
|
import { ImageUploadManager } from "../../Logic/ImageProviders/ImageUploadManager"
|
||||||
import { UIEventSource } from "../../Logic/UIEventSource"
|
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
||||||
import { ProvidedImage } from "../../Logic/ImageProviders/ImageProvider"
|
import { ProvidedImage } from "../../Logic/ImageProviders/ImageProvider"
|
||||||
import { CombinedFetcher } from "../../Logic/Web/NearbyImagesSearch"
|
import { CombinedFetcher } from "../../Logic/Web/NearbyImagesSearch"
|
||||||
import ThemeConfig from "../ThemeConfig/ThemeConfig"
|
import ThemeConfig from "../ThemeConfig/ThemeConfig"
|
||||||
|
@ -18,7 +18,7 @@ export class WithImageState extends WithGuiState implements SpecialVisualization
|
||||||
readonly nearbyImageSearcher: CombinedFetcher
|
readonly nearbyImageSearcher: CombinedFetcher
|
||||||
|
|
||||||
|
|
||||||
constructor(layout: ThemeConfig, mvtAvailableLayers: Set<string>) {
|
constructor(layout: ThemeConfig, mvtAvailableLayers: Store<Set<string>>) {
|
||||||
super(layout, mvtAvailableLayers)
|
super(layout, mvtAvailableLayers)
|
||||||
this.imageUploadManager = new ImageUploadManager(
|
this.imageUploadManager = new ImageUploadManager(
|
||||||
layout,
|
layout,
|
||||||
|
@ -56,7 +56,6 @@ export class WithImageState extends WithGuiState implements SpecialVisualization
|
||||||
private initActors() {
|
private initActors() {
|
||||||
|
|
||||||
new ThemeViewStateHashActor({
|
new ThemeViewStateHashActor({
|
||||||
previewedImage: this.previewedImage,
|
|
||||||
selectedElement: this.selectedElement,
|
selectedElement: this.selectedElement,
|
||||||
indexedFeatures: this.indexedFeatures,
|
indexedFeatures: this.indexedFeatures,
|
||||||
guistate: this.guistate
|
guistate: this.guistate
|
||||||
|
|
|
@ -141,7 +141,6 @@
|
||||||
{state}
|
{state}
|
||||||
imgClass="h-32 shrink-0"
|
imgClass="h-32 shrink-0"
|
||||||
image={{ url: image, id: image }}
|
image={{ url: image, id: image }}
|
||||||
previewedImage={state.previewedImage}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
import Tr from "../Base/Tr.svelte"
|
import Tr from "../Base/Tr.svelte"
|
||||||
import DotMenu from "../Base/DotMenu.svelte"
|
import DotMenu from "../Base/DotMenu.svelte"
|
||||||
import LoadingPlaceholder from "../Base/LoadingPlaceholder.svelte"
|
import LoadingPlaceholder from "../Base/LoadingPlaceholder.svelte"
|
||||||
|
import { MenuState } from "../../Models/MenuState"
|
||||||
|
|
||||||
export let image: Partial<ProvidedImage>
|
export let image: Partial<ProvidedImage>
|
||||||
let fallbackImage: string = undefined
|
let fallbackImage: string = undefined
|
||||||
|
@ -29,7 +30,7 @@
|
||||||
export let imgClass: string = undefined
|
export let imgClass: string = undefined
|
||||||
export let state: SpecialVisualizationState = undefined
|
export let state: SpecialVisualizationState = undefined
|
||||||
export let attributionFormat: "minimal" | "medium" | "large" = "medium"
|
export let attributionFormat: "minimal" | "medium" | "large" = "medium"
|
||||||
export let previewedImage: UIEventSource<Partial<ProvidedImage>> = undefined
|
let previewedImage: UIEventSource<Partial<ProvidedImage>> = MenuState.previewedImage
|
||||||
export let canZoom = previewedImage !== undefined
|
export let canZoom = previewedImage !== undefined
|
||||||
let loaded = false
|
let loaded = false
|
||||||
let showBigPreview = new UIEventSource(false)
|
let showBigPreview = new UIEventSource(false)
|
||||||
|
@ -70,12 +71,11 @@
|
||||||
coordinates: [image.lon, image.lat],
|
coordinates: [image.lon, image.lat],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
console.log(f)
|
|
||||||
state?.geocodedImages.set([f])
|
state?.geocodedImages.set([f])
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Popup shown={showBigPreview} bodyPadding="p-0" dismissable={true}>
|
<Popup shown={showBigPreview} bodyPadding="p-0" dismissable={false}>
|
||||||
<div slot="close" />
|
<div slot="close" />
|
||||||
<div style="height: 80vh">
|
<div style="height: 80vh">
|
||||||
<ImageOperations {image}>
|
<ImageOperations {image}>
|
||||||
|
@ -87,7 +87,6 @@
|
||||||
<CloseButton
|
<CloseButton
|
||||||
class="normal-background"
|
class="normal-background"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
console.log("Closing")
|
|
||||||
previewedImage?.set(undefined)
|
previewedImage?.set(undefined)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -122,7 +121,6 @@
|
||||||
class={imgClass ?? ""}
|
class={imgClass ?? ""}
|
||||||
class:cursor-zoom-in={canZoom}
|
class:cursor-zoom-in={canZoom}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
console.log("Setting", image.url)
|
|
||||||
previewedImage?.set(image)
|
previewedImage?.set(image)
|
||||||
}}
|
}}
|
||||||
on:error={() => {
|
on:error={() => {
|
||||||
|
|
|
@ -149,7 +149,6 @@
|
||||||
imgClass="carousel-max-height"
|
imgClass="carousel-max-height"
|
||||||
{image}
|
{image}
|
||||||
{state}
|
{state}
|
||||||
previewedImage={state?.previewedImage}
|
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="dot-menu-actions">
|
<svelte:fragment slot="dot-menu-actions">
|
||||||
<button on:click={() => ImageProvider.offerImageAsDownload(image)}>
|
<button on:click={() => ImageProvider.offerImageAsDownload(image)}>
|
||||||
|
|
|
@ -87,7 +87,6 @@
|
||||||
{state}
|
{state}
|
||||||
image={providedImage}
|
image={providedImage}
|
||||||
imgClass="max-h-64 w-auto sm:h-32 md:h-64"
|
imgClass="max-h-64 w-auto sm:h-32 md:h-64"
|
||||||
previewedImage={state.previewedImage}
|
|
||||||
attributionFormat="minimal"
|
attributionFormat="minimal"
|
||||||
>
|
>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
@ -87,7 +87,6 @@
|
||||||
{state}
|
{state}
|
||||||
{image}
|
{image}
|
||||||
imgClass="max-h-64 w-auto sm:h-32 md:h-64"
|
imgClass="max-h-64 w-auto sm:h-32 md:h-64"
|
||||||
previewedImage={state.previewedImage}
|
|
||||||
attributionFormat="minimal"
|
attributionFormat="minimal"
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue