| 
									
										
										
										
											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-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   export let state: { | 
					
						
							|  |  |  |     osmConnection: OsmConnection | 
					
						
							|  |  |  |     featureSwitches?: { featureSwitchUserbadge?: UIEventSource<boolean> } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											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-06-14 20:39:36 +02:00
										 |  |  |   let loadingStatus = state.osmConnection.loadingStatus | 
					
						
							|  |  |  |   let badge = state.featureSwitches?.featureSwitchUserbadge ?? new ImmutableStore(true) | 
					
						
							|  |  |  |   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, | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const apiState = state.osmConnection.apiIsOnline | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | {#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"> | 
					
						
							|  |  |  |       <img src="./assets/svg/invalid.svg" 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-17 01:36:22 +02:00
										 |  |  |   {/if}  | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | {/if} |