mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-01 10:23:03 +00:00
??
This commit is contained in:
parent
2bbada3cd4
commit
ba3fa8b431
1 changed files with 47 additions and 20 deletions
|
@ -177,25 +177,27 @@ watch([() => props.pagination.reversed, $$(scrollableElement)], () => {
|
||||||
if (scrollObserver) scrollObserver.disconnect();
|
if (scrollObserver) scrollObserver.disconnect();
|
||||||
|
|
||||||
scrollObserver = new IntersectionObserver(entries => {
|
scrollObserver = new IntersectionObserver(entries => {
|
||||||
|
console.log('scrollObserver', entries[0].isIntersecting);
|
||||||
weakBacked = entries[0].isIntersecting;
|
weakBacked = entries[0].isIntersecting;
|
||||||
}, {
|
}, {
|
||||||
root: scrollableElement,
|
root: scrollableElement,
|
||||||
rootMargin: props.pagination.reversed ? '-100% 0px 100% 0px' : '100% 0px -100% 0px',
|
rootMargin: props.pagination.reversed ? '-100% 0px 100% 0px' : '100% 0px -100% 0px',
|
||||||
threshold: 0.1, // 10%ぐらいになったらqueueを読む
|
threshold: 0.1, // 10%ぐらいになったらqueueを読む
|
||||||
});
|
});
|
||||||
|
console.log('new scrollObserver', scrollObserver);
|
||||||
}, { immediate: true });
|
}, { immediate: true });
|
||||||
|
|
||||||
watch([$$(rootEl), $$(scrollObserver)], () => {
|
watch([$$(rootEl), $$(scrollObserver)], () => {
|
||||||
scrollObserver?.disconnect();
|
scrollObserver?.disconnect();
|
||||||
nextTick(() => {
|
if (rootEl) scrollObserver?.observe(rootEl);
|
||||||
if (rootEl) scrollObserver?.observe(rootEl);
|
console.log('scrollObserver observe', rootEl);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onScrollTop/onScrollBottomで細かく検出する
|
* onScrollTop/onScrollBottomで細かく検出する
|
||||||
*/
|
*/
|
||||||
watch($$(backed), () => {
|
watch($$(backed), () => {
|
||||||
|
console.log('backed changed', backed);
|
||||||
if (!backed) {
|
if (!backed) {
|
||||||
executeQueue();
|
executeQueue();
|
||||||
}
|
}
|
||||||
|
@ -206,13 +208,16 @@ watch([$$(weakBacked), $$(contentEl)], () => {
|
||||||
scrollRemove = null;
|
scrollRemove = null;
|
||||||
|
|
||||||
if (weakBacked || !contentEl) {
|
if (weakBacked || !contentEl) {
|
||||||
|
console.log('weakBacked watcher remove scrollRemove', weakBacked, contentEl);
|
||||||
if (weakBacked) backed = true;
|
if (weakBacked) backed = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('weakBacked watcher add scrollRemove', weakBacked, contentEl);
|
||||||
scrollRemove = (() => {
|
scrollRemove = (() => {
|
||||||
const checkBacked = () => {
|
const checkBacked = () => {
|
||||||
backed = !checkTop();
|
backed = !checkTop();
|
||||||
|
console.log('checkBacked', backed);
|
||||||
};
|
};
|
||||||
|
|
||||||
// とりあえず評価してみる
|
// とりあえず評価してみる
|
||||||
|
@ -235,20 +240,33 @@ function preventDefault(ev: Event) {
|
||||||
* @param fn DOM操作(unshiftItemsなどで)
|
* @param fn DOM操作(unshiftItemsなどで)
|
||||||
*/
|
*/
|
||||||
function adjustScroll(fn: () => void): Promise<void> {
|
function adjustScroll(fn: () => void): Promise<void> {
|
||||||
|
console.log('adjustScroll');
|
||||||
const oldHeight = scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight();
|
const oldHeight = scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight();
|
||||||
const oldScroll = scrollableElement ? scrollableElement.scrollTop : window.scrollY;
|
const oldScroll = scrollableElement ? scrollableElement.scrollTop : window.scrollY;
|
||||||
// スクロールをやめさせる
|
// スクロールをやめさせる
|
||||||
scrollableElementOrHtml.addEventListener('mousewheel', preventDefault, { passive: false });
|
try {
|
||||||
scrollableElementOrHtml.addEventListener('touchmove', preventDefault, { passive: false });
|
// なぜかscrollableElementOrHtmlがundefinedであるというエラーが出る
|
||||||
scroll(scrollableElement, { top: oldScroll, behavior: 'instant' });
|
scrollableElementOrHtml.addEventListener('mousewheel', preventDefault, { passive: false });
|
||||||
|
scrollableElementOrHtml.addEventListener('touchmove', preventDefault, { passive: false });
|
||||||
|
// ついでにtryに入れてみる
|
||||||
|
scroll(scrollableElement, { top: oldScroll, behavior: 'instant' });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err, { scrollableElementOrHtml });
|
||||||
|
}
|
||||||
|
|
||||||
fn();
|
fn();
|
||||||
|
|
||||||
return nextTick(() => {
|
return nextTick(() => {
|
||||||
const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight);
|
try {
|
||||||
scroll(scrollableElement, { top, behavior: 'instant' });
|
const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight);
|
||||||
scrollableElementOrHtml.removeEventListener('mousewheel', preventDefault);
|
scroll(scrollableElement, { top, behavior: 'instant' });
|
||||||
scrollableElementOrHtml.removeEventListener('touchmove', preventDefault);
|
|
||||||
|
// なぜかscrollableElementOrHtmlがundefinedであるというエラーが出る
|
||||||
|
scrollableElementOrHtml.removeEventListener('mousewheel', preventDefault);
|
||||||
|
scrollableElementOrHtml.removeEventListener('touchmove', preventDefault);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err, { scrollableElementOrHtml });
|
||||||
|
}
|
||||||
return nextTick();
|
return nextTick();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -261,6 +279,7 @@ function adjustScroll(fn: () => void): Promise<void> {
|
||||||
* 注意: moreFetchingをtrueにするのでfalseにする必要がある
|
* 注意: moreFetchingをtrueにするのでfalseにする必要がある
|
||||||
*/
|
*/
|
||||||
async function init(): Promise<void> {
|
async function init(): Promise<void> {
|
||||||
|
console.log('init');
|
||||||
items.value = new Map();
|
items.value = new Map();
|
||||||
queue.value = new Map();
|
queue.value = new Map();
|
||||||
fetching.value = true;
|
fetching.value = true;
|
||||||
|
@ -298,6 +317,7 @@ async function init(): Promise<void> {
|
||||||
* reloadでinitが呼ばれた時はreload内でinitの後に呼ばれる
|
* reloadでinitが呼ばれた時はreload内でinitの後に呼ばれる
|
||||||
*/
|
*/
|
||||||
function scrollAfterInit() {
|
function scrollAfterInit() {
|
||||||
|
console.log('scrollAfterInit');
|
||||||
if (props.pagination.reversed) {
|
if (props.pagination.reversed) {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
|
@ -474,6 +494,8 @@ watch(visibility, visibilityChange);
|
||||||
* @param item アイテム
|
* @param item アイテム
|
||||||
*/
|
*/
|
||||||
const prepend = (item: MisskeyEntity): void => {
|
const prepend = (item: MisskeyEntity): void => {
|
||||||
|
console.log('prepend', item, 'queueSize', queueSize.value, 'backed', backed, 'isPausingUpdate', isPausingUpdate, 'active', active.value);
|
||||||
|
|
||||||
if (items.value.size === 0) {
|
if (items.value.size === 0) {
|
||||||
items.value.set(item.id, item);
|
items.value.set(item.id, item);
|
||||||
fetching.value = false;
|
fetching.value = false;
|
||||||
|
@ -517,19 +539,23 @@ function concatItems(oldItems: MisskeyEntity[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function executeQueue() {
|
async function executeQueue() {
|
||||||
|
console.log('executeQueue');
|
||||||
const queueArr = Array.from(queue.value.entries());
|
const queueArr = Array.from(queue.value.entries());
|
||||||
queue.value = new Map(queueArr.slice(props.pagination.limit));
|
queue.value = new Map(queueArr.slice(props.pagination.limit));
|
||||||
isPausingUpdate = true;
|
isPausingUpdate = true;
|
||||||
await adjustScroll(() => {
|
try {
|
||||||
unshiftItems(
|
await adjustScroll(() => {
|
||||||
queueArr.slice(0, props.pagination.limit).map(v => v[1]).reverse(),
|
unshiftItems(
|
||||||
Infinity,
|
queueArr.slice(0, props.pagination.limit).map(v => v[1]).reverse(),
|
||||||
);
|
Infinity,
|
||||||
});
|
);
|
||||||
weakBacked = !checkTop();
|
});
|
||||||
items.value = new Map([...items.value].slice(0, displayLimit.value));
|
weakBacked = !checkTop();
|
||||||
await nextTick();
|
items.value = new Map([...items.value].slice(0, displayLimit.value));
|
||||||
isPausingUpdate = false;
|
await nextTick();
|
||||||
|
} finally {
|
||||||
|
isPausingUpdate = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function prependQueue(newItem: MisskeyEntity) {
|
function prependQueue(newItem: MisskeyEntity) {
|
||||||
|
@ -573,6 +599,7 @@ onBeforeUnmount(() => {
|
||||||
preventAppearFetchMoreTimer.value = null;
|
preventAppearFetchMoreTimer.value = null;
|
||||||
}
|
}
|
||||||
scrollObserver?.disconnect();
|
scrollObserver?.disconnect();
|
||||||
|
if (scrollRemove) scrollRemove();
|
||||||
});
|
});
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
|
|
Loading…
Reference in a new issue