From 169e85dead10b8ac0ca59a7f30e873168d654d5e Mon Sep 17 00:00:00 2001 From: Natty Date: Wed, 28 Feb 2024 02:14:38 +0100 Subject: [PATCH] Fixed note rendering issues and added debouncing for timeline notes --- .../client/src/components/MagNote.vue | 1 - .../client/src/components/MagNoteSub.vue | 35 +++++---- .../src/components/MagNotifications.vue | 4 +- .../client/src/components/MkPagination.vue | 53 +++++++------- .../client/src/components/MkTimeline.vue | 73 +++++++++++++------ 5 files changed, 105 insertions(+), 61 deletions(-) diff --git a/fe_calckey/frontend/client/src/components/MagNote.vue b/fe_calckey/frontend/client/src/components/MagNote.vue index 8047422..d20f7d6 100644 --- a/fe_calckey/frontend/client/src/components/MagNote.vue +++ b/fe_calckey/frontend/client/src/components/MagNote.vue @@ -219,7 +219,6 @@ diff --git a/fe_calckey/frontend/client/src/components/MkPagination.vue b/fe_calckey/frontend/client/src/components/MkPagination.vue index 65b0268..812ee9c 100644 --- a/fe_calckey/frontend/client/src/components/MkPagination.vue +++ b/fe_calckey/frontend/client/src/components/MkPagination.vue @@ -263,42 +263,44 @@ const fetchMore = async (): Promise => { ); }; -const prepend = (item: Item): void => { +const isFresh = (): boolean => { + if (!rootEl.value) return false; + if (props.pagination.reversed) { - if (rootEl.value) { - const container = getScrollContainer(rootEl.value); - if (container == null) { - // TODO? - } else { - const pos = getScrollPosition(rootEl.value); - const viewHeight = container.clientHeight; - const height = container.scrollHeight; - const isBottom = pos + viewHeight > height - 32; - if (isBottom) { - items.value = items.value.slice(-props.displayLimit); - hasMore.value = true; - } - } - } - items.value.push(item); - // TODO - } else { - // 初回表示時はunshiftだけでOK - if (!rootEl.value) { - items.value.unshift(item); - return; + const container = getScrollContainer(rootEl.value); + + if (!container) { + return false; } + const pos = getScrollPosition(rootEl.value); + const viewHeight = container.clientHeight; + const height = container.scrollHeight; + const isBottom = pos + viewHeight > height - 32; + return isBottom; + } else { const isTop = isBackTop.value || (document.body.contains(rootEl.value) && isTopVisible(rootEl.value)); + return isTop; + } +}; - if (isTop) { +const prepend = (item: Item): void => { + if (props.pagination.reversed) { + if (isFresh()) { + items.value = items.value.slice(-props.displayLimit); + hasMore.value = true; + } + + items.value.push(item); + } else { + if (isFresh()) { // Prepend the item items.value = [item, ...items.value].slice(0, props.displayLimit); } else { - if (!queue.value.length) { + if (!queue.value.length && rootEl.value) { onScrollTop(rootEl.value, () => { items.value = [ ...queue.value.reverse(), @@ -370,6 +372,7 @@ defineExpose({ append, removeItem, updateItem, + isFresh, }); diff --git a/fe_calckey/frontend/client/src/components/MkTimeline.vue b/fe_calckey/frontend/client/src/components/MkTimeline.vue index ced25fb..edcea4b 100644 --- a/fe_calckey/frontend/client/src/components/MkTimeline.vue +++ b/fe_calckey/frontend/client/src/components/MkTimeline.vue @@ -18,7 +18,7 @@