fix pagination

This commit is contained in:
einhornimmond 2025-02-17 17:53:35 +01:00
parent a3147661c3
commit 84b0d82f98
2 changed files with 9 additions and 28 deletions

View File

@ -31,6 +31,7 @@
:total-rows="result.spaces.total"
:per-page="ITEMS_PER_PAGE"
aria-controls="list-humhub-spaces"
@update:model-value="refetch({ page: $event })"
/>
</div>
</template>
@ -54,8 +55,8 @@ const page = ref(1)
const selectedSpaceId = ref(props.modelValue)
const { result, refetch } = useQuery(
gql`
query spaces($page: Int!) {
spaces(page: $page) {
query spaces($page: Int!, $limit: Int!) {
spaces(page: $page, limit: $limit) {
total
page
pages
@ -78,35 +79,13 @@ watch(
(newValue) => emit('update:modelValue', newValue),
)
watch(
() => props.modelValue,
(newValue) => {
console.log('space id updated, new value:', newValue)
},
)
onMounted(() => {
console.log('on mounted', props.modelValue)
if (props.spaceId) {
const targetPage = Math.ceil(props.spaceId / ITEMS_PER_PAGE)
if (props.modelValue) {
const targetPage = Math.ceil(props.modelValue / ITEMS_PER_PAGE)
page.value = targetPage
refetch({ page: targetPage })
}
})
const prevPage = () => {
if (page.value > 1) {
page.value -= 1
refetch({ page: page.value })
}
}
const nextPage = () => {
if (hasMore.value) {
page.value += 1
refetch({ page: page.value })
}
}
</script>
<style scoped>
.list-group-item-action:hover:not(.active) {
@ -114,4 +93,7 @@ const nextPage = () => {
color: #0056b3;
transition: background-color 0.2s ease-in-out;
}
.list-group-item-action.active > a {
color: white;
}
</style>

View File

@ -111,12 +111,11 @@ const GET_SPACE = gql`
}
}
`
const { result, loading } = useQuery(GET_SPACE, () => ({ id: spaceId.value }), {
const { result } = useQuery(GET_SPACE, () => ({ id: spaceId.value }), {
enabled: computed(() => !!spaceId.value),
})
const selectedSpaceText = computed(() => {
console.log('selectedSpaceText: ', result.value)
if (!spaceId.value) {
return t('projectBranding.selectSpace')
}