From 7d0de00685e635ed0367f1ac3d7158aeed46880d Mon Sep 17 00:00:00 2001
From: senza <maximesenzamici@gmail.com>
Date: Thu, 10 Sep 2020 19:00:14 +0200
Subject: [PATCH] bugfix: math script bug when starting off on listing page -
 change launch & add event listener

---
 js/polls-math.js | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/js/polls-math.js b/js/polls-math.js
index 04d0cd9..0daf2d9 100644
--- a/js/polls-math.js
+++ b/js/polls-math.js
@@ -13,7 +13,7 @@
 firstLoad();
 
 function firstLoad(){
-  let elementsLoaded = document.querySelector("solid-display");
+  let elementsLoaded = document.querySelector("solid-poll,solid-display");
   //console.log("elements loaded are",elementsLoaded);
 
   if (!elementsLoaded){
@@ -26,10 +26,14 @@ function firstLoad(){
     const dataSourceURI = elementsLoaded.dataset.src;
     const urlComponents = new URL(dataSourceURI);
     const dataSourceDomain = urlComponents.origin;
-    ////console.log("the data domain is",dataSourceDomain);
+    //console.log("the data domain is",dataSourceDomain);
+    //console.log("elements are there, updating id's");
     
-    ////console.log("elements are there, updating id's");
-    getPollTotalInfo(dataSourceDomain);
+    document.querySelector("div#polls solid-display").addEventListener("populate",()=> {
+      //when populate of a poll
+      //console.log("poll page");
+      getPollTotalInfo(dataSourceDomain);
+    });
     
     document.querySelector("solid-form[name=addPoll]").addEventListener("populate",()=> {
       //console.log("populating add form");
@@ -40,14 +44,14 @@ function firstLoad(){
      Updates on navigate
     */
     document.querySelector("solid-router").addEventListener("navigate",()=> {
-      console.log("navigating");
+      //console.log("navigating");
       getPollTotalInfo(dataSourceDomain);
       updateFormSource();
 
     });
     //refresh display of total votes on a poll 
     document.querySelector("#poll-votes-values").addEventListener("populate",() => {
-      console.log("populating");
+      //console.log("populating");
       refreshTotalVotes();
     });
 
@@ -74,8 +78,8 @@ function firstLoad(){
         else{
           //get the data src node of first sib display & extract the url
           const dataSrc = pageTitle[i].dataset.src;
-          console.log("data src is",dataSrc,"and title page is", pageTitle[i]);
-          console.log(pageTitle[i].dataset.src);
+          //console.log("data src is",dataSrc,"and title page is", pageTitle[i]);
+          //console.log(pageTitle[i].dataset.src);
           //extract current poll ID from the data src
           const pollId = dataSrc.match(/\/([0-9]+)\/$/)[1];
           /*push to function that will take the value of ID 
-- 
GitLab