From e7c162ff499876640f41c9208cae0ee8beebb80f Mon Sep 17 00:00:00 2001
From: Trent Larson <trent@trentlarson.com>
Date: Wed, 1 Jan 2025 13:55:42 -0700
Subject: [PATCH] fix problem switching projects where old link data remained

---
 src/views/ProjectViewView.vue | 94 +++++++++++++++++++----------------
 1 file changed, 52 insertions(+), 42 deletions(-)

diff --git a/src/views/ProjectViewView.vue b/src/views/ProjectViewView.vue
index 787d7fbe8..45a4ab4d9 100644
--- a/src/views/ProjectViewView.vue
+++ b/src/views/ProjectViewView.vue
@@ -657,29 +657,47 @@ export default class ProjectViewView extends Vue {
       );
     }
 
+    this.givesToThis = [];
     this.loadGives();
 
+    this.givesProvidedByThis = [];
     this.loadGivesProvidedBy();
 
+    this.offersToThis = [];
     this.loadOffers();
 
+    this.fulfillersToThis = [];
     this.loadPlanFulfillersTo();
 
-    const fulfilledByUrl =
+    this.fulfilledByThis = null;
+    this.loadPlanFulfilledBy();
+  }
+
+  async loadGives() {
+    const givesUrl =
       this.apiServer +
-      "/api/v2/report/planFulfilledByPlan?planHandleId=" +
-      encodeURIComponent(projectId);
+      "/api/v2/report/givesToPlans?planIds=" +
+      encodeURIComponent(JSON.stringify([this.projectId]));
+    let postfix = "";
+    if (this.givesToThis.length > 0) {
+      postfix =
+        "&beforeId=" + this.givesToThis[this.givesToThis.length - 1].jwtId;
+    }
+    const givesInUrl = givesUrl + postfix;
+
+    const headers = await serverUtil.getHeaders(this.activeDid);
     try {
-      const resp = await this.axios.get(fulfilledByUrl, { headers });
-      if (resp.status === 200) {
-        this.fulfilledByThis = resp.data.data;
+      const resp = await this.axios.get(givesInUrl, { headers });
+      if (resp.status === 200 && resp.data.data) {
+        this.givesToThis = this.givesToThis.concat(resp.data.data);
+        this.givesHitLimit = resp.data.hitLimit;
       } else {
         this.$notify(
           {
             group: "alert",
             type: "danger",
             title: "Error",
-            text: "Failed to retrieve plans fulfilled by this project.",
+            text: "Failed to retrieve more gives to this project.",
           },
           5000,
         );
@@ -691,42 +709,45 @@ export default class ProjectViewView extends Vue {
           group: "alert",
           type: "danger",
           title: "Error",
-          text: "Something went wrong retrieving plans fulfilled by this project.",
+          text: "Something went wrong retrieving more gives to this project.",
         },
         5000,
       );
       console.error(
-        "Error retrieving plans fulfilled by this project:",
+        "Something went wrong retrieving more gives to this project:",
         serverError.message,
       );
     }
   }
 
-  async loadGives() {
-    const givesUrl =
+  async loadGivesProvidedBy() {
+    const providedByUrl =
       this.apiServer +
-      "/api/v2/report/givesToPlans?planIds=" +
-      encodeURIComponent(JSON.stringify([this.projectId]));
+      "/api/v2/report/givesProvidedBy?providerId=" +
+      encodeURIComponent(this.projectId);
     let postfix = "";
-    if (this.givesToThis.length > 0) {
+    if (this.givesProvidedByThis.length > 0) {
       postfix =
-        "&beforeId=" + this.givesToThis[this.givesToThis.length - 1].jwtId;
+        "&beforeId=" +
+        this.givesProvidedByThis[this.givesProvidedByThis.length - 1].jwtId;
     }
-    const givesInUrl = givesUrl + postfix;
+    const providedByFullUrl = providedByUrl + postfix;
 
     const headers = await serverUtil.getHeaders(this.activeDid);
     try {
-      const resp = await this.axios.get(givesInUrl, { headers });
-      if (resp.status === 200 && resp.data.data) {
-        this.givesToThis = this.givesToThis.concat(resp.data.data);
-        this.givesHitLimit = resp.data.hitLimit;
+      const resp = await this.axios.get(providedByFullUrl, { headers });
+      if (resp.status === 200) {
+        this.givesProvidedByThis = this.givesProvidedByThis.concat(
+          resp.data.data,
+        );
+        this.givesProvidedByHitLimit = resp.data.hitLimit;
       } else {
         this.$notify(
           {
             group: "alert",
             type: "danger",
             title: "Error",
-            text: "Failed to retrieve more gives to this project.",
+            text: "Failed to retrieve gives that were provided by this project.",
           },
           5000,
         );
@@ -738,12 +759,12 @@ export default class ProjectViewView extends Vue {
           group: "alert",
           type: "danger",
           title: "Error",
-          text: "Something went wrong retrieving more gives to this project.",
+          text: "Something went wrong retrieving gives that were provided by this project.",
         },
         5000,
       );
       console.error(
-        "Something went wrong retrieving more gives to this project:",
+        "Something went wrong retrieving gives that were provided by this project:",
         serverError.message,
       );
     }
@@ -844,34 +865,23 @@ export default class ProjectViewView extends Vue {
     }
   }
 
-  async loadGivesProvidedBy() {
-    const providedByUrl =
+  async loadPlanFulfilledBy() {
+    const fulfilledByUrl =
       this.apiServer +
-      "/api/v2/report/givesProvidedBy?providerId=" +
+      "/api/v2/report/planFulfilledByPlan?planHandleId=" +
       encodeURIComponent(this.projectId);
-    let postfix = "";
-    if (this.givesProvidedByThis.length > 0) {
-      postfix =
-        "&beforeId=" +
-        this.givesProvidedByThis[this.givesProvidedByThis.length - 1].jwtId;
-    }
-    const providedByFullUrl = providedByUrl + postfix;
-
     const headers = await serverUtil.getHeaders(this.activeDid);
     try {
-      const resp = await this.axios.get(providedByFullUrl, { headers });
+      const resp = await this.axios.get(fulfilledByUrl, { headers });
       if (resp.status === 200) {
-        this.givesProvidedByThis = this.givesProvidedByThis.concat(
-          resp.data.data,
-        );
-        this.givesProvidedByHitLimit = resp.data.hitLimit;
+        this.fulfilledByThis = resp.data.data;
       } else {
         this.$notify(
           {
             group: "alert",
             type: "danger",
             title: "Error",
-            text: "Failed to retrieve gives that were provided by this project.",
+            text: "Failed to retrieve plans fulfilled by this project.",
           },
           5000,
         );
@@ -883,12 +893,12 @@ export default class ProjectViewView extends Vue {
           group: "alert",
           type: "danger",
           title: "Error",
-          text: "Something went wrong retrieving gives that were provided by this project.",
+          text: "Something went wrong retrieving plans fulfilled by this project.",
         },
         5000,
       );
       console.error(
-        "Something went wrong retrieving gives that were provided by this project:",
+        "Error retrieving plans fulfilled by this project:",
         serverError.message,
       );
     }