Skip to content

Commit

Permalink
refactor: use one query for badge data
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Bedon committed Nov 6, 2024
1 parent 54758ee commit 09edebf
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 18 deletions.
44 changes: 44 additions & 0 deletions src/graphql/query/lenderProfileBadgeData.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
query lenderProfileBadgeData(
$contentType: String!
$contentKey: String
$preview: Boolean
$limit: Int
) {
userAchievementProgress {
id
lendingAchievements {
id
description
milestoneProgress {
earnedAtDate
id
milestoneStatus
progress
target
}
}
tieredLendingAchievements {
id
description
totalProgressToAchievement
matchingLoans {
id
filters
}
tiers {
target
tierStatement
completedDate
learnMoreURL
}
}
}
contentful {
entries(
contentType: $contentType
contentKey: $contentKey
preview: $preview
limit: $limit
)
}
}
33 changes: 15 additions & 18 deletions src/pages/LenderProfile/LenderProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import KvPageContainer from '@kiva/kv-components/vue/KvPageContainer';
import useBadgeData from '#src/composables/useBadgeData';
import userAchievementProgressQuery from '#src/graphql/query/userAchievementProgress.graphql';

Check failure on line 26 in src/pages/LenderProfile/LenderProfile.vue

View workflow job for this annotation

GitHub Actions / build

'userAchievementProgressQuery' is defined but never used
import contentfulEntriesQuery from '#src/graphql/query/contentfulEntries.graphql';

Check failure on line 27 in src/pages/LenderProfile/LenderProfile.vue

View workflow job for this annotation

GitHub Actions / build

'contentfulEntriesQuery' is defined but never used
import lenderProfileBadgeDataQuery from '#src/graphql/query/lenderProfileBadgeData.graphql';
export default {
name: 'LenderProfile',
Expand Down Expand Up @@ -107,15 +108,13 @@ export default {
return Promise.all([
client.query({ query: lenderPublicProfileQuery, variables: { publicId } }),
isBadgeKeyValid(badgeKey) ? [
client.query({ query: userAchievementProgressQuery }),
client.query({
query: contentfulEntriesQuery,
variables: {
contentType: 'challenge',
limit: 200,
}
})] : null,
isBadgeKeyValid(badgeKey) ? client.query({
query: lenderProfileBadgeDataQuery,
variables: {
contentType: 'challenge',
limit: 200,
}
}) : null,
]);
}
},
Expand Down Expand Up @@ -175,21 +174,19 @@ export default {
const badgeId = badgeKey.split('badge_')[1] ?? '';
const badgeLevel = this.$route.query?.badge_level ?? 0;
const achievementResult = this.apollo.readQuery({ query: userAchievementProgressQuery });
const badgeAchievementData = [
...(achievementResult?.userAchievementProgress?.lendingAchievements ?? []),
...(achievementResult?.userAchievementProgress?.tieredLendingAchievements ?? [])
];
const contentfulResult = this.apollo.readQuery({
query: contentfulEntriesQuery,
const result = this.apollo.readQuery({
query: lenderProfileBadgeDataQuery,
variables: {
contentType: 'challenge',
limit: 200,
}
});
const badgeContentfulData = (contentfulResult?.contentful?.entries?.items ?? [])
const badgeAchievementData = [
...(result?.userAchievementProgress?.lendingAchievements ?? []),
...(result?.userAchievementProgress?.tieredLendingAchievements ?? [])
];
const badgeContentfulData = (result?.contentful?.entries?.items ?? [])
.map(entry => getContentfulLevelData(entry));
const badgeData = combineBadgeData(badgeAchievementData, badgeContentfulData);
Expand Down

0 comments on commit 09edebf

Please sign in to comment.