Browse Source

tests to get more data from the net

boyska 6 months ago
parent
commit
949432ccca
2 changed files with 34 additions and 42 deletions
  1. 31 39
      src/js/radiomanifest.js
  2. 3 3
      src/pages/home.vue

+ 31 - 39
src/js/radiomanifest.js

@@ -1,47 +1,39 @@
 import radiomanifest from "@radiomanifest/radiomanifest";
 
-const cachedRadiomanifest = {};
-
-const RM = {
-  radio: {
-    ROR: {
-      name: "Radio Onda Rossa",
-      description: "un segnale che disturba",
-      url: "https://www.ondarossa.info",
-    },
-    Spore: {
-      name: "Radio Spore",
-      description: "una voce senza padrone",
-      url: "https://radiospore.oziosi.org",
-    },
-    Wombat: { name: "Radio Wombat", url: "https://radiowombat.net" },
-    Gramma: {
-      name: "Radio Gramma",
-      description: "supporto parziale!",
-      url: "https://test.radiogramma.org",
+const knownRadios = {
+    "https://www.ondarossa.info": {
+      "name": "ror"
     },
-    RBO: {
-      name: "Radio Blackout",
-      url: "https://radioblackout.org",
-    },
-  },
-
-  currentRadio: null,
+    "https://radiospore.oziosi.org": {},
+    // "https://radiowombat.net": {},
+    // "https://test.radiogramma.org": {},
+    "https://radioblackout.org": {},
+  }
+class Controller {
+  constructor() {
+    this.cache = {}
+    this.currentRadio = null
 
-  async get(id) {
-    // check if this radio id exists
-    if (!RM.radio[id]) {
-      throw new Error("This radio id does not exists!");
+    for(let r in knownRadios) {
+      this.get(r);
     }
+  }
 
-    // check if is cached, load it otherwise
-    if (!cachedRadiomanifest[id]) {
-      const radio = RM.radio[id];
-      cachedRadiomanifest[id] = await radiomanifest.get(radio.url);
+  async get(url) {
+    if(this.cache[url]) {
+      this.currentRadio = this.cache[url];
+      return this.cache[url];
     }
-    this.currentRadio = cachedRadiomanifest[id];
-    return cachedRadiomanifest[id];
-  },
-};
+    this.cache[url] = knownRadios[url];
+    // fetch more data in background
+    radiomanifest.get(url).then((rm) => {
+      console.log("arrivato", url)
+      this.cache[url] = rm
+    })
+  }
+}
+
+const ControllerSingleton = new Controller();
+// console.log(ControllerSingleton);
 
-export default RM;
+export default ControllerSingleton;

+ 3 - 3
src/pages/home.vue

@@ -7,9 +7,9 @@ import radiomanifest from "../js/radiomanifest";
     <f7-block-title>Radio</f7-block-title>
     <f7-list>
       <f7-list-item
-        v-for="(radio, id) in radiomanifest.radio"
-        :key="id"
-        :link="`/radio/${id}`"
+        v-for="(radio, url) in radiomanifest.cache"
+        :key="radio.ts"
+        :link="`/radio/${url}`"
         :title="radio.name"
       />
     </f7-list>