Skip to content

Commit d95c662

Browse files
committed
TMP: feat: add "Load more" button to paginator for better well-being
1 parent 78fd25a commit d95c662

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

app/components/common/CommonPaginator.vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ defineSlots<{
4545
const { t } = useI18n()
4646
const nuxtApp = useNuxtApp()
4747
48-
const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, toRef(() => stream), eventType, preprocess)
48+
const {
49+
items,
50+
prevItems,
51+
update,
52+
state,
53+
endAnchor,
54+
error,
55+
canLoadMore,
56+
} = usePaginator(paginator, toRef(() => stream), eventType, preprocess)
4957
5058
nuxtApp.hook('elk-logo:click', () => {
5159
update()
@@ -117,5 +125,18 @@ defineExpose({ createEntry, removeEntry, updateEntry })
117125
<div v-else-if="state === 'error'" p5 text-secondary>
118126
{{ t('common.error') }}: {{ error }}
119127
</div>
128+
<!-- TODO: debug -->
129+
<div flex="~ center col">
130+
<button
131+
flex btn-solid mt-1
132+
:title="$t('settings.notifications.push_notifications.warning.enable_close')"
133+
@click="canLoadMore = true"
134+
>
135+
Load more
136+
</button>
137+
<p m-y-4>
138+
debug: canLoadMore="{{ canLoadMore }}" / state="{{ state }}"
139+
</p>
140+
</div>
120141
</div>
121142
</template>

app/composables/paginator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function usePaginator<T, P, U = T>(
1818
const items = ref<U[]>([])
1919
const nextItems = ref<U[]>([])
2020
const prevItems = ref<T[]>([])
21+
const canLoadMore = ref<boolean>(false)
2122

2223
const endAnchor = ref<HTMLDivElement>()
2324
const bound = useElementBounding(endAnchor)
@@ -70,7 +71,7 @@ export function usePaginator<T, P, U = T>(
7071
}, { immediate: true })
7172

7273
async function loadNext() {
73-
if (state.value !== 'idle')
74+
if (state.value !== 'idle' || !canLoadMore.value)
7475
return
7576

7677
state.value = 'loading'
@@ -99,6 +100,7 @@ export function usePaginator<T, P, U = T>(
99100
error.value = e
100101
state.value = 'error'
101102
}
103+
canLoadMore.value = false
102104

103105
await nextTick()
104106
bound.update()
@@ -123,6 +125,7 @@ export function usePaginator<T, P, U = T>(
123125
&& state.value === 'idle'
124126
// No new content is loaded when the keepAlive page enters the background
125127
&& deactivated.value === false
128+
&& canLoadMore.value
126129
) {
127130
loadNext()
128131
}
@@ -137,5 +140,6 @@ export function usePaginator<T, P, U = T>(
137140
state,
138141
error,
139142
endAnchor,
143+
canLoadMore,
140144
}
141145
}

0 commit comments

Comments
 (0)