| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import { VariableUiElement } from "../Base/VariableUIElement" | 
					
						
							|  |  |  | import Svg from "../../Svg" | 
					
						
							|  |  |  | import Combine from "../Base/Combine" | 
					
						
							|  |  |  | import { SubtleButton } from "../Base/SubtleButton" | 
					
						
							|  |  |  | import Translations from "../i18n/Translations" | 
					
						
							| 
									
										
										
										
											2023-02-08 01:14:21 +01:00
										 |  |  | import personal from "../../assets/themes/personal/personal.json" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import Constants from "../../Models/Constants" | 
					
						
							|  |  |  | import BaseUIElement from "../BaseUIElement" | 
					
						
							|  |  |  | import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" | 
					
						
							|  |  |  | import { ImmutableStore, Store, Stores, UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  | import Loc from "../../Models/Loc" | 
					
						
							|  |  |  | import { OsmConnection } from "../../Logic/Osm/OsmConnection" | 
					
						
							|  |  |  | import UserRelatedState from "../../Logic/State/UserRelatedState" | 
					
						
							|  |  |  | import Toggle from "../Input/Toggle" | 
					
						
							|  |  |  | import { Utils } from "../../Utils" | 
					
						
							|  |  |  | import Title from "../Base/Title" | 
					
						
							| 
									
										
										
										
											2023-02-08 01:14:21 +01:00
										 |  |  | import themeOverview from "../../assets/generated/theme_overview.json" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import { Translation } from "../i18n/Translation" | 
					
						
							|  |  |  | import { TextField } from "../Input/TextField" | 
					
						
							|  |  |  | import FilteredCombine from "../Base/FilteredCombine" | 
					
						
							|  |  |  | import Locale from "../i18n/Locale" | 
					
						
							| 
									
										
										
										
											2020-07-29 15:48:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  | export default class MoreScreen extends Combine { | 
					
						
							|  |  |  |     private static readonly officialThemes: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         id: string | 
					
						
							|  |  |  |         icon: string | 
					
						
							|  |  |  |         title: any | 
					
						
							|  |  |  |         shortDescription: any | 
					
						
							|  |  |  |         definition?: any | 
					
						
							|  |  |  |         mustHaveLanguage?: boolean | 
					
						
							|  |  |  |         hideFromOverview: boolean | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  |         keywors?: any[] | 
					
						
							| 
									
										
										
										
											2023-02-08 01:14:21 +01:00
										 |  |  |     }[] = themeOverview | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     constructor( | 
					
						
							|  |  |  |         state: UserRelatedState & { | 
					
						
							|  |  |  |             locationControl?: UIEventSource<Loc> | 
					
						
							|  |  |  |             layoutToUse?: LayoutConfig | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         onMainScreen: boolean = false | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |         const tr = Translations.t.general.morescreen | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         let themeButtonStyle = "" | 
					
						
							|  |  |  |         let themeListStyle = "" | 
					
						
							|  |  |  |         if (onMainScreen) { | 
					
						
							| 
									
										
										
										
											2022-09-08 08:24:17 +02:00
										 |  |  |             themeButtonStyle = "h-32 min-h-32 max-h-32 text-ellipsis overflow-hidden" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             themeListStyle = | 
					
						
							|  |  |  |                 "md:grid md:grid-flow-row md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-g4 gap-4" | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |         const search = new TextField({ | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  |             placeholder: tr.searchForATheme, | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         search.enterPressed.addCallbackD((searchTerm) => { | 
					
						
							| 
									
										
										
										
											2022-04-30 14:00:03 +02:00
										 |  |  |             searchTerm = searchTerm.toLowerCase() | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             if (searchTerm === "personal") { | 
					
						
							|  |  |  |                 window.location.href = MoreScreen.createUrlFor( | 
					
						
							|  |  |  |                     { id: "personal" }, | 
					
						
							|  |  |  |                     false, | 
					
						
							|  |  |  |                     state | 
					
						
							|  |  |  |                 ).data | 
					
						
							| 
									
										
										
										
											2022-04-30 14:00:03 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             if (searchTerm === "bugs" || searchTerm === "issues") { | 
					
						
							| 
									
										
										
										
											2022-04-30 14:00:03 +02:00
										 |  |  |                 window.location.href = "https://github.com/pietervdvn/MapComplete/issues" | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             if (searchTerm === "source") { | 
					
						
							| 
									
										
										
										
											2022-04-30 14:00:03 +02:00
										 |  |  |                 window.location.href = "https://github.com/pietervdvn/MapComplete" | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             if (searchTerm === "docs") { | 
					
						
							| 
									
										
										
										
											2022-04-30 14:00:03 +02:00
										 |  |  |                 window.location.href = "https://github.com/pietervdvn/MapComplete/tree/develop/Docs" | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             if (searchTerm === "osmcha" || searchTerm === "stats") { | 
					
						
							| 
									
										
										
										
											2022-04-30 14:00:03 +02:00
										 |  |  |                 window.location.href = Utils.OsmChaLinkFor(7) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  |             // Enter pressed -> search the first _official_ matchin theme and open it
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             const publicTheme = MoreScreen.officialThemes.find( | 
					
						
							|  |  |  |                 (th) => | 
					
						
							|  |  |  |                     th.hideFromOverview == false && | 
					
						
							|  |  |  |                     th.id !== "personal" && | 
					
						
							|  |  |  |                     MoreScreen.MatchesLayoutFunc(th)(searchTerm) | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  |             if (publicTheme !== undefined) { | 
					
						
							|  |  |  |                 window.location.href = MoreScreen.createUrlFor(publicTheme, false, state).data | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             const hiddenTheme = MoreScreen.officialThemes.find( | 
					
						
							|  |  |  |                 (th) => th.id !== "personal" && MoreScreen.MatchesLayoutFunc(th)(searchTerm) | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  |             if (hiddenTheme !== undefined) { | 
					
						
							|  |  |  |                 window.location.href = MoreScreen.createUrlFor(hiddenTheme, false, state).data | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (onMainScreen) { | 
					
						
							|  |  |  |             search.focus() | 
					
						
							| 
									
										
										
										
											2022-12-24 02:01:58 +01:00
										 |  |  |             document.addEventListener("keydown", function (event) { | 
					
						
							|  |  |  |                 if (event.ctrlKey && event.code === "KeyF") { | 
					
						
							|  |  |  |                     search.focus() | 
					
						
							|  |  |  |                     event.preventDefault() | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const searchBar = new Combine([ | 
					
						
							|  |  |  |             Svg.search_svg().SetClass("w-8"), | 
					
						
							|  |  |  |             search.SetClass("mr-4 w-full"), | 
					
						
							|  |  |  |         ]).SetClass("flex rounded-full border-2 border-black items-center my-2 w-1/2") | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  |         super([ | 
					
						
							|  |  |  |             new Combine([searchBar]).SetClass("flex justify-center"), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             MoreScreen.createOfficialThemesList( | 
					
						
							|  |  |  |                 state, | 
					
						
							|  |  |  |                 themeButtonStyle, | 
					
						
							|  |  |  |                 themeListStyle, | 
					
						
							|  |  |  |                 search.GetValue() | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             MoreScreen.createPreviouslyVistedHiddenList( | 
					
						
							|  |  |  |                 state, | 
					
						
							|  |  |  |                 themeButtonStyle, | 
					
						
							|  |  |  |                 themeListStyle, | 
					
						
							|  |  |  |                 search.GetValue() | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             MoreScreen.createUnofficialThemeList( | 
					
						
							|  |  |  |                 themeButtonStyle, | 
					
						
							|  |  |  |                 state, | 
					
						
							|  |  |  |                 themeListStyle, | 
					
						
							|  |  |  |                 search.GetValue() | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             tr.streetcomplete.Clone().SetClass("block text-base mx-10 my-3 mb-10"), | 
					
						
							|  |  |  |         ]) | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     private static NothingFound(search: UIEventSource<string>): BaseUIElement { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const t = Translations.t.general.morescreen | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |         return new Combine([ | 
					
						
							|  |  |  |             new Title(t.noMatchingThemes, 5).SetClass("w-max font-bold"), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             new SubtleButton(Svg.search_disable_ui(), t.noSearch, { imgSize: "h-6" }) | 
					
						
							|  |  |  |                 .SetClass("h-12 w-max") | 
					
						
							|  |  |  |                 .onClick(() => search.setData("")), | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |         ]).SetClass("flex flex-col items-center w-full") | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private static createUrlFor( | 
					
						
							|  |  |  |         layout: { id: string; definition?: string }, | 
					
						
							|  |  |  |         isCustom: boolean, | 
					
						
							|  |  |  |         state?: { locationControl?: UIEventSource<{ lat; lon; zoom }>; layoutToUse?: { id } } | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |     ): Store<string> { | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         if (layout === undefined) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             return undefined | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (layout.id === undefined) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             console.error("ID is undefined for layout", layout) | 
					
						
							|  |  |  |             return undefined | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (layout.id === state?.layoutToUse?.id) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             return undefined | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const currentLocation = state?.locationControl | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         let path = window.location.pathname | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         // Path starts with a '/' and contains everything, e.g. '/dir/dir/page.html'
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         path = path.substr(0, path.lastIndexOf("/")) | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         // Path will now contain '/dir/dir', or empty string in case of nothing
 | 
					
						
							|  |  |  |         if (path === "") { | 
					
						
							|  |  |  |             path = "." | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let linkPrefix = `${path}/${layout.id.toLowerCase()}.html?` | 
					
						
							|  |  |  |         if (location.hostname === "localhost" || location.hostname === "127.0.0.1") { | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |             linkPrefix = `${path}/theme.html?layout=${layout.id}&` | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-21 20:57:25 +01:00
										 |  |  |         if (isCustom) { | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |             linkPrefix = `${path}/theme.html?userlayout=${layout.id}&` | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 15:41:14 +01:00
										 |  |  |         let hash = "" | 
					
						
							| 
									
										
										
										
											2022-04-13 02:44:06 +02:00
										 |  |  |         if (layout.definition !== undefined) { | 
					
						
							|  |  |  |             hash = "#" + btoa(JSON.stringify(layout.definition)) | 
					
						
							| 
									
										
										
										
											2022-02-14 15:41:14 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-04-13 02:44:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return ( | 
					
						
							|  |  |  |             currentLocation?.map((currentLocation) => { | 
					
						
							|  |  |  |                 const params = [ | 
					
						
							|  |  |  |                     ["z", currentLocation?.zoom], | 
					
						
							|  |  |  |                     ["lat", currentLocation?.lat], | 
					
						
							|  |  |  |                     ["lon", currentLocation?.lon], | 
					
						
							|  |  |  |                 ] | 
					
						
							|  |  |  |                     .filter((part) => part[1] !== undefined) | 
					
						
							|  |  |  |                     .map((part) => part[0] + "=" + part[1]) | 
					
						
							|  |  |  |                     .join("&") | 
					
						
							|  |  |  |                 return `${linkPrefix}${params}${hash}` | 
					
						
							|  |  |  |             }) ?? new ImmutableStore<string>(`${linkPrefix}`) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Creates a button linking to the given theme | 
					
						
							|  |  |  |      * @private | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static createLinkButton( | 
					
						
							|  |  |  |         state: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             locationControl?: UIEventSource<Loc> | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  |             layoutToUse?: LayoutConfig | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |         layout: { | 
					
						
							|  |  |  |             id: string | 
					
						
							|  |  |  |             icon: string | 
					
						
							|  |  |  |             title: any | 
					
						
							|  |  |  |             shortDescription: any | 
					
						
							|  |  |  |             definition?: any | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  |             mustHaveLanguage?: boolean | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |         isCustom: boolean = false | 
					
						
							|  |  |  |     ): BaseUIElement { | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  |         const url = MoreScreen.createUrlFor(layout, isCustom, state) | 
					
						
							| 
									
										
										
										
											2022-07-01 00:16:05 +02:00
										 |  |  |         let content = new Combine([ | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             new Translation( | 
					
						
							|  |  |  |                 layout.title, | 
					
						
							|  |  |  |                 !isCustom && !layout.mustHaveLanguage ? "themes:" + layout.id + ".title" : undefined | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2022-07-01 00:16:05 +02:00
										 |  |  |             new Translation(layout.shortDescription)?.SetClass("subtle") ?? "", | 
					
						
							|  |  |  |         ]).SetClass("overflow-hidden flex flex-col") | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (state.layoutToUse === undefined) { | 
					
						
							| 
									
										
										
										
											2022-07-01 00:16:05 +02:00
										 |  |  |             // Currently on the index screen: we style the buttons equally large
 | 
					
						
							|  |  |  |             content = new Combine([content]).SetClass("flex flex-col justify-center h-24") | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return new SubtleButton(layout.icon, content, { url, newTab: false }) | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-18 21:26:07 +01:00
										 |  |  |     public static CreateProffessionalSerivesButton() { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const t = Translations.t.professional.indexPage | 
					
						
							| 
									
										
										
										
											2022-01-18 00:09:01 +01:00
										 |  |  |         return new Combine([ | 
					
						
							|  |  |  |             new Title(t.hook, 4), | 
					
						
							|  |  |  |             t.hookMore, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             new SubtleButton(undefined, t.button, { url: "./professional.html" }), | 
					
						
							| 
									
										
										
										
											2022-01-18 00:09:01 +01:00
										 |  |  |         ]).SetClass("flex flex-col border border-gray-300 p-2 rounded-lg") | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private static createUnofficialThemeList( | 
					
						
							|  |  |  |         buttonClass: string, | 
					
						
							|  |  |  |         state: UserRelatedState, | 
					
						
							|  |  |  |         themeListClasses: string, | 
					
						
							|  |  |  |         search: UIEventSource<string> | 
					
						
							|  |  |  |     ): BaseUIElement { | 
					
						
							| 
									
										
										
										
											2022-07-01 00:16:05 +02:00
										 |  |  |         var currentIds: Store<string[]> = state.installedUserThemes | 
					
						
							| 
									
										
										
										
											2022-02-10 23:16:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |         var stableIds = Stores.ListStabilized<string>(currentIds) | 
					
						
							| 
									
										
										
										
											2022-02-04 15:48:26 +01:00
										 |  |  |         return new VariableUiElement( | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             stableIds.map((ids) => { | 
					
						
							|  |  |  |                 const allThemes: { element: BaseUIElement; predicate?: (s: string) => boolean }[] = | 
					
						
							|  |  |  |                     [] | 
					
						
							| 
									
										
										
										
											2022-02-04 15:48:26 +01:00
										 |  |  |                 for (const id of ids) { | 
					
						
							| 
									
										
										
										
											2022-06-21 18:22:09 +02:00
										 |  |  |                     const themeInfo = state.GetUnofficialTheme(id) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     if (themeInfo === undefined) { | 
					
						
							| 
									
										
										
										
											2022-06-21 18:22:09 +02:00
										 |  |  |                         continue | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     const link = MoreScreen.createLinkButton(state, themeInfo, true) | 
					
						
							| 
									
										
										
										
											2022-02-04 15:48:26 +01:00
										 |  |  |                     if (link !== undefined) { | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  |                         allThemes.push({ | 
					
						
							|  |  |  |                             element: link.SetClass(buttonClass), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                             predicate: (s) => id.toLowerCase().indexOf(s) >= 0, | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  |                         }) | 
					
						
							| 
									
										
										
										
											2022-02-04 14:36:26 +01:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-02-04 15:48:26 +01:00
										 |  |  |                 if (allThemes.length <= 0) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     return undefined | 
					
						
							| 
									
										
										
										
											2022-02-04 15:48:26 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 return new Combine([ | 
					
						
							| 
									
										
										
										
											2022-04-13 02:44:06 +02:00
										 |  |  |                     Translations.t.general.customThemeIntro, | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |                     new FilteredCombine(allThemes, search, { | 
					
						
							|  |  |  |                         innerClasses: themeListClasses, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                         onEmpty: MoreScreen.NothingFound(search), | 
					
						
							|  |  |  |                     }), | 
					
						
							|  |  |  |                 ]) | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-15 19:58:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private static createPreviouslyVistedHiddenList( | 
					
						
							|  |  |  |         state: UserRelatedState, | 
					
						
							|  |  |  |         buttonClass: string, | 
					
						
							|  |  |  |         themeListStyle: string, | 
					
						
							|  |  |  |         search: UIEventSource<string> | 
					
						
							|  |  |  |     ): BaseUIElement { | 
					
						
							| 
									
										
										
										
											2021-10-15 19:58:02 +02:00
										 |  |  |         const t = Translations.t.general.morescreen | 
					
						
							|  |  |  |         const prefix = "mapcomplete-hidden-theme-" | 
					
						
							| 
									
										
										
										
											2023-02-08 01:14:21 +01:00
										 |  |  |         const hiddenThemes = themeOverview.filter((layout) => layout.hideFromOverview) | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |         const hiddenTotal = hiddenThemes.length | 
					
						
							| 
									
										
										
										
											2022-01-18 00:09:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         return new Toggle( | 
					
						
							|  |  |  |             new VariableUiElement( | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 state.osmConnection.preferencesHandler.preferences.map((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) | 
					
						
							|  |  |  |                                 ) | 
					
						
							|  |  |  |                         ) | 
					
						
							|  |  |  |                     ) | 
					
						
							| 
									
										
										
										
											2022-01-18 00:09:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     if (knownThemes.size === 0) { | 
					
						
							| 
									
										
										
										
											2021-10-15 19:58:02 +02:00
										 |  |  |                         return undefined | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2022-01-18 00:09:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     const knownThemeDescriptions = hiddenThemes | 
					
						
							|  |  |  |                         .filter((theme) => knownThemes.has(theme.id)) | 
					
						
							|  |  |  |                         .map((theme) => ({ | 
					
						
							|  |  |  |                             element: MoreScreen.createLinkButton(state, theme)?.SetClass( | 
					
						
							|  |  |  |                                 buttonClass | 
					
						
							|  |  |  |                             ), | 
					
						
							|  |  |  |                             predicate: MoreScreen.MatchesLayoutFunc(theme), | 
					
						
							|  |  |  |                         })) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     const knownLayouts = new FilteredCombine(knownThemeDescriptions, search, { | 
					
						
							|  |  |  |                         innerClasses: themeListStyle, | 
					
						
							|  |  |  |                         onEmpty: MoreScreen.NothingFound(search), | 
					
						
							|  |  |  |                     }) | 
					
						
							| 
									
										
										
										
											2021-10-15 19:58:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     return new Combine([ | 
					
						
							|  |  |  |                         new Title(t.previouslyHiddenTitle), | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                         t.hiddenExplanation.Subs({ | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |                             hidden_discovered: "" + knownThemes.size, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                             total_hidden: "" + hiddenTotal, | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                         }), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                         knownLayouts, | 
					
						
							| 
									
										
										
										
											2021-10-15 19:58:02 +02:00
										 |  |  |                     ]) | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2021-10-15 19:58:02 +02:00
										 |  |  |             ).SetClass("flex flex-col"), | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             undefined, | 
					
						
							|  |  |  |             state.osmConnection.isLoggedIn | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |     private static MatchesLayoutFunc(layout: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         id: string | 
					
						
							|  |  |  |         title: any | 
					
						
							|  |  |  |         shortDescription: any | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  |         keywords?: any[] | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     }): (search: string) => boolean { | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |         return (search: string) => { | 
					
						
							|  |  |  |             search = search.toLocaleLowerCase() | 
					
						
							|  |  |  |             if (layout.id.toLowerCase().indexOf(search) >= 0) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 return true | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             const entitiesToSearch = [ | 
					
						
							|  |  |  |                 layout.shortDescription, | 
					
						
							|  |  |  |                 layout.title, | 
					
						
							|  |  |  |                 ...(layout.keywords ?? []), | 
					
						
							|  |  |  |             ] | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  |             for (const entity of entitiesToSearch) { | 
					
						
							| 
									
										
										
										
											2022-04-30 02:10:57 +02:00
										 |  |  |                 if (entity === undefined) { | 
					
						
							|  |  |  |                     continue | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-04-28 02:04:25 +02:00
										 |  |  |                 const term = entity["*"] ?? entity[Locale.language.data] | 
					
						
							|  |  |  |                 if (term?.toLowerCase()?.indexOf(search) >= 0) { | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |                     return true | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             return false | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private static createOfficialThemesList( | 
					
						
							|  |  |  |         state: { osmConnection: OsmConnection; locationControl?: UIEventSource<Loc> }, | 
					
						
							|  |  |  |         buttonClass: string, | 
					
						
							|  |  |  |         themeListStyle: string, | 
					
						
							|  |  |  |         search: UIEventSource<string> | 
					
						
							|  |  |  |     ): BaseUIElement { | 
					
						
							|  |  |  |         let buttons: { element: BaseUIElement; predicate?: (s: string) => boolean }[] = | 
					
						
							|  |  |  |             MoreScreen.officialThemes.map((layout) => { | 
					
						
							|  |  |  |                 if (layout === undefined) { | 
					
						
							|  |  |  |                     console.trace("Layout is undefined") | 
					
						
							|  |  |  |                     return undefined | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (layout.hideFromOverview) { | 
					
						
							|  |  |  |                     return undefined | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 const button = MoreScreen.createLinkButton(state, layout)?.SetClass(buttonClass) | 
					
						
							|  |  |  |                 if (layout.id === personal.id) { | 
					
						
							|  |  |  |                     const element = new VariableUiElement( | 
					
						
							|  |  |  |                         state.osmConnection.userDetails | 
					
						
							|  |  |  |                             .map((userdetails) => userdetails.csCount) | 
					
						
							|  |  |  |                             .map((csCount) => { | 
					
						
							|  |  |  |                                 if (csCount < Constants.userJourney.personalLayoutUnlock) { | 
					
						
							|  |  |  |                                     return undefined | 
					
						
							|  |  |  |                                 } else { | 
					
						
							|  |  |  |                                     return button | 
					
						
							|  |  |  |                                 } | 
					
						
							|  |  |  |                             }) | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                     return { element } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 return { element: button, predicate: MoreScreen.MatchesLayoutFunc(layout) } | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const professional = MoreScreen.CreateProffessionalSerivesButton() | 
					
						
							| 
									
										
										
										
											2022-01-18 00:09:01 +01:00
										 |  |  |         const customGeneratorLink = MoreScreen.createCustomGeneratorButton(state) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         buttons.splice(0, 0, { element: customGeneratorLink }, { element: professional }) | 
					
						
							| 
									
										
										
										
											2022-04-24 01:32:19 +02:00
										 |  |  |         return new FilteredCombine(buttons, search, { | 
					
						
							|  |  |  |             innerClasses: themeListStyle, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             onEmpty: MoreScreen.NothingFound(search), | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |      * Returns either a link to the issue tracker or a link to the custom generator, depending on the achieved number of changesets | 
					
						
							|  |  |  |      * */ | 
					
						
							|  |  |  |     private static createCustomGeneratorButton(state: { | 
					
						
							|  |  |  |         osmConnection: OsmConnection | 
					
						
							|  |  |  |     }): VariableUiElement { | 
					
						
							|  |  |  |         const tr = Translations.t.general.morescreen | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         return new VariableUiElement( | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             state.osmConnection.userDetails.map((userDetails) => { | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |                 if (userDetails.csCount < Constants.userJourney.themeGeneratorReadOnlyUnlock) { | 
					
						
							| 
									
										
										
										
											2021-06-13 15:04:55 +02:00
										 |  |  |                     return new SubtleButton(null, tr.requestATheme.Clone(), { | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |                         url: "https://github.com/pietervdvn/MapComplete/issues", | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                         newTab: true, | 
					
						
							|  |  |  |                     }) | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-06-13 15:04:55 +02:00
										 |  |  |                 return new SubtleButton(Svg.pencil_ui(), tr.createYourOwnTheme.Clone(), { | 
					
						
							| 
									
										
										
										
											2021-06-18 16:19:07 +02:00
										 |  |  |                     url: "https://pietervdvn.github.io/mc/legacy/070/customGenerator.html", | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     newTab: false, | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |