Skip to content
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

fixing link logic in HomepageTeaserBlock #704

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-hairs-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@explorer-1/vue": patch
---

Fixing link logic in HomepageTeaserBlock
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
class="lg:pr-14"
:text="data.paragraph"
/>
<template v-if="data.link && theLink">
<template v-if="data.link || theExternalLink">
<BaseLink
variant="primary"
class="mt-5"
link-class="inline-block"
caret-wrapper-class="py-2"
:href="theLink"
:to="data.link.page ? data.link.page.url : null"
:href="theExternalLink"
:to="data.link.page ? data.link.page.url : undefined"
external-target-blank
>
{{ data.link.text }}
Expand All @@ -60,13 +60,13 @@
v-if="theCard.image"
class="relative h-auto"
>
<template v-if="theCard.link && theLink">
<template v-if="theCard.link || theCardExternalLink">
<BaseLink
variant="none"
link-class="block"
:aria-label="theCard.link.text || 'Learn more'"
:href="theLink"
:to="theCard.link.page ? theCard.link.page.url : null"
:href="theCardExternalLink"
:to="theCard.link.page?.url || undefined"
external-target-blank
>
<HomepageTeaserBlockCardImage :data="theCard" />
Expand All @@ -87,14 +87,14 @@
{{ theCard.description }}
</p>

<template v-if="theCard.link && theLink">
<template v-if="theCard.link || theCardExternalLink">
<BaseLink
variant="primary"
class="mt-3"
link-class="inline-block"
caret-wrapper-class="py-2"
:href="theLink"
:to="theCard.link.page ? theCard.link.page.url : null"
:href="theCardExternalLink"
:to="theCard.link.page ? theCard.link.page.url : undefined"
external-target-blank
>
{{ theCard.link.text }}
Expand Down Expand Up @@ -135,20 +135,23 @@ export default defineComponent({
}
},
computed: {
theCard(): object | null {
if (this.data.card && this.data.card.length > 0) {
return this.data.card[0]
theCard(): object | undefined {
if (this.data?.card && this.data.card.length > 0) {
return this.data?.card[0]
}
return null
return undefined
},
hasCoverImage(): boolean {
if (this.data.coverImage && this.data.coverImage.src) {
return true
}
return false
},
theLink() {
return mixinGetExternalLink(this.data.link) || undefined
theExternalLink() {
return mixinGetExternalLink(this.data?.link) || undefined
},
theCardExternalLink() {
return mixinGetExternalLink(this.theCard?.link) || undefined
},
theSrcSet() {
return this.data.coverImage
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/utils/mixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ export const mixinGetSrcSet = (srcSetObject: Partial<ImageObject>): string => {
}
// Use with RelatedLinkBlock to retrieve the external link to use with an href prop
export const mixinGetExternalLink = (link: RelatedLinkObject): string | undefined => {
if (link.externalLink) {
if (link?.externalLink) {
return link.externalLink
} else if (link.document) {
} else if (link?.document) {
return link.document.url
}
return undefined
Expand Down