Skip to content

Commit

Permalink
fix(ContentList): handle props change and fix slots default (#1668)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Nov 10, 2022
1 parent 37e2caf commit 3b5a80e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/runtime/components/ContentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export default defineComponent({
? ({ data, refresh, isPartial }) => slots?.default({ list: data, refresh, isPartial, ...this.$attrs })
: ({ data }) => emptyNode('default', data),
// Empty slot
empty: bindings => slots?.empty ? slots.empty(bindings) : ({ data }) => emptyNode('default', data),
empty: bindings => slots?.empty ? slots.empty(bindings) : emptyNode('default', bindings?.data),
// Not Found slot
'not-found': bindings => slots?.['not-found'] ? slots?.['not-found']?.(bindings) : ({ data }) => emptyNode('not-found', data)
'not-found': bindings => slots?.['not-found'] ? slots?.['not-found']?.(bindings) : emptyNode('not-found', bindings?.data)
}
)
}
Expand Down
6 changes: 4 additions & 2 deletions src/runtime/components/ContentQuery.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { hash } from 'ohash'
import { PropType, toRefs, defineComponent, h, useSlots } from 'vue'
import { PropType, toRefs, defineComponent, h, useSlots, watch } from 'vue'
import type { ParsedContent, QueryBuilder, SortParams } from '../types'
import { computed, useAsyncData, queryContent } from '#imports'
Expand Down Expand Up @@ -143,6 +143,8 @@ export default defineComponent({
}
)
watch(() => props, () => refresh(), { deep: true })
return {
isPartial,
data,
Expand Down Expand Up @@ -194,7 +196,7 @@ export default defineComponent({
if (!data && slots?.['not-found']) { return slots['not-found']({ props, ...this.$attrs }) }
// Empty slots for `one` if type is "markdown" refers to an empty `body.children` key.
if (data?._type === 'markdown' && !data?.body?.children.length) { return slots.empty({ props, ...this.$attrs }) }
if (slots?.empty && data?._type === 'markdown' && !data?.body?.children.length) { return slots.empty({ props, ...this.$attrs }) }
} else if (!data || !data.length) {
// Handle `find()` and `findSurround()`
Expand Down

0 comments on commit 3b5a80e

Please sign in to comment.