<script lang="ts">
  import { onMount } from "svelte";
  import markStale from "../stores/markStale";
  let lastFocus = Date.now();

  function handleFocus() {
    if ((Date.now() - lastFocus) > 60000) {
      markStale("*");
      lastFocus = Date.now();
    }
  }

  onMount(() => {
    window.addEventListener("focus", handleFocus);

    return () => {
      window.removeEventListener("focus", handleFocus);
    }
  })
</script>