| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   import Loading from "./Loading.svelte" | 
					
						
							|  |  |  |   import type { OsmServiceState } from "../../Logic/Osm/OsmConnection" | 
					
						
							|  |  |  |   import { Translation } from "../i18n/Translation" | 
					
						
							|  |  |  |   import Translations from "../i18n/Translations" | 
					
						
							|  |  |  |   import Tr from "./Tr.svelte" | 
					
						
							|  |  |  |   import { OsmConnection } from "../../Logic/Osm/OsmConnection" | 
					
						
							|  |  |  |   import { ImmutableStore, UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							| 
									
										
										
										
											2023-12-01 15:23:28 +01:00
										 |  |  |   import Invalid from "../../assets/svg/Invalid.svelte" | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   export let state: { | 
					
						
							|  |  |  |     osmConnection: OsmConnection | 
					
						
							| 
									
										
										
										
											2023-12-07 21:57:20 +01:00
										 |  |  |     featureSwitches?: { featureSwitchEnableLogin?: UIEventSource<boolean> } | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * If set, 'loading' will act as if we are already logged in. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   export let ignoreLoading: boolean = false | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  |   let loadingStatus = state?.osmConnection?.loadingStatus ?? new ImmutableStore("logged-in") | 
					
						
							| 
									
										
										
										
											2023-12-07 21:57:20 +01:00
										 |  |  |   let badge = state?.featureSwitches?.featureSwitchEnableLogin ?? new ImmutableStore(true) | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   const t = Translations.t.general | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   const offlineModes: Partial<Record<OsmServiceState, Translation>> = { | 
					
						
							|  |  |  |     offline: t.loginFailedOfflineMode, | 
					
						
							|  |  |  |     unreachable: t.loginFailedUnreachableMode, | 
					
						
							| 
									
										
										
										
											2023-04-07 02:13:57 +02:00
										 |  |  |     unknown: t.loginFailedUnreachableMode, | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     readonly: t.loginFailedReadonlyMode, | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   const apiState = | 
					
						
							|  |  |  |     state?.osmConnection?.apiIsOnline ?? new ImmutableStore<OsmServiceState>("online") | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | </script> | 
					
						
							| 
									
										
										
										
											2023-10-24 22:01:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | {#if $badge} | 
					
						
							| 
									
										
										
										
											2023-10-17 01:36:22 +02:00
										 |  |  |   {#if !ignoreLoading && $loadingStatus === "loading"} | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     <slot name="loading"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |       <Loading /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     </slot> | 
					
						
							|  |  |  |   {:else if $loadingStatus === "error"} | 
					
						
							| 
									
										
										
										
											2023-06-14 20:44:01 +02:00
										 |  |  |     <div class="alert max-w-64 flex items-center"> | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |       <Invalid class="m-2 h-8 w-8 shrink-0" /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |       <Tr t={offlineModes[$apiState]} /> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   {:else if $loadingStatus === "logged-in"} | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     <slot /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   {:else if $loadingStatus === "not-attempted"} | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     <slot name="not-logged-in" /> | 
					
						
							| 
									
										
										
										
											2023-10-30 13:45:44 +01:00
										 |  |  |   {/if} | 
					
						
							| 
									
										
										
										
											2023-10-24 22:01:10 +02:00
										 |  |  | {/if} |