From 64bc47e13ef1702a8cfa8ed511b3a78d68113fd3 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Tue, 5 Nov 2024 09:06:04 -0700 Subject: [PATCH] add "+" to numbers if hit limit (>50), fix linting --- src/libs/endorserServer.ts | 15 ++++++---- src/views/HomeView.vue | 39 +++++++++++++------------ src/views/NewActivityView.vue | 24 +++++++++++---- test-playwright/50-record-offer.spec.ts | 2 +- 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index eb5d57e15..f1f362d9b 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -591,6 +591,10 @@ export async function setPlanInCache( planCache.set(handleId, planSummary); } +/** + * + * @returns { data: Array, hitLimit: boolean } + */ export async function getNewOffersToUser( axios: Axios, apiServer: string, @@ -603,10 +607,12 @@ export async function getNewOffersToUser( } const headers = await getHeaders(activeDid); const response = await axios.get(url, { headers }); - const offers = response.data.data; - return offers; + return response.data; } - +/** + * + * @returns { data: Array, hitLimit: boolean } + */ export async function getNewOffersToUserProjects( axios: Axios, apiServer: string, @@ -619,8 +625,7 @@ export async function getNewOffersToUserProjects( } const headers = await getHeaders(activeDid); const response = await axios.get(url, { headers }); - const offers = response.data.data; - return offers; + return response.data; } /** diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 783eb348d..0d656662b 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -210,7 +210,7 @@ class="block text-center text-6xl" data-testId="newDirectOffersActivityNumber" > - {{ numNewOffersToUser }} + {{ numNewOffersToUser }}{{ newOffersToUserHitLimit ? "+" : "" }}

new offer{{ numNewOffersToUser === 1 ? "" : "s" }} to you

@@ -222,7 +222,8 @@ class="block text-center text-6xl" data-testId="newOffersToUserProjectsActivityNumber" > - {{ numNewOffersToUserProjects }} + {{ numNewOffersToUserProjects + }}{{ newOffersToUserProjectsHitLimit ? "+" : "" }}

new offer{{ numNewOffersToUserProjects === 1 ? "" : "s" }} to your @@ -461,6 +462,8 @@ export default class HomeView extends Vue { isRegistered = false; lastAckedOfferToUserJwtId?: string; // the last JWT ID for offer-to-user that they've acknowledged seeing lastAckedOfferToUserProjectsJwtId?: string; // the last JWT ID for offers-to-user's-projects that they've acknowledged seeing + newOffersToUserHitLimit: boolean = false; + newOffersToUserProjectsHitLimit: boolean = false; numNewOffersToUser: number = 0; // number of new offers-to-user numNewOffersToUserProjects: number = 0; // number of new offers-to-user's-projects searchBoxes: Array<{ @@ -529,25 +532,25 @@ export default class HomeView extends Vue { this.updateAllFeed(); if (this.activeDid) { - this.numNewOffersToUser = ( - await getNewOffersToUser( - this.axios, - this.apiServer, - this.activeDid, - this.lastAckedOfferToUserJwtId, - ) - ).length; + const offersToUserData = await getNewOffersToUser( + this.axios, + this.apiServer, + this.activeDid, + this.lastAckedOfferToUserJwtId, + ); + this.numNewOffersToUser = offersToUserData.data.length; + this.newOffersToUserHitLimit = offersToUserData.hitLimit; } if (this.activeDid) { - this.numNewOffersToUserProjects = ( - await getNewOffersToUserProjects( - this.axios, - this.apiServer, - this.activeDid, - this.lastAckedOfferToUserProjectsJwtId, - ) - ).length; + const offersToUserProjects = await getNewOffersToUserProjects( + this.axios, + this.apiServer, + this.activeDid, + this.lastAckedOfferToUserProjectsJwtId, + ); + this.numNewOffersToUserProjects = offersToUserProjects.data.length; + this.newOffersToUserProjectsHitLimit = offersToUserProjects.hitLimit; } // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/src/views/NewActivityView.vue b/src/views/NewActivityView.vue index 614852543..26d089a2d 100644 --- a/src/views/NewActivityView.vue +++ b/src/views/NewActivityView.vue @@ -17,7 +17,10 @@

- {{ newOffersToUser.length }} + {{ newOffersToUser.length + }}{{ newOffersToUserHitLimit ? "+" : "" }} New Offer{{ newOffersToUser.length === 1 ? "" : "s" }} To You @@ -68,9 +71,10 @@
- {{ - newOffersToUserProjects.length - }} + {{ newOffersToUserProjects.length + }}{{ newOffersToUserProjectsHitLimit ? "+" : "" }} New Offer{{ newOffersToUserProjects.length === 1 ? "" : "s" }} To Your Projects = []; + newOffersToUserHitLimit = false; newOffersToUserProjects: Array = []; + newOffersToUserProjectsHitLimit = false; showOffersDetails = false; showOffersToUserProjectsDetails = false; @@ -185,18 +191,24 @@ export default class NewActivityView extends Vue { if (allAccounts.length > 0) { this.allMyDids = allAccounts.map((acc) => acc.did); } - this.newOffersToUser = await getNewOffersToUser( + + const offersToUserData = await getNewOffersToUser( this.axios, this.apiServer, this.activeDid, this.lastAckedOfferToUserJwtId, ); - this.newOffersToUserProjects = await getNewOffersToUserProjects( + this.newOffersToUser = offersToUserData.data; + this.newOffersToUserHitLimit = offersToUserData.hitLimit; + + const offersToUserProjectsData = await getNewOffersToUserProjects( this.axios, this.apiServer, this.activeDid, this.lastAckedOfferToUserProjectsJwtId, ); + this.newOffersToUserProjects = offersToUserProjectsData.data; + this.newOffersToUserProjectsHitLimit = offersToUserProjectsData.hitLimit; // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { diff --git a/test-playwright/50-record-offer.spec.ts b/test-playwright/50-record-offer.spec.ts index f7c1d7d44..e9c21a5a9 100644 --- a/test-playwright/50-record-offer.spec.ts +++ b/test-playwright/50-record-offer.spec.ts @@ -72,7 +72,7 @@ test('Record an offer', async ({ page }) => { // go to the home page and check that the offer is shown as new await page.goto('./'); const offerNumElem = page.getByTestId('newOffersToUserProjectsActivityNumber'); - await expect(offerNumElem).toHaveText('50'); + await expect(offerNumElem).toHaveText('50+'); // click on the number of new offers to go to the list page await offerNumElem.click();