Skip to content

Commit

Permalink
Use setInterval to reduce traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoheiu committed Oct 11, 2023
1 parent fb07197 commit c801e18
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/routes/article/[id]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import Tags from '$lib/Tags.svelte';
import { Action } from '$lib/types';
import { onMount } from 'svelte';
import { onDestroy, onMount } from 'svelte';
import type { PageData } from './$types';
import { House } from 'phosphor-svelte';
import Buttons from '$lib/Buttons.svelte';
Expand All @@ -11,6 +11,7 @@
export let data: PageData;
let progData = data.result?.progress;
let intervalId: NodeJS.Timeout;
const getScrollPosition = () => {
const bodyheight = document.documentElement.scrollHeight;
Expand Down Expand Up @@ -62,8 +63,13 @@
}
};
onMount(async () => {
onMount(() => {
restoreScrollPos();
intervalId = setInterval(saveScrollPos, 1000);
});
onDestroy(() => {
clearInterval(intervalId);
});
</script>

Expand All @@ -74,7 +80,6 @@
<title>leaf</title>
{/if}
</svelte:head>
<svelte:window on:scroll={saveScrollPos} />
{#if data.result}
<div class="z-50 sticky top-0 mb-3 flex h-8 items-center bg-slate-50">
<a href="/"><House size={ICON_SIZE} /></a>
Expand Down

0 comments on commit c801e18

Please sign in to comment.