| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * A screen showing: | 
					
						
							|  |  |  |    * - A link to share the current view | 
					
						
							|  |  |  |    * - Some query parameters that can be enabled/disabled | 
					
						
							|  |  |  |    * - The code to embed MC as IFrame | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   import ThemeViewState from "../../Models/ThemeViewState" | 
					
						
							|  |  |  |   import { QueryParameters } from "../../Logic/Web/QueryParameters" | 
					
						
							|  |  |  |   import Tr from "../Base/Tr.svelte" | 
					
						
							|  |  |  |   import Translations from "../i18n/Translations" | 
					
						
							|  |  |  |   import { Utils } from "../../Utils" | 
					
						
							|  |  |  |   import Svg from "../../Svg" | 
					
						
							|  |  |  |   import ToSvelte from "../Base/ToSvelte.svelte" | 
					
						
							|  |  |  |   import { DocumentDuplicateIcon } from "@rgossiaux/svelte-heroicons/outline" | 
					
						
							| 
									
										
										
										
											2024-01-22 04:08:19 +01:00
										 |  |  |   import Share from "../../assets/svg/Share.svelte" | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   export let state: ThemeViewState | 
					
						
							|  |  |  |   const tr = Translations.t.general.sharescreen | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let url = window.location | 
					
						
							|  |  |  |   let linkToShare: string = undefined | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * In some cases (local deploys, custom themes), we need to set the URL to `/theme.html?layout=xyz` instead of `/xyz?...` | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   let needsThemeRedirect = url.port !== "" || url.hostname.match(/^[0-9]/) || !state.layout.official | 
					
						
							|  |  |  |   let layoutId = state.layout.id | 
					
						
							|  |  |  |   let baseLink = | 
					
						
							|  |  |  |     url.protocol + | 
					
						
							|  |  |  |     "//" + | 
					
						
							|  |  |  |     url.host + | 
					
						
							|  |  |  |     "/" + | 
					
						
							|  |  |  |     (needsThemeRedirect ? "theme.html?layout=" + layoutId + "&" : layoutId + "?") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let showWelcomeMessage = true | 
					
						
							|  |  |  |   let enableLogin = true | 
					
						
							|  |  |  |   $: { | 
					
						
							|  |  |  |     const layout = state.layout | 
					
						
							|  |  |  |     let excluded = Utils.NoNull([ | 
					
						
							|  |  |  |       showWelcomeMessage ? undefined : "fs-welcome-message", | 
					
						
							|  |  |  |       enableLogin ? undefined : "fs-enable-login", | 
					
						
							|  |  |  |     ]) | 
					
						
							|  |  |  |     linkToShare = | 
					
						
							|  |  |  |       baseLink + | 
					
						
							|  |  |  |       QueryParameters.GetParts(new Set(excluded)) | 
					
						
							|  |  |  |         .concat(excluded.map((k) => k + "=" + false)) | 
					
						
							|  |  |  |         .join("&") | 
					
						
							|  |  |  |     if (layout.definitionRaw !== undefined) { | 
					
						
							|  |  |  |       linkToShare += "&userlayout=" + (layout.definedAtUrl ?? layout.id) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |   async function shareCurrentLink() { | 
					
						
							|  |  |  |     await navigator.share({ | 
					
						
							|  |  |  |       title: Translations.W(state.layout.title)?.ConstructElement().textContent ?? "MapComplete", | 
					
						
							|  |  |  |       text: Translations.W(state.layout.description)?.ConstructElement().textContent ?? "", | 
					
						
							|  |  |  |       url: linkToShare, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |   let isCopied = false | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |   async function copyCurrentLink() { | 
					
						
							|  |  |  |     await navigator.clipboard.writeText(linkToShare) | 
					
						
							|  |  |  |     isCopied = true | 
					
						
							|  |  |  |     await Utils.waitFor(5000) | 
					
						
							|  |  |  |     isCopied = false | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <div> | 
					
						
							|  |  |  |   <Tr t={tr.intro} /> | 
					
						
							|  |  |  |   <div class="flex"> | 
					
						
							|  |  |  |     {#if typeof navigator?.share === "function"} | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |       <button class="h-8 w-8 shrink-0 p-1" on:click={shareCurrentLink}> | 
					
						
							| 
									
										
										
										
											2024-02-20 13:33:38 +01:00
										 |  |  |         <Share /> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  |       </button> | 
					
						
							|  |  |  |     {/if} | 
					
						
							|  |  |  |     {#if navigator.clipboard !== undefined} | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |       <button class="no-image-background h-8 w-8 shrink-0 p-1" on:click={copyCurrentLink}> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  |         <DocumentDuplicateIcon /> | 
					
						
							|  |  |  |       </button> | 
					
						
							|  |  |  |     {/if} | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |     <div class="literal-code" on:click={(e) => Utils.selectTextIn(e.target)}> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  |       {linkToShare} | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <div class="flex justify-center"> | 
					
						
							|  |  |  |     {#if isCopied} | 
					
						
							|  |  |  |       <Tr t={tr.copiedToClipboard} cls="thanks m-2" /> | 
					
						
							|  |  |  |     {/if} | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |   <Tr t={tr.embedIntro} /> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |   <div class="link-underline my-1 flex flex-col"> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  |     <label> | 
					
						
							|  |  |  |       <input bind:checked={showWelcomeMessage} type="checkbox" /> | 
					
						
							|  |  |  |       <Tr t={tr.fsWelcomeMessage} /> | 
					
						
							|  |  |  |     </label> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <label> | 
					
						
							|  |  |  |       <input bind:checked={enableLogin} type="checkbox" /> | 
					
						
							|  |  |  |       <Tr t={tr.fsUserbadge} /> | 
					
						
							|  |  |  |     </label> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <div class="literal-code m-1"> | 
					
						
							|  |  |  |     <span class="literal-code iframe-code-block"> <br /> | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |     <iframe src="${url}" | 
					
						
							|  |  |  |     <br /> | 
					
						
							|  |  |  |     allow="geolocation" width="100%" height="100%" style="min-width: 250px; min-height: 250px" | 
					
						
							|  |  |  |     <br /> | 
					
						
							|  |  |  |     title="${state.layout.title?.txt ?? "MapComplete"} with MapComplete"> | 
					
						
							|  |  |  |     <br /> | 
					
						
							|  |  |  |     </iframe> | 
					
						
							|  |  |  |     <br /> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  |     </span> | 
					
						
							|  |  |  |   </div> | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |   <Tr t={tr.documentation} cls="link-underline" /> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | </div> |