| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | import {VariableUiElement} from "../Base/VariableUIElement"; | 
					
						
							|  |  |  | import Svg from "../../Svg"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							|  |  |  | import {FixedUiElement} from "../Base/FixedUiElement"; | 
					
						
							|  |  |  | import LanguagePicker from "../LanguagePicker"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							|  |  |  | import Link from "../Base/Link"; | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | import Toggle from "../Input/Toggle"; | 
					
						
							|  |  |  | import Img from "../Base/Img"; | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  | import MapState from "../../Logic/State/MapState"; | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | export default class UserBadge extends Toggle { | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |     constructor(state: MapState) { | 
					
						
							| 
									
										
										
										
											2020-11-05 12:28:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         const userDetails = state.osmConnection.userDetails; | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const loginButton = Translations.t.general.loginWithOpenStreetMap | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |             .Clone() | 
					
						
							| 
									
										
										
										
											2021-09-22 19:56:36 +02:00
										 |  |  |             .SetClass("userbadge-login inline-flex justify-center items-center w-full h-full text-lg font-bold min-w-[20em]") | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             .onClick(() => state.osmConnection.AttemptLogin()); | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const logout = | 
					
						
							| 
									
										
										
										
											2020-11-14 02:54:33 +01:00
										 |  |  |             Svg.logout_svg() | 
					
						
							| 
									
										
										
										
											2020-11-05 12:28:02 +01:00
										 |  |  |                 .onClick(() => { | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                     state.osmConnection.LogOut(); | 
					
						
							| 
									
										
										
										
											2020-11-05 12:28:02 +01:00
										 |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-01 17:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |         const userBadge = new VariableUiElement(userDetails.map(user => { | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |             { | 
					
						
							|  |  |  |                 const homeButton = new VariableUiElement( | 
					
						
							|  |  |  |                     userDetails.map((userinfo) => { | 
					
						
							|  |  |  |                         if (userinfo.home) { | 
					
						
							|  |  |  |                             return Svg.home_ui(); | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         return " "; | 
					
						
							|  |  |  |                     }) | 
					
						
							|  |  |  |                 ).onClick(() => { | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                     const home = state.osmConnection.userDetails.data?.home; | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                     if (home === undefined) { | 
					
						
							|  |  |  |                         return; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                     state.leafletMap.data.setView([home.lat, home.lon], 16); | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const linkStyle = "flex items-baseline" | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                 const languagePicker = (LanguagePicker.CreateLanguagePicker(state.layoutToUse.language) ?? new FixedUiElement("")) | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                     .SetStyle("width:min-content;"); | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                 let messageSpan = | 
					
						
							|  |  |  |                     new Link( | 
					
						
							|  |  |  |                         new Combine([Svg.envelope, "" + user.totalMessages]).SetClass(linkStyle), | 
					
						
							| 
									
										
										
										
											2021-06-30 18:48:23 +02:00
										 |  |  |                         `${user.backend}/messages/inbox`, | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                         true | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const csCount = | 
					
						
							|  |  |  |                     new Link( | 
					
						
							|  |  |  |                         new Combine([Svg.star, "" + user.csCount]).SetClass(linkStyle), | 
					
						
							| 
									
										
										
										
											2021-06-30 18:48:23 +02:00
										 |  |  |                         `${user.backend}/user/${user.name}/history`, | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                         true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (user.unreadMessages > 0) { | 
					
						
							|  |  |  |                     messageSpan = new Link( | 
					
						
							|  |  |  |                         new Combine([Svg.envelope, "" + user.unreadMessages]), | 
					
						
							| 
									
										
										
										
											2021-07-08 14:55:21 +02:00
										 |  |  |                         `${user.backend}/messages/inbox`, | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                         true | 
					
						
							|  |  |  |                     ).SetClass("alert") | 
					
						
							| 
									
										
										
										
											2020-07-20 09:57:19 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 let dryrun = new FixedUiElement(""); | 
					
						
							|  |  |  |                 if (user.dryRun) { | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |                     dryrun = new FixedUiElement("TESTING").SetClass("alert font-xs p-0 max-h-4"); | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const settings = | 
					
						
							|  |  |  |                     new Link(Svg.gear_svg(), | 
					
						
							| 
									
										
										
										
											2021-06-30 18:48:23 +02:00
										 |  |  |                         `${user.backend}/user/${encodeURIComponent(user.name)}/account`, | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                         true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const userName = new Link( | 
					
						
							|  |  |  |                     new FixedUiElement(user.name), | 
					
						
							| 
									
										
										
										
											2021-06-30 18:48:23 +02:00
										 |  |  |                     `${user.backend}/user/${user.name}`, | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                     true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const userStats = new Combine([ | 
					
						
							|  |  |  |                     homeButton, | 
					
						
							|  |  |  |                     settings, | 
					
						
							|  |  |  |                     messageSpan, | 
					
						
							|  |  |  |                     csCount, | 
					
						
							|  |  |  |                     languagePicker, | 
					
						
							|  |  |  |                     logout | 
					
						
							|  |  |  |                 ]) | 
					
						
							|  |  |  |                     .SetClass("userstats") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const usertext = new Combine([ | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |                     new Combine([userName, dryrun]).SetClass("flex justify-end w-full"), | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |                     userStats | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |                 ]).SetClass("flex flex-col sm:w-auto sm:pl-2 overflow-hidden w-0") | 
					
						
							|  |  |  |                 const userIcon = | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |                     (user.img === undefined ? Svg.osm_logo_ui() : new Img(user.img)).SetClass("rounded-full opacity-0 m-0 p-0 duration-500 w-16 min-width-16 h16 float-left") | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |                         .onClick(() => { | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |                             if (usertext.HasClass("w-0")) { | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |                                 usertext.RemoveClass("w-0") | 
					
						
							|  |  |  |                                 usertext.SetClass("w-min pl-2") | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |                             } else { | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |                                 usertext.RemoveClass("w-min") | 
					
						
							|  |  |  |                                 usertext.RemoveClass("pl-2") | 
					
						
							|  |  |  |                                 usertext.SetClass("w-0") | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                         }) | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return new Combine([ | 
					
						
							|  |  |  |                     usertext, | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |                     userIcon, | 
					
						
							|  |  |  |                 ]).SetClass("h-16 flex bg-white") | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 09:57:19 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |         })); | 
					
						
							| 
									
										
										
										
											2020-07-20 09:57:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |         userBadge.SetClass("inline-block m-0 w-full").SetStyle("pointer-events: all") | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |         super( | 
					
						
							| 
									
										
										
										
											2021-07-03 20:18:52 +02:00
										 |  |  |             userBadge, | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |             loginButton, | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             state.osmConnection.isLoggedIn | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2020-07-23 16:00:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-04 00:18:08 +02:00
										 |  |  |         this.SetClass("shadow rounded-full h-min overflow-hidden block w-full md:w-max") | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 19:56:36 +02:00
										 |  |  | } |