Skip to content

Commit

Permalink
feat(NcReferenceList): Add support for a fallback reference widget
Browse files Browse the repository at this point in the history
Allow to render a fallback widget if no other reference widget loads.

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Jan 23, 2024
1 parent d77877f commit 45ecc91
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/components/NcRichText/NcReferenceList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default {
type: Number,
default: 1,
},
displayFallback: {
type: Boolean,
default: false,
},
},
data() {
return {
Expand All @@ -39,19 +43,36 @@ export default {
},
computed: {
isVisible() {
return this.loading || this.displayedReferences
return this.loading || this.displayedReferences.length !== 0
},
values() {
return this.referenceData
? this.referenceData
: (this.references ? Object.values(this.references) : [])
if (this.referenceData) {
return this.referenceData
}
if (this.displayFallback && !this.loading && !this.references) {
return [this.fallbackReference]
}
return this.references ? Object.values(this.references) : []
},
firstReference() {
return this.values[0] ?? null
},
displayedReferences() {
return this.values.slice(0, this.limit)
},
fallbackReference() {
return {
accessible: true,
openGraphObject: {
id: this.text,
link: this.text,
name: this.text,
},
richObjectType: 'open-graph',
}
},
},
watch: {
text: 'fetch',
Expand All @@ -75,9 +96,11 @@ export default {
this.resolve().then((response) => {
this.references = response.data.ocs.data.references
this.loading = false
this.$emit('loaded')
}).catch((error) => {
console.error('Failed to extract references', error)
this.loading = false
this.$emit('loaded')
})
},
resolve() {
Expand Down

0 comments on commit 45ecc91

Please sign in to comment.