]> git.ipfire.org Git - thirdparty/google/fonts.git/commitdiff
tags.html: save and load a previous session 9189/head
authorMarc Foley <m.foley.88@gmail.com>
Wed, 12 Mar 2025 09:53:17 +0000 (09:53 +0000)
committerMarc Foley <m.foley.88@gmail.com>
Wed, 12 Mar 2025 09:53:17 +0000 (09:53 +0000)
.ci/tags.html

index 34b4845727b6b98d017968f59d3726959592a3d2..f85336ab3bd75a75baee94f1f30b614f255ecedc 100644 (file)
@@ -20,6 +20,7 @@
             <details>
               <summary>File</summary>
               <ul class="shadow w-36">
+                <li><a @click="lastSession">Last Session</a></li>
                 <li><a @click="saveCSV">Export CSV</a></li>
                 <li><a @click="prCSV">Open PR</a></li>
               </ul>
@@ -338,7 +339,6 @@ function axesCombos(axes) {
       this.loadFonts();
       this.loadCSV();
       this.loadFamilyPangrams();
-
     },
     mounted() {
       const urlParams = new URLSearchParams(window.location.search);
@@ -394,6 +394,15 @@ function axesCombos(axes) {
       }
     },
     methods: {
+      saveSession() {
+        localStorage.setItem("tagData", this.tagsToCSV());
+      },
+      lastSession() {
+        if (localStorage.getItem("tagData")) {
+          this.tags = this.parseCSV(localStorage.getItem("tagData"));
+        }
+        this.history.push("Last session loaded");
+      },
       async getFamilyData() {
         let dat = await fetch("family_data.json").then(response => response.json()).then(data => {
           let results = [];
@@ -460,6 +469,7 @@ function axesCombos(axes) {
       edited(family) {
         this.isEdited = true;
         this.history.push(`* ${family.name},${family.category},${family.Weight}`);
+        this.saveSession();
       },
       parseUnicode(str) {
         let ranges = str.split(",");
@@ -553,6 +563,7 @@ function axesCombos(axes) {
           this.tags.push(newFamily);
           this.history.push(`+ ${newFamily.displayName},${newFamily.category},${newFamily.score}`);
         }
+        this.saveSession();
       },
       copyFamily() {
         this.isEdited = true;
@@ -566,6 +577,7 @@ function axesCombos(axes) {
           this.tags.push(newTag);
           this.history.push(`+ ${newTag.Family},${newTag["Group/Tag"]},${newTag.Weight}`);
         })
+        this.saveSession();
       },
       AddPlaceHolderTags() {
         this.isEdited = true;
@@ -591,6 +603,7 @@ function axesCombos(axes) {
         let tagKey = `${Family.name},${Family.category}`;
         this.seen.delete(tagKey);
         this.history.push(`- ${Family.displayName},${Family.category},${Family.score}`);
+        this.saveSession();
       },
       tagsToCSV() {
         this.RemovePlaceHolderTags();
@@ -652,17 +665,22 @@ function axesCombos(axes) {
             return response.text()
           })
           .then(csvText => {
-            const lines = csvText.split("\r\n")
-            lines.forEach((line) => {
-              if (line === "") {
-                return;
-              }
-              let family = FontTag.fromCsv(line);
-              this.categories.add(family.category);
-              this.tags.push(family);
-            });
+            this.tags = this.parseCSV(csvText);
             csvText = "Family,Group/Tag,Weight\r\n" + csvText;
         })
+      },
+      parseCSV(text) {
+        const lines = text.split("\r\n");
+        let res = [];
+        lines.forEach((line) => {
+          if (line === "") {
+            return;
+          }
+          let family = FontTag.fromCsv(line);
+          this.categories.add(family.category);
+          res.push(family);
+        });
+        return res;
       }
     }
   } // methods