| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |   import { Translation } from "../i18n/Translation" | 
					
						
							| 
									
										
										
										
											2023-07-15 18:04:30 +02:00
										 |  |  |   import * as personal from "../../../assets/themes/personal/personal.json" | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |   import { ImmutableStore, Store, UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  |   import UserDetails, { OsmConnection } from "../../Logic/Osm/OsmConnection" | 
					
						
							|  |  |  |   import Constants from "../../Models/Constants" | 
					
						
							|  |  |  |   import type { LayoutInformation } from "../../Models/ThemeConfig/LayoutConfig" | 
					
						
							|  |  |  |   import Tr from "../Base/Tr.svelte" | 
					
						
							|  |  |  |   import SubtleLink from "../Base/SubtleLink.svelte" | 
					
						
							| 
									
										
										
										
											2023-07-28 01:02:31 +02:00
										 |  |  |   import Translations from "../i18n/Translations" | 
					
						
							| 
									
										
										
										
											2023-10-17 01:57:21 +02:00
										 |  |  |   import { LocalStorageSource } from "../../Logic/Web/LocalStorageSource" | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |   export let theme: LayoutInformation | 
					
						
							|  |  |  |   export let isCustom: boolean = false | 
					
						
							|  |  |  |   export let userDetails: UIEventSource<UserDetails> | 
					
						
							| 
									
										
										
										
											2023-06-15 05:03:52 +02:00
										 |  |  |   export let state: { layoutToUse?: { id: string }; osmConnection: OsmConnection } | 
					
						
							| 
									
										
										
										
											2023-07-05 23:39:40 +02:00
										 |  |  |   export let selected: boolean = false | 
					
						
							| 
									
										
										
										
											2023-10-30 13:44:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-17 01:57:21 +02:00
										 |  |  |   let unlockedPersonal = LocalStorageSource.GetParsed("unlocked_personal_theme", false) | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-30 13:44:27 +01:00
										 |  |  |   userDetails.addCallbackAndRunD((userDetails) => { | 
					
						
							|  |  |  |     if (!userDetails.loggedIn) { | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (userDetails.csCount > Constants.userJourney.personalLayoutUnlock) { | 
					
						
							|  |  |  |       unlockedPersonal.setData(true) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return true | 
					
						
							| 
									
										
										
										
											2023-10-17 01:57:21 +02:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2023-10-30 13:44:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |   $: title = new Translation( | 
					
						
							|  |  |  |     theme.title, | 
					
						
							|  |  |  |     !isCustom && !theme.mustHaveLanguage ? "themes:" + theme.id + ".title" : undefined | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  |   $: description = new Translation(theme.shortDescription) | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |   // TODO: Improve this function | 
					
						
							|  |  |  |   function createUrl( | 
					
						
							|  |  |  |     layout: { id: string; definition?: string }, | 
					
						
							|  |  |  |     isCustom: boolean, | 
					
						
							|  |  |  |     state?: { layoutToUse?: { id } } | 
					
						
							|  |  |  |   ): Store<string> { | 
					
						
							|  |  |  |     if (layout === undefined) { | 
					
						
							|  |  |  |       return undefined | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (layout.id === undefined) { | 
					
						
							|  |  |  |       console.error("ID is undefined for layout", layout) | 
					
						
							|  |  |  |       return undefined | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |     if (layout.id === state?.layoutToUse?.id) { | 
					
						
							|  |  |  |       return undefined | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |     let path = window.location.pathname | 
					
						
							|  |  |  |     // Path starts with a '/' and contains everything, e.g. '/dir/dir/page.html' | 
					
						
							|  |  |  |     path = path.substr(0, path.lastIndexOf("/")) | 
					
						
							|  |  |  |     // Path will now contain '/dir/dir', or empty string in case of nothing | 
					
						
							|  |  |  |     if (path === "") { | 
					
						
							|  |  |  |       path = "." | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |     let linkPrefix = `${path}/${layout.id.toLowerCase()}.html?` | 
					
						
							|  |  |  |     if ( | 
					
						
							|  |  |  |       location.hostname === "localhost" || | 
					
						
							|  |  |  |       location.hostname === "127.0.0.1" || | 
					
						
							|  |  |  |       location.port === "1234" | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |       // Redirect to 'theme.html?layout=* instead of 'layout.html'. This is probably a debug run, where the routing does not work | 
					
						
							|  |  |  |       linkPrefix = `${path}/theme.html?layout=${layout.id}&` | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-05-11 02:17:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |     if (isCustom) { | 
					
						
							|  |  |  |       linkPrefix = `${path}/theme.html?userlayout=${layout.id}&` | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |     let hash = "" | 
					
						
							|  |  |  |     if (layout.definition !== undefined) { | 
					
						
							|  |  |  |       hash = "#" + btoa(JSON.stringify(layout.definition)) | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |     return new ImmutableStore<string>(`${linkPrefix}${hash}`) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let href = createUrl(theme, isCustom, state) | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-17 01:57:21 +02:00
										 |  |  | {#if theme.id !== personal.id || $unlockedPersonal} | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |   <SubtleLink href={$href} options={{ extraClasses: "w-full" }}> | 
					
						
							| 
									
										
										
										
											2023-11-23 15:47:16 +01:00
										 |  |  |     <img slot="image" src={theme.icon} class="m-1 mr-2 block h-11 w-11 sm:m-2 sm:mr-4" alt="" /> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:44:01 +02:00
										 |  |  |     <span class="flex flex-col overflow-hidden text-ellipsis"> | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |       <Tr t={title} /> | 
					
						
							| 
									
										
										
										
											2023-11-23 15:47:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 23:39:40 +02:00
										 |  |  |       {#if selected} | 
					
						
							| 
									
										
										
										
											2024-02-20 16:58:47 +01:00
										 |  |  |         <span class="thanks hidden-on-mobile" aria-hidden="true"> | 
					
						
							| 
									
										
										
										
											2023-07-06 00:18:54 +02:00
										 |  |  |           <Tr t={Translations.t.general.morescreen.enterToOpen} /> | 
					
						
							| 
									
										
										
										
											2023-07-05 23:39:40 +02:00
										 |  |  |         </span> | 
					
						
							|  |  |  |       {/if} | 
					
						
							| 
									
										
										
										
											2023-06-14 15:07:03 +02:00
										 |  |  |     </span> | 
					
						
							|  |  |  |   </SubtleLink> | 
					
						
							| 
									
										
										
										
											2023-02-03 22:28:11 +01:00
										 |  |  | {/if} |