Skip to content

Commit

Permalink
Pause updates if scrolled down
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed Dec 27, 2023
1 parent a58dda3 commit 0e75562
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, inject, onBeforeUnmount, onMounted, onUpdated, provide, ref, watch } from 'vue';
import { createFilterWrapper, debounceFilter, useDocumentVisibility, usePreferredDark, useWindowSize } from '@vueuse/core'
import { createFilterWrapper, debounceFilter, useDocumentVisibility, usePreferredDark, useWindowScroll, useWindowSize } from '@vueuse/core'
import { type Config, type Post } from '@/types';
import { loadConfig } from '@/config';
Expand Down Expand Up @@ -32,13 +32,23 @@ onBeforeUnmount(() => {
stopUpdates()
})
// Pause updates while tab/window is hidden
// Pause updates while tab/window is hidden or window is scrolled down
const visibilityState = useDocumentVisibility()
watch(visibilityState, () => {
if (visibilityState.value === "hidden")
const scrollState = useWindowScroll()
const updatePaused = computed(() => {
const ypos = scrollState.y.value;
const hidden = visibilityState.value === "hidden";
return ypos > 256 || hidden
})
watch(updatePaused, () => {
if (updatePaused.value) {
console.debug("Updates paused")
stopUpdates()
else
} else {
console.debug("Updates resumed")
restartUpdates()
}
})
// Fix Masonry layout on updates, config changes or window resize events
Expand Down

0 comments on commit 0e75562

Please sign in to comment.