add focus handling.
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-01-04 15:57:37 +01:00
parent da2f71b306
commit f785cda541
2 changed files with 32 additions and 0 deletions
+2
View File
@@ -24,6 +24,7 @@
import GoalForm from "./forms/GoalForm.svelte"; import GoalForm from "./forms/GoalForm.svelte";
import LoginForm from "./forms/LoginForm.svelte"; import LoginForm from "./forms/LoginForm.svelte";
import authStore from "./stores/auth"; import authStore from "./stores/auth";
import FocusHandler from "./components/FocusHandler.svelte";
onMount(() => { onMount(() => {
authStore.check() authStore.check()
@@ -32,6 +33,7 @@
{#if $authStore.checked} {#if $authStore.checked}
{#if $authStore.loggedIn} {#if $authStore.loggedIn}
<FocusHandler />
<Router> <Router>
<Menu /> <Menu />
<main> <main>
@@ -0,0 +1,30 @@
<script lang="ts">
import { onMount } from "svelte";
import goalStore, { fpGoalStore } from "../stores/goal";
import logStore from "../stores/logs";
import projectStore, { fpProjectStore } from "../stores/project";
let lastFocus = new Date();
function handleFocus() {
if (Date.now() - lastFocus.getTime() < 60000) {
return;
}
lastFocus = new Date();
goalStore.markStale();
fpGoalStore.markStale();
projectStore.markStale();
fpProjectStore.markStale();
logStore.markStale();
}
onMount(() => {
window.addEventListener("focus", handleFocus);
return () => {
window.removeEventListener("focus", handleFocus);
}
})
</script>