| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import Combine from "../Base/Combine" | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  | import * as welcome_messages from "../../assets/welcome_message.json" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import BaseUIElement from "../BaseUIElement" | 
					
						
							|  |  |  | import { FixedUiElement } from "../Base/FixedUiElement" | 
					
						
							|  |  |  | import MoreScreen from "./MoreScreen" | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  | import * as themeOverview from "../../assets/generated/theme_overview.json" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import Translations from "../i18n/Translations" | 
					
						
							|  |  |  | import Title from "../Base/Title" | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class FeaturedMessage extends Combine { | 
					
						
							|  |  |  |     constructor() { | 
					
						
							|  |  |  |         const now = new Date() | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         let welcome_message = undefined | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |         for (const wm of FeaturedMessage.WelcomeMessages()) { | 
					
						
							|  |  |  |             if (wm.start_date >= now) { | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (wm.end_date <= now) { | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |             if (welcome_message !== undefined) { | 
					
						
							|  |  |  |                 console.warn("Multiple applicable messages today:", welcome_message.featured_theme) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             welcome_message = wm | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         welcome_message = welcome_message ?? undefined | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         super([FeaturedMessage.CreateFeaturedBox(welcome_message)]) | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     public static WelcomeMessages(): { | 
					
						
							|  |  |  |         start_date: Date | 
					
						
							|  |  |  |         end_date: Date | 
					
						
							|  |  |  |         message: string | 
					
						
							|  |  |  |         featured_theme?: string | 
					
						
							|  |  |  |     }[] { | 
					
						
							|  |  |  |         const all_messages: { | 
					
						
							|  |  |  |             start_date: Date | 
					
						
							|  |  |  |             end_date: Date | 
					
						
							|  |  |  |             message: string | 
					
						
							|  |  |  |             featured_theme?: string | 
					
						
							|  |  |  |         }[] = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const themesById = new Map<string, { id: string; title: any; shortDescription: any }>() | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |         for (const theme of themeOverview["default"]) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             themesById.set(theme.id, theme) | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |         for (const i in welcome_messages) { | 
					
						
							|  |  |  |             if (isNaN(Number(i))) { | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             const wm = welcome_messages[i] | 
					
						
							|  |  |  |             if (wm === null) { | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |             if (themesById.get(wm.featured_theme) === undefined) { | 
					
						
							|  |  |  |                 console.log("THEMES BY ID:", themesById) | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |                 console.error("Unkown featured theme for ", wm) | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (!wm.message) { | 
					
						
							|  |  |  |                 console.error("Featured message is missing for", wm) | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             all_messages.push({ | 
					
						
							|  |  |  |                 start_date: new Date(wm.start_date), | 
					
						
							|  |  |  |                 end_date: new Date(wm.end_date), | 
					
						
							|  |  |  |                 message: wm.message, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 featured_theme: wm.featured_theme, | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |             }) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return all_messages | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     public static CreateFeaturedBox(welcome_message: { | 
					
						
							|  |  |  |         message: string | 
					
						
							|  |  |  |         featured_theme?: string | 
					
						
							|  |  |  |     }): BaseUIElement { | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |         const els: BaseUIElement[] = [] | 
					
						
							|  |  |  |         if (welcome_message === undefined) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             return undefined | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         const title = new Title(Translations.t.index.featuredThemeTitle.Clone()) | 
					
						
							|  |  |  |         const msg = new FixedUiElement(welcome_message.message).SetClass("link-underline font-lg") | 
					
						
							|  |  |  |         els.push(new Combine([title, msg]).SetClass("m-4")) | 
					
						
							|  |  |  |         if (welcome_message.featured_theme !== undefined) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             const theme = themeOverview["default"].filter( | 
					
						
							|  |  |  |                 (th) => th.id === welcome_message.featured_theme | 
					
						
							|  |  |  |             )[0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             els.push( | 
					
						
							|  |  |  |                 MoreScreen.createLinkButton({}, theme) | 
					
						
							|  |  |  |                     .SetClass("m-4 self-center md:w-160") | 
					
						
							|  |  |  |                     .SetStyle("height: min-content;") | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return new Combine(els).SetClass( | 
					
						
							|  |  |  |             "border-2 border-grey-400 rounded-xl flex flex-col md:flex-row" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-10-17 03:35:13 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |