| 
									
										
										
										
											2021-10-08 04:33:39 +02:00
										 |  |  | import BaseUIElement from "../BaseUIElement" | 
					
						
							|  |  |  | import Locale from "../i18n/Locale" | 
					
						
							|  |  |  | import { VariableUiElement } from "../Base/VariableUIElement" | 
					
						
							|  |  |  | import { Translation } from "../i18n/Translation" | 
					
						
							|  |  |  | import Svg from "../../Svg" | 
					
						
							|  |  |  | import Combine from "../Base/Combine" | 
					
						
							|  |  |  | import Title from "../Base/Title" | 
					
						
							|  |  |  | import Wikipedia from "../../Logic/Web/Wikipedia" | 
					
						
							|  |  |  | import Wikidata, { WikidataResponse } from "../../Logic/Web/Wikidata" | 
					
						
							|  |  |  | import { TabbedComponent } from "../Base/TabbedComponent" | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  | import { Store, UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							| 
									
										
										
										
											2021-10-08 04:33:39 +02:00
										 |  |  | import Loading from "../Base/Loading" | 
					
						
							|  |  |  | import { FixedUiElement } from "../Base/FixedUiElement" | 
					
						
							|  |  |  | import Translations from "../i18n/Translations" | 
					
						
							|  |  |  | import Link from "../Base/Link" | 
					
						
							|  |  |  | import WikidataPreviewBox from "./WikidataPreviewBox" | 
					
						
							| 
									
										
										
										
											2022-04-30 00:18:47 +02:00
										 |  |  | import { Paragraph } from "../Base/Paragraph" | 
					
						
							| 
									
										
										
										
											2021-10-02 17:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  | export interface WikipediaBoxOptions { | 
					
						
							|  |  |  |     addHeader: boolean | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |     firstParagraphOnly: boolean | 
					
						
							|  |  |  |     noImages: boolean | 
					
						
							|  |  |  |     currentState?: UIEventSource<"loading" | "loaded" | "error"> | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  | export default class WikipediaBox extends Combine { | 
					
						
							|  |  |  |     constructor(wikidataIds: string[], options?: WikipediaBoxOptions) { | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |         const mainContents = [] | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |         options = options ?? { addHeader: false, firstParagraphOnly: true, noImages: false } | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |         const pages = wikidataIds.map((entry) => | 
					
						
							|  |  |  |             WikipediaBox.createLinkedContent(entry.trim(), options) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |         if (wikidataIds.length == 1) { | 
					
						
							|  |  |  |             const page = pages[0] | 
					
						
							|  |  |  |             mainContents.push( | 
					
						
							|  |  |  |                 new Combine([ | 
					
						
							| 
									
										
										
										
											2022-04-30 00:18:47 +02:00
										 |  |  |                     new Combine([ | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |                         options.noImages | 
					
						
							|  |  |  |                             ? undefined | 
					
						
							|  |  |  |                             : Svg.wikipedia_ui() | 
					
						
							|  |  |  |                                   .SetStyle("width: 1.5rem") | 
					
						
							|  |  |  |                                   .SetClass("inline-block mr-3"), | 
					
						
							| 
									
										
										
										
											2022-04-30 00:18:47 +02:00
										 |  |  |                         page.titleElement, | 
					
						
							|  |  |  |                     ]).SetClass("flex"), | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |                     page.linkElement, | 
					
						
							|  |  |  |                 ]).SetClass("flex justify-between align-middle") | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |             mainContents.push(page.contents.SetClass("overflow-auto normal-background rounded-lg")) | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |         } else if (wikidataIds.length > 1) { | 
					
						
							|  |  |  |             const tabbed = new TabbedComponent( | 
					
						
							|  |  |  |                 pages.map((page) => { | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |                     const contents = page.contents | 
					
						
							|  |  |  |                         .SetClass("overflow-auto normal-background rounded-lg block") | 
					
						
							|  |  |  |                         .SetStyle("max-height: inherit; height: inherit; padding-bottom: 3.3rem") | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |                     return { | 
					
						
							|  |  |  |                         header: page.titleElement.SetClass("pl-2 pr-2"), | 
					
						
							|  |  |  |                         content: new Combine([ | 
					
						
							|  |  |  |                             page.linkElement | 
					
						
							|  |  |  |                                 .SetStyle("top: 2rem; right: 2.5rem;") | 
					
						
							|  |  |  |                                 .SetClass( | 
					
						
							|  |  |  |                                     "absolute subtle-background rounded-full p-3 opacity-50 hover:opacity-100 transition-opacity" | 
					
						
							|  |  |  |                                 ), | 
					
						
							|  |  |  |                             contents, | 
					
						
							|  |  |  |                         ]) | 
					
						
							|  |  |  |                             .SetStyle("max-height: inherit; height: inherit") | 
					
						
							|  |  |  |                             .SetClass("relative"), | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 }), | 
					
						
							|  |  |  |                 0, | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |                     leftOfHeader: options.noImages | 
					
						
							|  |  |  |                         ? undefined | 
					
						
							|  |  |  |                         : Svg.wikipedia_svg() | 
					
						
							|  |  |  |                               .SetStyle("width: 1.5rem; align-self: center;") | 
					
						
							|  |  |  |                               .SetClass("mr-4"), | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |                     styleHeader: (header) => | 
					
						
							|  |  |  |                         header.SetClass("subtle-background").SetStyle("height: 3.3rem"), | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             tabbed.SetStyle("height: inherit; max-height: inherit; overflow: hidden") | 
					
						
							|  |  |  |             mainContents.push(tabbed) | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |         super(mainContents) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.SetClass("block rounded-xl subtle-background m-1 p-2 flex flex-col").SetStyle( | 
					
						
							|  |  |  |             "max-height: inherit" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |     private static createLinkedContent( | 
					
						
							|  |  |  |         entry: string, | 
					
						
							|  |  |  |         options: WikipediaBoxOptions | 
					
						
							|  |  |  |     ): { | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |         titleElement: BaseUIElement | 
					
						
							|  |  |  |         contents: BaseUIElement | 
					
						
							|  |  |  |         linkElement: BaseUIElement | 
					
						
							|  |  |  |     } { | 
					
						
							|  |  |  |         if (entry.match("[qQ][0-9]+")) { | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |             return WikipediaBox.createWikidatabox(entry, options) | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |             return WikipediaBox.createWikipediabox(entry, options) | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Given a '<language>:<article-name>'-string, constructs the wikipedia article | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |     private static createWikipediabox( | 
					
						
							|  |  |  |         wikipediaArticle: string, | 
					
						
							|  |  |  |         options: WikipediaBoxOptions | 
					
						
							|  |  |  |     ): { | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |         titleElement: BaseUIElement | 
					
						
							|  |  |  |         contents: BaseUIElement | 
					
						
							|  |  |  |         linkElement: BaseUIElement | 
					
						
							|  |  |  |     } { | 
					
						
							|  |  |  |         const wp = Translations.t.general.wikipedia | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const article = Wikipedia.extractLanguageAndName(wikipediaArticle) | 
					
						
							|  |  |  |         if (article === undefined) { | 
					
						
							|  |  |  |             return { | 
					
						
							|  |  |  |                 titleElement: undefined, | 
					
						
							|  |  |  |                 contents: wp.noWikipediaPage, | 
					
						
							|  |  |  |                 linkElement: undefined, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |         const wikipedia = new Wikipedia({ language: article.language }) | 
					
						
							|  |  |  |         const url = wikipedia.getPageUrl(article.pageName) | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |         const linkElement = new Link( | 
					
						
							|  |  |  |             Svg.pop_out_svg().SetStyle("width: 1.2rem").SetClass("block  "), | 
					
						
							|  |  |  |             url, | 
					
						
							|  |  |  |             true | 
					
						
							|  |  |  |         ).SetClass("flex items-center enable-links") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             titleElement: new Title(article.pageName, 3), | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |             contents: WikipediaBox.createContents(article.pageName, wikipedia, options), | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |             linkElement, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |      * Given a `Q1234`, constructs a wikipedia box (if a wikipedia page is available) or wikidata box as fallback. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |     private static createWikidatabox( | 
					
						
							|  |  |  |         wikidataId: string, | 
					
						
							|  |  |  |         options: WikipediaBoxOptions | 
					
						
							|  |  |  |     ): { | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |         titleElement: BaseUIElement | 
					
						
							|  |  |  |         contents: BaseUIElement | 
					
						
							|  |  |  |         linkElement: BaseUIElement | 
					
						
							|  |  |  |     } { | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |         const wp = Translations.t.general.wikipedia | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |         const wikiLink: Store< | 
					
						
							|  |  |  |             | [string, string, WikidataResponse] | 
					
						
							|  |  |  |             | "loading" | 
					
						
							|  |  |  |             | "failed" | 
					
						
							|  |  |  |             | ["no page", WikidataResponse] | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |         > = Wikidata.LoadWikidataEntry(wikidataId).map( | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |             (maybewikidata) => { | 
					
						
							|  |  |  |                 if (maybewikidata === undefined) { | 
					
						
							|  |  |  |                     return "loading" | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (maybewikidata["error"] !== undefined) { | 
					
						
							|  |  |  |                     return "failed" | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 const wikidata = <WikidataResponse>maybewikidata["success"] | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                 if (wikidata === undefined) { | 
					
						
							| 
									
										
										
										
											2021-10-09 22:40:52 +02:00
										 |  |  |                     return "failed" | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 if (wikidata.wikisites.size === 0) { | 
					
						
							| 
									
										
										
										
											2021-10-07 22:16:11 +02:00
										 |  |  |                     return ["no page", wikidata] | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const preferredLanguage = [ | 
					
						
							|  |  |  |                     Locale.language.data, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     "en", | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |                     Array.from(wikidata.wikisites.keys())[0], | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 ] | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |                 let language | 
					
						
							|  |  |  |                 let pagetitle | 
					
						
							|  |  |  |                 let i = 0 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 do { | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |                     language = preferredLanguage[i] | 
					
						
							|  |  |  |                     pagetitle = wikidata.wikisites.get(language) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     i++ | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |                 } while (pagetitle === undefined) | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                 return [pagetitle, language, wikidata] | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |             [Locale.language] | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const contents = new VariableUiElement( | 
					
						
							|  |  |  |             wikiLink.map((status) => { | 
					
						
							|  |  |  |                 if (status === "loading") { | 
					
						
							|  |  |  |                     return new Loading(wp.loading.Clone()).SetClass("pl-6 pt-2") | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 if (status === "failed") { | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |                     return wp.failed.Clone().SetClass("alert p-4") | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-10-07 22:16:11 +02:00
										 |  |  |                 if (status[0] == "no page") { | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                     const [_, wd] = <[string, WikidataResponse]>status | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |                     options.currentState?.setData("loaded") | 
					
						
							| 
									
										
										
										
											2021-10-07 22:16:11 +02:00
										 |  |  |                     return new Combine([ | 
					
						
							| 
									
										
										
										
											2021-10-08 04:33:39 +02:00
										 |  |  |                         WikidataPreviewBox.WikidataResponsePreview(wd), | 
					
						
							| 
									
										
										
										
											2021-10-07 22:16:11 +02:00
										 |  |  |                         wp.noWikipediaPage.Clone().SetClass("subtle"), | 
					
						
							|  |  |  |                     ]).SetClass("flex flex-col p-4") | 
					
						
							| 
									
										
										
										
											2021-10-03 01:38:57 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                 const [pagetitle, language, wd] = <[string, string, WikidataResponse]>status | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |                 const wikipedia = new Wikipedia({ language }) | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |                 const quickFacts = WikidataPreviewBox.QuickFacts(wd) | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |                 return WikipediaBox.createContents(pagetitle, wikipedia, { | 
					
						
							|  |  |  |                     topBar: quickFacts, | 
					
						
							|  |  |  |                     ...options, | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |         const titleElement = new VariableUiElement( | 
					
						
							|  |  |  |             wikiLink.map((state) => { | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |                 if (typeof state !== "string") { | 
					
						
							| 
									
										
										
										
											2021-10-07 22:16:11 +02:00
										 |  |  |                     const [pagetitle, _] = state | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                     if (pagetitle === "no page") { | 
					
						
							|  |  |  |                         const wd = <WikidataResponse>state[1] | 
					
						
							|  |  |  |                         return new Title(Translation.fromMap(wd.labels), 3) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |                     return new Title(pagetitle, 3) | 
					
						
							| 
									
										
										
										
											2021-10-07 22:16:11 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |                 return new Link( | 
					
						
							|  |  |  |                     new Title(wikidataId, 3), | 
					
						
							|  |  |  |                     "https://www.wikidata.org/wiki/" + wikidataId, | 
					
						
							|  |  |  |                     true | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2022-05-01 20:56:16 +02:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const linkElement = new VariableUiElement( | 
					
						
							|  |  |  |             wikiLink.map((state) => { | 
					
						
							|  |  |  |                 if (typeof state !== "string") { | 
					
						
							|  |  |  |                     const [pagetitle, language] = state | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |                     const popout = options.noImages | 
					
						
							|  |  |  |                         ? "Source" | 
					
						
							|  |  |  |                         : Svg.pop_out_svg().SetStyle("width: 1.2rem").SetClass("block") | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                     if (pagetitle === "no page") { | 
					
						
							|  |  |  |                         const wd = <WikidataResponse>state[1] | 
					
						
							|  |  |  |                         return new Link(popout, "https://www.wikidata.org/wiki/" + wd.id, true) | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     const url = `https://${language}.wikipedia.org/wiki/${pagetitle}` | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |                     return new Link(popout, url, true) | 
					
						
							| 
									
										
										
										
											2021-10-07 22:16:11 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  |                 return undefined | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2021-10-09 22:40:52 +02:00
										 |  |  |         ).SetClass("flex items-center enable-links") | 
					
						
							| 
									
										
										
										
											2021-10-07 22:06:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             contents: contents, | 
					
						
							|  |  |  |             linkElement: linkElement, | 
					
						
							|  |  |  |             titleElement: titleElement, | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |      * Returns the actual content in a scrollable way for the given wikipedia page | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |     private static createContents( | 
					
						
							|  |  |  |         pagename: string, | 
					
						
							|  |  |  |         wikipedia: Wikipedia, | 
					
						
							|  |  |  |         options: { | 
					
						
							|  |  |  |             topBar?: BaseUIElement | 
					
						
							|  |  |  |         } & WikipediaBoxOptions | 
					
						
							|  |  |  |     ): BaseUIElement { | 
					
						
							|  |  |  |         const htmlContent = wikipedia.GetArticle(pagename, options) | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |         const wp = Translations.t.general.wikipedia | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |         const contents: VariableUiElement = new VariableUiElement( | 
					
						
							|  |  |  |             htmlContent.map((htmlContent) => { | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |                 if (htmlContent === undefined) { | 
					
						
							| 
									
										
										
										
											2021-10-02 17:57:54 +02:00
										 |  |  |                     // Still loading
 | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |                     return new Loading(wp.loading.Clone()) | 
					
						
							| 
									
										
										
										
											2021-10-02 17:57:54 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |                 if (htmlContent["success"] !== undefined) { | 
					
						
							| 
									
										
										
										
											2022-04-30 00:18:47 +02:00
										 |  |  |                     let content: BaseUIElement = new FixedUiElement(htmlContent["success"]) | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |                     if (options?.addHeader) { | 
					
						
							| 
									
										
										
										
											2022-04-30 00:18:47 +02:00
										 |  |  |                         content = new Combine([ | 
					
						
							|  |  |  |                             new Paragraph( | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |                                 new Link(wp.fromWikipedia, wikipedia.getPageUrl(pagename), true) | 
					
						
							| 
									
										
										
										
											2022-04-30 00:18:47 +02:00
										 |  |  |                             ), | 
					
						
							|  |  |  |                             new Paragraph(content), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                         ]) | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2022-04-30 00:18:47 +02:00
										 |  |  |                     return content.SetClass("wikipedia-article") | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-04-30 00:18:47 +02:00
										 |  |  |                 if (htmlContent["error"]) { | 
					
						
							|  |  |  |                     console.warn("Loading wikipage failed due to", htmlContent["error"]) | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  |                     return wp.failed.Clone().SetClass("alert p-4") | 
					
						
							| 
									
										
										
										
											2022-04-30 00:18:47 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-02 17:57:54 +02:00
										 |  |  |                 return undefined | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-10-02 22:31:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |         htmlContent.addCallbackAndRunD((c) => { | 
					
						
							|  |  |  |             if (c["success"] !== undefined) { | 
					
						
							|  |  |  |                 options.currentState?.setData("loaded") | 
					
						
							|  |  |  |             } else if (c["error"] !== undefined) { | 
					
						
							|  |  |  |                 options.currentState?.setData("error") | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 options.currentState?.setData("loading") | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 20:40:24 +02:00
										 |  |  |         return new Combine([ | 
					
						
							| 
									
										
										
										
											2022-05-26 13:23:25 +02:00
										 |  |  |             options?.topBar?.SetClass("border-2 border-grey rounded-lg m-1 mb-0"), | 
					
						
							| 
									
										
										
										
											2022-05-27 05:49:21 +02:00
										 |  |  |             contents.SetClass("block pl-6 pt-2"), | 
					
						
							|  |  |  |         ]) | 
					
						
							| 
									
										
										
										
											2021-10-02 17:57:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |