Browse Source

add focus handling.

main
Gisle Aune 4 years ago
parent
commit
f785cda541
  1. 2
      svelte-ui/src/App.svelte
  2. 30
      svelte-ui/src/components/FocusHandler.svelte

2
svelte-ui/src/App.svelte

@ -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>

30
svelte-ui/src/components/FocusHandler.svelte

@ -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>
Loading…
Cancel
Save