Add paragraph and wikipedia options

This commit is contained in:
pietervdvn 2022-04-30 00:18:47 +02:00
parent 8b06ca77f9
commit 73cec987c9
4 changed files with 72 additions and 21 deletions

33
UI/Base/Paragraph.ts Normal file
View file

@ -0,0 +1,33 @@
import BaseUIElement from "../BaseUIElement";
export class Paragraph extends BaseUIElement {
public readonly content: (string | BaseUIElement);
constructor(html: (string | BaseUIElement)) {
super();
this.content = html ?? "";
}
AsMarkdown(): string {
let c:string ;
if(typeof this.content !== "string"){
c = this.content.AsMarkdown()
}else{
c = this.content
}
return "\n\n"+c+"\n\n"
}
protected InnerConstructElement(): HTMLElement {
const e = document.createElement("p")
if(typeof this.content !== "string"){
e.appendChild(this.content.ConstructElement())
}else{
e.innerHTML = this.content
}
return e;
}
}

View file

@ -28,12 +28,12 @@ export default class WikidataPreviewBox extends VariableUiElement {
requires: WikidataPreviewBox.isHuman,
property: "P21",
display: new Map([
['Q6581097', () => Svg.gender_male_ui().SetStyle("width: 1rem; height: auto")],
['Q6581072', () => Svg.gender_female_ui().SetStyle("width: 1rem; height: auto")],
['Q1097630', () => Svg.gender_inter_ui().SetStyle("width: 1rem; height: auto")],
['Q1052281', () => Svg.gender_trans_ui().SetStyle("width: 1rem; height: auto")/*'transwomen'*/],
['Q2449503', () => Svg.gender_trans_ui().SetStyle("width: 1rem; height: auto")/*'transmen'*/],
['Q48270', () => Svg.gender_queer_ui().SetStyle("width: 1rem; height: auto")]
['Q6581097', () => Svg.gender_male_svg().SetStyle("width: 1rem; height: auto")],
['Q6581072', () => Svg.gender_female_svg().SetStyle("width: 1rem; height: auto")],
['Q1097630', () => Svg.gender_inter_svg().SetStyle("width: 1rem; height: auto")],
['Q1052281', () => Svg.gender_trans_svg().SetStyle("width: 1rem; height: auto")/*'transwomen'*/],
['Q2449503', () => Svg.gender_trans_svg().SetStyle("width: 1rem; height: auto")/*'transmen'*/],
['Q48270', () => Svg.gender_queer_svg().SetStyle("width: 1rem; height: auto")]
])
},
{
@ -84,7 +84,7 @@ export default class WikidataPreviewBox extends VariableUiElement {
let link = new Link(
new Combine([
wikidata.id,
Svg.wikidata_ui().SetStyle("width: 2.5rem").SetClass("block")
Svg.wikidata_svg().SetStyle("width: 2.5rem").SetClass("block")
]).SetClass("flex"),
Wikidata.IdToArticle(wikidata.id), true)?.SetClass("must-link")

View file

@ -14,9 +14,14 @@ import {FixedUiElement} from "../Base/FixedUiElement";
import Translations from "../i18n/Translations";
import Link from "../Base/Link";
import WikidataPreviewBox from "./WikidataPreviewBox";
import {Paragraph} from "../Base/Paragraph";
export default class WikipediaBox extends Combine {
public static configuration = {
onlyFirstParagaph: false,
addHeader: false
}
constructor(wikidataIds: string[]) {
@ -27,9 +32,9 @@ export default class WikipediaBox extends Combine {
const page = pages[0]
mainContents.push(
new Combine([
new Combine([Svg.wikipedia_ui()
.SetStyle("width: 1.5rem").SetClass("inline-block mr-3"), page.titleElement])
.SetClass("flex"),
new Combine([
Svg.wikipedia_svg().SetStyle("width: 1.5rem").SetClass("inline-block mr-3"),
page.titleElement]).SetClass("flex"),
page.linkElement
]).SetClass("flex justify-between align-middle"),
)
@ -52,7 +57,7 @@ export default class WikipediaBox extends Combine {
}),
0,
{
leftOfHeader: Svg.wikipedia_ui().SetStyle("width: 1.5rem; align-self: center;").SetClass("mr-4"),
leftOfHeader: Svg.wikipedia_svg().SetStyle("width: 1.5rem; align-self: center;").SetClass("mr-4"),
styleHeader: header => header.SetClass("subtle-background").SetStyle("height: 3.3rem")
}
)
@ -141,7 +146,7 @@ export default class WikipediaBox extends Combine {
return new Title(pagetitle, 3)
}
//return new Title(Translations.t.general.wikipedia.wikipediaboxTitle.Clone(), 2)
return new Title(wikidataId, 3)
return new Link(new Title(wikidataId, 3), "https://www.wikidata.org/wiki/"+wikidataId, true)
}))
@ -150,13 +155,13 @@ export default class WikipediaBox extends Combine {
const [pagetitle, language] = state
if (pagetitle === "no page") {
const wd = <WikidataResponse>state[1]
return new Link(Svg.pop_out_ui().SetStyle("width: 1.2rem").SetClass("block "),
return new Link(Svg.pop_out_svg().SetStyle("width: 1.2rem").SetClass("block "),
"https://www.wikidata.org/wiki/" + wd.id
, true)
}
const url = `https://${language}.wikipedia.org/wiki/${pagetitle}`
return new Link(Svg.pop_out_ui().SetStyle("width: 1.2rem").SetClass("block "), url, true)
return new Link(Svg.pop_out_svg().SetStyle("width: 1.2rem").SetClass("block "), url, true)
}
return undefined
}))
@ -172,15 +177,14 @@ export default class WikipediaBox extends Combine {
/**
* Returns the actual content in a scrollable way
* @param pagename
* @param language
* @private
*/
private static createContents(pagename: string, language: string, wikidata: WikidataResponse): BaseUIElement {
const htmlContent = Wikipedia.GetArticle({
const wpOptions = {
pageName: pagename,
language: language
})
language: language,
firstParagraphOnly: WikipediaBox.configuration.onlyFirstParagaph
}
const htmlContent = Wikipedia.GetArticle(wpOptions)
const wp = Translations.t.general.wikipedia
const quickFacts = WikidataPreviewBox.QuickFacts(wikidata);
const contents: UIEventSource<string | BaseUIElement> = htmlContent.map(htmlContent => {
@ -189,7 +193,20 @@ export default class WikipediaBox extends Combine {
return new Loading(wp.loading.Clone())
}
if (htmlContent["success"] !== undefined) {
return new FixedUiElement(htmlContent["success"]).SetClass("wikipedia-article")
let content: BaseUIElement = new FixedUiElement(htmlContent["success"]);
if(WikipediaBox.configuration.addHeader){
content = new Combine(
[
new Paragraph(
new Link(wp.fromWikipedia, Wikipedia.getPageUrl(wpOptions), true),
),
new Paragraph(
content
)
]
)
}
return content.SetClass("wikipedia-article")
}
if (htmlContent["error"]) {
console.warn("Loading wikipage failed due to", htmlContent["error"])

View file

@ -247,6 +247,7 @@
"createNewWikidata": "Create a new Wikidata item",
"doSearch": "Search above to see results",
"failed": "Loading the Wikipedia entry failed",
"fromWikipedia": "From Wikipedia, the free encyclopedia",
"loading": "Loading Wikipedia...",
"noResults": "Nothing found for <i>{search}</i>",
"noWikipediaPage": "This Wikidata item has no corresponding Wikipedia page yet.",