make the home screen elements load more quickly

This commit is contained in:
2024-04-19 15:37:10 -06:00
parent 5a9958cb4f
commit 606f21faec

View File

@@ -268,7 +268,6 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import * as R from "ramda";
import { UAParser } from "ua-parser-js"; import { UAParser } from "ua-parser-js";
import { IIdentifier } from "@veramo/core"; import { IIdentifier } from "@veramo/core";
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
@@ -306,8 +305,8 @@ interface GiveRecordWithContactInfo extends GiveSummaryRecord {
displayName: string; displayName: string;
known: boolean; known: boolean;
}; };
image: string; image?: string;
recipientProjectName: string | undefined; recipientProjectName?: string;
receiver: { receiver: {
displayName: string; displayName: string;
known: boolean; known: boolean;
@@ -488,70 +487,63 @@ export default class HomeView extends Vue {
endOfResults = false; endOfResults = false;
// include the descriptions of the giver and receiver // include the descriptions of the giver and receiver
const identity = await this.getIdentity(this.activeDid); const identity = await this.getIdentity(this.activeDid);
const newFeedData: Array<Promise<GiveRecordWithContactInfo>> = for (const record: GiveSummaryRecord of results.data) {
results.data.map(async (record: GiveSummaryRecord) => { // similar code is in endorser-mobile utility.ts
// similar code is in endorser-mobile utility.ts // claim.claim happen for some claims wrapped in a Verifiable Credential
// claim.claim happen for some claims wrapped in a Verifiable Credential // eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any const claim = (record.fullClaim as any).claim || record.fullClaim;
const claim = (record.fullClaim as any).claim || record.fullClaim; // agent.did is for legacy data, before March 2023
// agent.did is for legacy data, before March 2023 const giverDid =
const giverDid = claim.agent?.identifier || (claim.agent as any)?.did; // eslint-disable-line @typescript-eslint/no-explicit-any
claim.agent?.identifier || (claim.agent as any)?.did; // eslint-disable-line @typescript-eslint/no-explicit-any // recipient.did is for legacy data, before March 2023
// recipient.did is for legacy data, before March 2023 const recipientDid =
const recipientDid = claim.recipient?.identifier || (claim.recipient as any)?.did; // eslint-disable-line @typescript-eslint/no-explicit-any
claim.recipient?.identifier || (claim.recipient as any)?.did; // eslint-disable-line @typescript-eslint/no-explicit-any const plan = await getPlanFromCache(
const plan = await getPlanFromCache( record.fulfillsPlanHandleId,
record.fulfillsPlanHandleId, identity,
identity, this.axios,
this.axios, this.apiServer,
this.apiServer, );
);
// check if the record should be filtered out // check if the record should be filtered out
let anyMatch = false; let anyMatch = false;
if ( if (this.isFeedFilteredByVisible && containsNonHiddenDid(record)) {
this.isFeedFilteredByVisible && // has a visible DID so it's a keeper
containsNonHiddenDid(record) anyMatch = true;
) { }
// has a visible DID so it's a keeper if (!anyMatch && this.isFeedFilteredByNearby) {
anyMatch = true; // check if the associated project has a location inside user's search box
} if (record.fulfillsPlanHandleId) {
if (!anyMatch && this.isFeedFilteredByNearby) { if (plan?.locLat && plan?.locLon) {
// check if the associated project has a location inside user's search box if (this.latLongInAnySearchBox(plan.locLat, plan.locLon)) {
if (record.fulfillsPlanHandleId) { anyMatch = true;
if (plan?.locLat && plan?.locLon) {
if (this.latLongInAnySearchBox(plan.locLat, plan.locLon)) {
anyMatch = true;
}
} }
} }
} }
if (this.isAnyFeedFilterOn && !anyMatch) { }
return null; if (this.isAnyFeedFilterOn && !anyMatch) {
} continue;
}
return { const newRecord: GiveRecordWithContactInfo = {
...record, ...record,
giver: didInfoForContact( giver: didInfoForContact(
giverDid, giverDid,
this.activeDid, this.activeDid,
contactForDid(giverDid, this.allContacts), contactForDid(giverDid, this.allContacts),
this.allMyDids, this.allMyDids,
), ),
image: claim.image, image: claim.image,
recipientProjectName: plan?.name, recipientProjectName: plan?.name as string,
receiver: didInfoForContact( receiver: didInfoForContact(
recipientDid, recipientDid,
this.activeDid, this.activeDid,
contactForDid(recipientDid, this.allContacts), contactForDid(recipientDid, this.allContacts),
this.allMyDids, this.allMyDids,
), ),
}; };
}); this.feedData.push(newRecord);
const allNewFeedData: GiveRecordWithContactInfo[] = }
await Promise.all(newFeedData);
const filteredFeedData = allNewFeedData.filter(R.isNotNil);
this.feedData = this.feedData.concat(filteredFeedData);
this.feedPreviousOldestId = this.feedPreviousOldestId =
results.data[results.data.length - 1].jwtId; results.data[results.data.length - 1].jwtId;
// The following update is only done on the first load. // The following update is only done on the first load.