Skip to content

Commit

Permalink
fix(frontend): scroll error (#112)
Browse files Browse the repository at this point in the history
Co-authored-by: dumbfox <[email protected]>
  • Loading branch information
u1-liquid and yahuli authored Jul 24, 2023
1 parent ff0166f commit b6d9894
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 6 additions & 6 deletions packages/frontend/src/components/MkPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const moreFetching = ref(false);
const more = ref(false);
const preventAppearFetchMore = ref(false);
const preventAppearFetchMoreTimer = ref<number | null>(null);
const isBackTop = ref(false);
const isActive = ref(false);
const empty = computed(() => items.value.size === 0);
const error = ref(false);
const {
Expand Down Expand Up @@ -167,8 +167,8 @@ watch($$(rootEl), () => {
});
});
watch([$$(backed), $$(contentEl)], () => {
if (!backed) {
watch([$$(backed), $$(contentEl)], (n, o) => {
if (!backed && isActive.value) {
if (!contentEl) return;
scrollRemove = (props.pagination.reversed ? onScrollBottom : onScrollTop)(contentEl, executeQueue, TOLERANCE);
Expand Down Expand Up @@ -339,7 +339,7 @@ const appearFetchMoreAhead = async (): Promise<void> => {
fetchMoreAppearTimeout();
};
const isTop = (): boolean => isBackTop.value || (props.pagination.reversed ? isBottomVisible : isTopVisible)(contentEl!, TOLERANCE);
const isTop = (): boolean => isActive.value && (props.pagination.reversed ? isBottomVisible : isTopVisible)(contentEl!, TOLERANCE);
watch(visibility, () => {
if (visibility.value === 'hidden') {
Expand Down Expand Up @@ -431,11 +431,11 @@ const updateItem = (id: MisskeyEntity['id'], replacer: (old: MisskeyEntity) => M
const inited = init();
onActivated(() => {
isBackTop.value = false;
isActive.value = true;
});
onDeactivated(() => {
isBackTop.value = props.pagination.reversed ? window.scrollY >= (rootEl ? rootEl.scrollHeight - window.innerHeight : 0) : window.scrollY === 0;
isActive.value = false;
});
function toBottom() {
Expand Down
11 changes: 4 additions & 7 deletions packages/frontend/src/nirax.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NIRAX --- A lightweight router

import { EventEmitter } from 'eventemitter3';
import { Component, onMounted, shallowRef, ShallowRef } from 'vue';
import { Component, nextTick, onMounted, shallowRef, ShallowRef } from 'vue';
import { safeURIDecode } from '@/scripts/safe-uri-decode';

type RouteDef = {
Expand Down Expand Up @@ -284,12 +284,9 @@ export function useScrollPositionManager(getScrollContainer: () => HTMLElement,

router.addListener('change', ctx => {
const scrollPos = scrollPosStore.get(ctx.key) ?? 0;
scrollContainer.scroll({ top: scrollPos, behavior: 'instant' });
if (scrollPos !== 0) {
window.setTimeout(() => { // ι·η§»η›΄εΎŒγ―γ‚Ώγ‚€γƒŸγƒ³γ‚°γ«γ‚ˆγ£γ¦γ―γ‚³γƒ³γƒγƒΌγƒγƒ³γƒˆγŒεΎ©ε…ƒγ—εˆ‡γ£γ¦γͺγ„ε―θƒ½ζ€§γ‚‚θ€ƒγˆγ‚‰γ‚Œγ‚‹γŸγ‚ε°‘γ—ζ™‚ι–“γ‚’η©Ίγ‘γ¦ε†εΊ¦γ‚Ήγ‚―γƒ­γƒΌγƒ«
scrollContainer.scroll({ top: scrollPos, behavior: 'instant' });
}, 100);
}
nextTick(() => {
scrollContainer.scroll({ top: scrollPos, behavior: 'instant' });
});
});

router.addListener('same', () => {
Expand Down

0 comments on commit b6d9894

Please sign in to comment.