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

fix(ContentList): handle props change and fix slots default #1668

Merged
merged 1 commit into from
Nov 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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