-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: badge in progress content component #5618
Open
christian14b
wants to merge
3
commits into
main
Choose a base branch
from
in-progress-badge-content
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,264 @@ | ||
<template> | ||
<div> | ||
<div | ||
class="tw-pt-1 tw-pb-1.5 tw-flex tw-flex-col md:tw-flex-row tw-items-center tw-justify-left tw-gap-3" | ||
> | ||
<BadgeContainer :status="BADGE_IN_PROGRESS" :shape="getBadgeShape()" class="tw-z-1"> | ||
<img | ||
:src="badgeImage" | ||
alt="Badge" | ||
style="max-height: 133px;" | ||
@load="isBadgeImageLoaded = true" | ||
> | ||
</BadgeContainer> | ||
<div> | ||
<h3>{{ badgeName }}</h3> | ||
<p>{{ subHead }}</p> | ||
</div> | ||
</div> | ||
<KvCarousel | ||
ref="kvCarouselRef" | ||
:key="carouselKey" | ||
class="kv-carousel tw-w-full md:tw-block tw-hidden" | ||
:embla-options="{ | ||
loop: false, | ||
startIndex, | ||
}" | ||
:multiple-slides-visible="true" | ||
slides-to-scroll="visible" | ||
:slide-max-width="singleSlideWidth" | ||
@interact-carousel="onInteractCarousel" | ||
> | ||
<template | ||
v-for="(loanId, index) in augmentedLoanIds" | ||
:key="`badge-in-progress-carousel-${index}-${loanId}`" #[`slide${index}`] | ||
> | ||
<KvClassicLoanCardContainer | ||
:loan-id="loanId" | ||
:show-tags="true" | ||
:use-full-width="true" | ||
:show-view-loan="true" | ||
class="tw-h-full" | ||
/> | ||
</template> | ||
<template v-if="showViewMoreCard" #[`${viewAllLoansSlideIndex}`]> | ||
<div :key="`load-more-card`" class="tw-flex tw-justify-center tw-items-center tw-h-full"> | ||
<KvButton | ||
class="tw-mx-1 tw-mb-3 tw-whitespace-nowrap" | ||
variant="secondary" | ||
@click="onLoadMore" | ||
> | ||
Load more | ||
</KvButton> | ||
</div> | ||
</template> | ||
</KvCarousel> | ||
<div | ||
class="md:tw-hidden tw-grid tw-justify-items-center tw-gap-3 md:tw-gap-y-4 md:tw-py-1.5" | ||
> | ||
<template | ||
v-for="(loanId, index) in augmentedLoanIds" | ||
:key="`badge-in-progress-carousel-${index}-${loanId}`" | ||
> | ||
<KvClassicLoanCardContainer | ||
:loan-id="loanId" | ||
:show-tags="true" | ||
:show-view-loan="true" | ||
class="tw-h-full" | ||
/> | ||
</template> | ||
</div> | ||
<div class="tw-mt-4 tw-flex tw-flex-col md:tw-hidden tw-justify-center tw-w-auto tw-mx-auto"> | ||
<KvButton | ||
class="tw-mx-1 tw-mb-3 tw-whitespace-nowrap" | ||
variant="secondary" | ||
@click="onLoadMore" | ||
> | ||
Load more | ||
</KvButton> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
|
||
import KvClassicLoanCardContainer from '#src/components/LoanCards/KvClassicLoanCardContainer'; | ||
import KvCarousel from '@kiva/kv-components/vue/KvCarousel'; | ||
import KvButton from '@kiva/kv-components/vue/KvButton'; | ||
import { | ||
computed, watch, ref, inject | ||
} from 'vue'; | ||
import useBadgeModal, { | ||
MOBILE_BREAKPOINT, | ||
BADGE_IN_PROGRESS, | ||
} from '#src/composables/useBadgeModal'; | ||
import { useRouter } from 'vue-router'; | ||
import useIsMobile from '#src/composables/useIsMobile'; | ||
import BadgeContainer from './BadgeContainer'; | ||
|
||
const props = defineProps({ | ||
/** | ||
* { | ||
* id: '', | ||
* fields: { | ||
* challengeName: '', | ||
* shareFact: '', | ||
* badgeImage: { | ||
* fields: { | ||
* file: { | ||
* url: '', | ||
* }, | ||
* }, | ||
* }, | ||
* }, | ||
* totalProgressToAchievement, | ||
* tiers: [ | ||
* { | ||
* target: 2, | ||
* completedDate: null, | ||
* }, | ||
* ], | ||
* } | ||
*/ | ||
badge: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
isLoading: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
loanIds: { | ||
type: Array, | ||
default: () => ([]) | ||
}, | ||
loanLimit: { | ||
type: Number, | ||
default: 1 | ||
}, | ||
showViewMoreCard: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}); | ||
|
||
const isLoading = computed(() => props.isLoading ?? false); | ||
const loanIds = computed(() => props.loanIds ?? []); | ||
const loanLimit = computed(() => props.loanLimit ?? 1); | ||
const loanDisplayCount = ref(3); | ||
const loadMoreClicked = ref(false); | ||
const kvCarouselRef = ref(null); | ||
const $kvTrackEvent = inject('$kvTrackEvent'); | ||
const carouselKey = ref('badge-in-progress-carousel'); | ||
const startIndex = ref(0); | ||
const { | ||
getBadgeShape, | ||
getPrefilteredUrl, | ||
} = useBadgeModal(props.badge); | ||
const { isMobile } = useIsMobile(MOBILE_BREAKPOINT); | ||
|
||
const router = useRouter(); | ||
const forceRerender = () => { | ||
carouselKey.value += 1; | ||
startIndex.value = 1; | ||
}; | ||
|
||
watch(loanIds, async ids => { | ||
if (!isLoading.value) { | ||
const defaultInitialCount = 3; | ||
const loansCount = ids.length; | ||
loanDisplayCount.value = loansCount > defaultInitialCount ? defaultInitialCount : loansCount; | ||
loadMoreClicked.value = loansCount === loanDisplayCount.value; | ||
kvCarouselRef.value?.reInitVisible(); | ||
} | ||
}, { immediate: true }); | ||
|
||
const augmentedLoanIds = computed(() => { | ||
if (isLoading.value) { | ||
return [...Array(6).fill(0)]; | ||
} | ||
return [...loanIds.value].splice(0, loanDisplayCount.value); | ||
}); | ||
|
||
const viewAllLoansSlideIndex = computed(() => { | ||
const slideIndex = augmentedLoanIds?.value?.length ?? 0; | ||
return `slide${slideIndex + 1}`; | ||
}); | ||
|
||
const singleSlideWidth = computed(() => { | ||
const viewportWidth = typeof window !== 'undefined' ? window.innerWidth : 1024; | ||
// Handle tiny screens | ||
if (viewportWidth < 414) { | ||
return `${viewportWidth - 80}px`; | ||
} | ||
if (viewportWidth >= 414 && viewportWidth < 768) return '278px'; | ||
if (viewportWidth >= 768 && viewportWidth < 1024) return '328px'; | ||
return '328px'; | ||
}); | ||
|
||
const onInteractCarousel = interaction => { | ||
$kvTrackEvent('carousel', 'click-carousel-horizontal-scroll', interaction); | ||
}; | ||
|
||
const badgeName = computed(() => props.badge?.fields?.challengeName ?? ''); | ||
// TODO: Replace once the work of using the icon of the correct in-progress badge level is complete | ||
const badgeImage = computed(() => props.badge?.fields?.badgeImage?.fields?.file?.url ?? ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need to change once we update to use all badge icons, this needs to be the badge of the current level. I'm creating utils to get the correct tier. Please add a |
||
const badgeLevel = computed(() => props.badge?.fields?.level ?? ''); | ||
const totalProgress = computed(() => props.badge?.totalProgressToAchievement ?? 0); | ||
const tiers = computed(() => props.badge?.tiers ?? []); | ||
|
||
const sortedTiers = computed(() => { | ||
const defaultTiers = [...tiers.value]; | ||
return defaultTiers.sort((a, b) => a.target - b.target); | ||
}); | ||
|
||
const currentTier = computed(() => { | ||
return sortedTiers.value?.find(tier => !tier?.completedDate) ?? null; | ||
}); | ||
|
||
const target = computed(() => { | ||
return currentTier.value?.target ?? 0; | ||
}); | ||
|
||
const subHead = computed(() => `${totalProgress.value} of ${target.value} loans completed`); | ||
|
||
const onLoadMore = () => { | ||
let initialLabelString = 'Scroll to'; | ||
if (isMobile.value) { | ||
initialLabelString = 'Load'; | ||
} | ||
if (!loadMoreClicked.value) { | ||
$kvTrackEvent('portfolio', 'click', `${initialLabelString} more loans`, badgeName.value, badgeLevel.value); | ||
|
||
loanDisplayCount.value = loanLimit.value; | ||
loadMoreClicked.value = true; | ||
return forceRerender(); | ||
} | ||
|
||
$kvTrackEvent( | ||
'portfolio', | ||
'click', | ||
`${initialLabelString} more loans on loan finding page`, | ||
badgeName.value, | ||
badgeLevel.value | ||
); | ||
|
||
router.push(`lend/filter?${getPrefilteredUrl()}`); | ||
}; | ||
|
||
</script> | ||
|
||
<style lang="postcss" scoped> | ||
|
||
.kv-carousel >>> div[aria-label*=screen] { | ||
@apply tw-invisible; | ||
} | ||
|
||
.badge-container { | ||
width: 175px; | ||
|
||
@screen md { | ||
width: 220px; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dashed border is showing up inside the badge icon. It should show around the outside. Is this because of the maxheight override? Also, it would be helpful to add
BadgeModal
stories to cover the 5 different badge use cases, to ensure the badge icon looks correctly for each.Related, this version of the
BadgeModal
requires there to be modal content to be complete compared to the mocks (modal without title, back button, etc.). Is that something you see as a follow-up ticket?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, badge image is old, new one looks good
And yeah, I think the other elements should be handled while integrating this in BadgeModal, I'll create a separate ticket to integrate them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good regarding the follow-up ticket. Please include a link to the mocks and bullets for the specific requirements in the mocks that are still needed.