From 8d9e59b2a64dd639847ca5a133e055fd18f638d6 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sun, 2 Apr 2023 16:56:13 +0200 Subject: [PATCH] add postprocess --- components/common/CommonPaginator.vue | 27 ++++++++++------ components/timeline/TimelineHome.vue | 39 ++++++++++++++++++++++- components/timeline/TimelinePaginator.vue | 3 +- composables/timeline.ts | 29 +---------------- nuxt.config.ts | 1 + 5 files changed, 60 insertions(+), 39 deletions(-) diff --git a/components/common/CommonPaginator.vue b/components/common/CommonPaginator.vue index ee51666d..ddc236e7 100644 --- a/components/common/CommonPaginator.vue +++ b/components/common/CommonPaginator.vue @@ -11,6 +11,7 @@ const { virtualScroller = false, eventType = 'update', preprocess, + postprocess = items => items, noEndMessage = false, } = defineProps<{ paginator: Paginator @@ -19,6 +20,7 @@ const { stream?: Promise eventType?: 'notification' | 'update' preprocess?: (items: (U | T)[]) => U[] + postprocess?: (items: U[]) => U[] noEndMessage?: boolean }>() @@ -47,11 +49,18 @@ const nuxtApp = useNuxtApp() const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, $$(stream), eventType, preprocess) +const postProcessedItems = computedWithControl(() => postprocess(items.value as U[]), () => items.value) + nuxtApp.hook('elk-logo:click', () => { update() nuxtApp.$scrollToTop() }) +nuxtApp.hook('elk-timeline-home-filter:change', () => { + postProcessedItems.trigger() + nuxtApp.$scrollToTop() +}) + function createEntry(item: any) { items.value = [...items.value, preprocess?.([item]) ?? item] } @@ -73,11 +82,11 @@ defineExpose({ createEntry, removeEntry, updateEntry })