[gnome-maps/wip/mlundblad/wikidata: 3/3] WIP: placeView: Fallback to Wikidata when no Wikipedia article




commit 3c8f617e258a2e09eb29ed7560607c199be11cb2
Author: Marcus Lundblad <ml dfupdate se>
Date:   Tue Oct 4 23:28:26 2022 +0200

    WIP: placeView: Fallback to Wikidata when no Wikipedia article

 src/placeView.js | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/placeView.js b/src/placeView.js
index c8bcdc40..12606eac 100644
--- a/src/placeView.js
+++ b/src/placeView.js
@@ -465,7 +465,8 @@ export class PlaceView extends Gtk.Box {
                            info: Translations.translateReligion(place.religion) });
         }
 
-        if (place.wiki && Wikipedia.isValidWikipedia(place.wiki)) {
+        if (place.wiki && Wikipedia.isValidWikipedia(place.wiki) ||
+            place.wikidata && Wikipedia.isValidWikidata(place.wikidata)) {
             content.push({ type: 'wikipedia', info: '' });
         }
 
@@ -577,7 +578,9 @@ export class PlaceView extends Gtk.Box {
         let content = this._createContent(place);
         this._attachContent(content);
 
-        if (place.wiki && Wikipedia.isValidWikipedia(place.wiki)) {
+        if (place.wikidata) {
+            this._requestWikidata(place.wikidata, place.wiki);
+        } else if (place.wiki && Wikipedia.isValidWikipedia(place.wiki)) {
             this._requestWikipedia(place.wiki);
         }
 
@@ -592,11 +595,19 @@ export class PlaceView extends Gtk.Box {
                                    this._onThumbnailComplete.bind(this));
     }
 
+    _requestWikidata(wikidata, defaultArticle) {
+        Wikipedia.fetchArticleInfoForWikidata(
+            wikidata, defaultArticle, THUMBNAIL_FETCH_SIZE,
+            this._onWikiMetadataComplete.bind(this),
+            this._onThumbnailComplete.bind(this));
+    }
+
     _onThumbnailComplete(thumbnail) {
         this.thumbnail = thumbnail;
     }
 
     _onWikiMetadataComplete(wiki, metadata) {
+        Utils.debug('this: ' + this);
         if (metadata.extract) {
             let text = GLib.markup_escape_text(metadata.extract, -1);
             let link = this._formatWikiLink(wiki);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]