mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 00:43:49 +01:00
[client] Use defaultStore instead of $store, debounce fetches
This commit is contained in:
parent
9a34c38d0b
commit
248bf22b94
@ -42,6 +42,7 @@ import MkPagination from "@/components/MkPagination.vue";
|
||||
import { i18n } from "@/i18n";
|
||||
import { scroll } from "@/scripts/scroll";
|
||||
import {instance} from "@/instance";
|
||||
import { defaultStore } from "@/store.js";
|
||||
|
||||
const tlEl = ref<HTMLElement>();
|
||||
|
||||
@ -53,20 +54,22 @@ const props = defineProps<{
|
||||
const pagingComponent = ref<InstanceType<typeof MkPagination>>();
|
||||
|
||||
const interval = ref<NodeJS.Timer>();
|
||||
const lastFetchScrollTop = ref(0);
|
||||
|
||||
function scrollTop() {
|
||||
if (!tlEl.value) return;
|
||||
scroll(tlEl.value, { top: 0, behavior: "smooth" });
|
||||
}
|
||||
|
||||
const setTimer = () => {
|
||||
if ($store.state.enableInfiniteScroll && !interval.value) {
|
||||
interval.value = setInterval(() => {
|
||||
const viewport = document.documentElement.clientHeight;
|
||||
const left = document.documentElement.scrollHeight - document.documentElement.scrollTop;
|
||||
if (left <= viewport * 3) pagingComponent.value.prefetchMore();
|
||||
}, 100);
|
||||
}
|
||||
function setTimer() {
|
||||
if (interval.value || !defaultStore.state.enableInfiniteScroll) return;
|
||||
interval.value = setInterval(() => {
|
||||
const viewport = document.documentElement.clientHeight;
|
||||
const left = document.documentElement.scrollHeight - document.documentElement.scrollTop;
|
||||
if (left > viewport * 3 || document.documentElement.scrollTop - lastFetchScrollTop.value < viewport) return;
|
||||
pagingComponent.value.prefetchMore();
|
||||
lastFetchScrollTop.value = document.documentElement.scrollTop;
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function clearTimer() {
|
||||
|
@ -83,6 +83,7 @@ import {
|
||||
import MkButton from "@/components/MkButton.vue";
|
||||
import { i18n } from "@/i18n";
|
||||
import {instance} from "@/instance";
|
||||
import { defaultStore } from "@/store.js";
|
||||
|
||||
export type Paging<
|
||||
E extends keyof misskey.Endpoints = keyof misskey.Endpoints,
|
||||
@ -242,7 +243,7 @@ const refresh = async (): void => {
|
||||
};
|
||||
|
||||
const prefetchMore = async (): Promise<void> => {
|
||||
if (props.disableAutoLoad || !$store.state.enableInfiniteScroll) return;
|
||||
if (props.disableAutoLoad || !defaultStore.state.enableInfiniteScroll) return;
|
||||
await fetchMore();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user