forked from MapComplete/MapComplete
		
	First part of a huge refactoring
This commit is contained in:
		
							parent
							
								
									0c22b15c8d
								
							
						
					
					
						commit
						11150a258d
					
				
					 56 changed files with 1425 additions and 1324 deletions
				
			
		|  | @ -1,5 +1,4 @@ | |||
| import {VariableUiElement} from "../Base/VariableUIElement"; | ||||
| import {AllKnownLayouts} from "../../Customizations/AllKnownLayouts"; | ||||
| import Svg from "../../Svg"; | ||||
| import Combine from "../Base/Combine"; | ||||
| import {SubtleButton} from "../Base/SubtleButton"; | ||||
|  | @ -15,6 +14,8 @@ import UserRelatedState from "../../Logic/State/UserRelatedState"; | |||
| import Toggle from "../Input/Toggle"; | ||||
| import {Utils} from "../../Utils"; | ||||
| import Title from "../Base/Title"; | ||||
| import * as themeOverview from "../../assets/generated/theme_overview.json" | ||||
| import {Translation} from "../i18n/Translation"; | ||||
| 
 | ||||
| export default class MoreScreen extends Combine { | ||||
| 
 | ||||
|  | @ -47,7 +48,12 @@ export default class MoreScreen extends Combine { | |||
|         state: { | ||||
|             locationControl?: UIEventSource<Loc>, | ||||
|             layoutToUse?: LayoutConfig | ||||
|         }, layout: LayoutConfig, customThemeDefinition: string = undefined | ||||
|         }, layout: { | ||||
|             id: string, | ||||
|             icon: string, | ||||
|             title: any, | ||||
|             shortDescription: any | ||||
|         }, customThemeDefinition: string = undefined | ||||
|     ): | ||||
|         BaseUIElement { | ||||
|         if (layout === undefined) { | ||||
|  | @ -75,11 +81,11 @@ export default class MoreScreen extends Combine { | |||
|         let linkPrefix = `${path}/${layout.id.toLowerCase()}.html?` | ||||
|         let linkSuffix = "" | ||||
|         if (location.hostname === "localhost" || location.hostname === "127.0.0.1") { | ||||
|             linkPrefix = `${path}/index.html?layout=${layout.id}&` | ||||
|             linkPrefix = `${path}/theme.html?layout=${layout.id}&` | ||||
|         } | ||||
| 
 | ||||
|         if (customThemeDefinition) { | ||||
|             linkPrefix = `${path}/index.html?userlayout=${layout.id}&` | ||||
|             linkPrefix = `${path}/theme.html?userlayout=${layout.id}&` | ||||
|             linkSuffix = `#${customThemeDefinition}` | ||||
|         } | ||||
| 
 | ||||
|  | @ -98,10 +104,10 @@ export default class MoreScreen extends Combine { | |||
|         return new SubtleButton(layout.icon, | ||||
|             new Combine([ | ||||
|                 `<dt class='text-lg leading-6 font-medium text-gray-900 group-hover:text-blue-800'>`, | ||||
|                 Translations.WT(layout.title), | ||||
|                 new Translation(layout.title), | ||||
|                 `</dt>`, | ||||
|                 `<dd class='mt-1 text-base text-gray-500 group-hover:text-blue-900 overflow-ellipsis'>`, | ||||
|                 Translations.WT(layout.shortDescription)?.SetClass("subtle") ?? "", | ||||
|                 new Translation(layout.shortDescription)?.SetClass("subtle") ?? "", | ||||
|                 `</dd>`, | ||||
|             ]), {url: linkText, newTab: false}); | ||||
|     } | ||||
|  | @ -122,27 +128,29 @@ export default class MoreScreen extends Combine { | |||
|     private static createPreviouslyVistedHiddenList(state: UserRelatedState, buttonClass: string, themeListStyle: string) { | ||||
|         const t = Translations.t.general.morescreen | ||||
|         const prefix = "mapcomplete-hidden-theme-" | ||||
|         const hiddenTotal = AllKnownLayouts.layoutsList.filter(layout => layout.hideFromOverview).length | ||||
|         const hiddenThemes = themeOverview["default"].filter(layout => layout.hideFromOverview) | ||||
|         const hiddenTotal = hiddenThemes.length | ||||
|          | ||||
|         return new Toggle( | ||||
|             new VariableUiElement( | ||||
|                 state.osmConnection.preferencesHandler.preferences.map(allPreferences => { | ||||
|                     const knownThemes = Utils.NoNull(Object.keys(allPreferences) | ||||
|                     const knownThemes: Set<string> = new Set(Utils.NoNull(Object.keys(allPreferences) | ||||
|                         .filter(key => key.startsWith(prefix)) | ||||
|                         .map(key => key.substring(prefix.length, key.length - "-enabled".length)) | ||||
|                         .map(theme => AllKnownLayouts.allKnownLayouts.get(theme))) | ||||
|                         .filter(theme => theme?.hideFromOverview) | ||||
|                     if (knownThemes.length === 0) { | ||||
|                         .map(key => key.substring(prefix.length, key.length - "-enabled".length)))); | ||||
|                      | ||||
|                     if(knownThemes.size === 0){ | ||||
|                         return undefined | ||||
|                     } | ||||
|                      | ||||
|                      const knownThemeDescriptions = hiddenThemes.filter(theme => knownThemes.has(theme.id)) | ||||
|                          .map(theme => MoreScreen.createLinkButton(state, theme)?.SetClass(buttonClass)); | ||||
| 
 | ||||
|                     const knownLayouts = new Combine(knownThemes.map(layout => | ||||
|                         MoreScreen.createLinkButton(state, layout)?.SetClass(buttonClass) | ||||
|                     )).SetClass(themeListStyle) | ||||
|                     const knownLayouts = new Combine(knownThemeDescriptions).SetClass(themeListStyle) | ||||
| 
 | ||||
|                     return new Combine([ | ||||
|                         new Title(t.previouslyHiddenTitle), | ||||
|                         t.hiddenExplanation.Subs({ | ||||
|                             hidden_discovered: "" + knownThemes.length, | ||||
|                             hidden_discovered: "" + knownThemes.size, | ||||
|                             total_hidden: "" + hiddenTotal | ||||
|                         }), | ||||
|                         knownLayouts | ||||
|  | @ -158,7 +166,7 @@ export default class MoreScreen extends Combine { | |||
|     } | ||||
| 
 | ||||
|     private static createOfficialThemesList(state: { osmConnection: OsmConnection, locationControl?: UIEventSource<Loc> }, buttonClass: string): BaseUIElement { | ||||
|         let officialThemes = AllKnownLayouts.layoutsList | ||||
|         let officialThemes = themeOverview["default"]; | ||||
| 
 | ||||
|         let buttons = officialThemes.map((layout) => { | ||||
|             if (layout === undefined) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue