forked from MapComplete/MapComplete
Integrating plantnet-API, add rudimentary UI
This commit is contained in:
parent
89eecdb38a
commit
a8959fc934
4 changed files with 80 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import {Store, UIEventSource} from "../../Logic/UIEventSource";
|
||||
import Wikidata, {WikidataResponse} from "../../Logic/Web/Wikidata";
|
||||
import {Translation, TypedTranslation} from "../i18n/Translation";
|
||||
import {FixedUiElement} from "../Base/FixedUiElement";
|
||||
|
@ -57,7 +57,7 @@ export default class WikidataPreviewBox extends VariableUiElement {
|
|||
}
|
||||
]
|
||||
|
||||
constructor(wikidataId: UIEventSource<string>, options?: {noImages?: boolean}) {
|
||||
constructor(wikidataId: Store<string>, options?: {noImages?: boolean, whileLoading?: BaseUIElement | string, extraItems?: (BaseUIElement | string)[]}) {
|
||||
let inited = false;
|
||||
const wikidata = wikidataId
|
||||
.stabilized(250)
|
||||
|
@ -71,7 +71,7 @@ export default class WikidataPreviewBox extends VariableUiElement {
|
|||
|
||||
super(wikidata.map(maybeWikidata => {
|
||||
if (maybeWikidata === null || !inited) {
|
||||
return undefined;
|
||||
return options?.whileLoading;
|
||||
}
|
||||
|
||||
if (maybeWikidata === undefined) {
|
||||
|
@ -87,7 +87,7 @@ export default class WikidataPreviewBox extends VariableUiElement {
|
|||
|
||||
}
|
||||
|
||||
public static WikidataResponsePreview(wikidata: WikidataResponse, options?: {noImages?: boolean}): BaseUIElement {
|
||||
public static WikidataResponsePreview(wikidata: WikidataResponse, options?: {noImages?: boolean, extraItems?: (BaseUIElement | string)[]}): BaseUIElement {
|
||||
let link = new Link(
|
||||
new Combine([
|
||||
wikidata.id,
|
||||
|
@ -100,7 +100,8 @@ export default class WikidataPreviewBox extends VariableUiElement {
|
|||
[Translation.fromMap(wikidata.labels)?.SetClass("font-bold"),
|
||||
link]).SetClass("flex justify-between"),
|
||||
Translation.fromMap(wikidata.descriptions),
|
||||
WikidataPreviewBox.QuickFacts(wikidata, options)
|
||||
WikidataPreviewBox.QuickFacts(wikidata, options),
|
||||
...(options.extraItems ?? [])
|
||||
]).SetClass("flex flex-col link-underline")
|
||||
|
||||
|
||||
|
@ -108,8 +109,6 @@ export default class WikidataPreviewBox extends VariableUiElement {
|
|||
if (wikidata.claims.get("P18")?.size > 0) {
|
||||
imageUrl = Array.from(wikidata.claims.get("P18"))[0]
|
||||
}
|
||||
|
||||
|
||||
if (imageUrl && !options?.noImages) {
|
||||
imageUrl = WikimediaImageProvider.singleton.PrepUrl(imageUrl).url
|
||||
info = new Combine([new Img(imageUrl).SetStyle("max-width: 5rem; width: unset; height: 4rem").SetClass("rounded-xl mr-2"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue