Browse Source

make the home screen elements load more quickly

kb/add-usage-guide
Trent Larson 7 months ago
parent
commit
606f21faec
  1. 120
      src/views/HomeView.vue

120
src/views/HomeView.vue

@ -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 (this.isFeedFilteredByVisible && containsNonHiddenDid(record)) {
if ( // has a visible DID so it's a keeper
this.isFeedFilteredByVisible && anyMatch = true;
containsNonHiddenDid(record) }
) { if (!anyMatch && this.isFeedFilteredByNearby) {
// has a visible DID so it's a keeper // check if the associated project has a location inside user's search box
anyMatch = true; if (record.fulfillsPlanHandleId) {
} if (plan?.locLat && plan?.locLon) {
if (!anyMatch && this.isFeedFilteredByNearby) { if (this.latLongInAnySearchBox(plan.locLat, plan.locLon)) {
// check if the associated project has a location inside user's search box anyMatch = true;
if (record.fulfillsPlanHandleId) {
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 {
...record, const newRecord: GiveRecordWithContactInfo = {
giver: didInfoForContact( ...record,
giverDid, giver: didInfoForContact(
this.activeDid, giverDid,
contactForDid(giverDid, this.allContacts), this.activeDid,
this.allMyDids, contactForDid(giverDid, this.allContacts),
), this.allMyDids,
image: claim.image, ),
recipientProjectName: plan?.name, image: claim.image,
receiver: didInfoForContact( recipientProjectName: plan?.name as string,
recipientDid, receiver: didInfoForContact(
this.activeDid, recipientDid,
contactForDid(recipientDid, this.allContacts), this.activeDid,
this.allMyDids, contactForDid(recipientDid, this.allContacts),
), this.allMyDids,
}; ),
}); };
const allNewFeedData: GiveRecordWithContactInfo[] = this.feedData.push(newRecord);
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.

Loading…
Cancel
Save