From 57155d872fea3d40d1063a2cb6a28b1daff9f375 Mon Sep 17 00:00:00 2001 From: Yash Kolekar Date: Mon, 5 Aug 2024 13:00:05 +0530 Subject: [PATCH] create a timer to remind user if workout left pending for too long --- src/routes/workouts/manage/workoutRunes.svelte.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/routes/workouts/manage/workoutRunes.svelte.ts b/src/routes/workouts/manage/workoutRunes.svelte.ts index 49c3bc4e..beaa2180 100644 --- a/src/routes/workouts/manage/workoutRunes.svelte.ts +++ b/src/routes/workouts/manage/workoutRunes.svelte.ts @@ -7,6 +7,7 @@ import { } from '$lib/workoutFunctions'; import type { Prisma } from '@prisma/client'; import type { FullWorkoutWithMesoData } from '../[workoutId]/+page.server'; +import { settingsRunes } from '../../settings/settingsRunes.svelte'; type PreviousWorkoutData = { exercises: WorkoutExerciseWithSets[]; @@ -24,6 +25,7 @@ function createWorkoutRunes() { let exerciseHistorySheetOpen = $state(false); let exerciseHistorySheetName: string | undefined = $state(); + let workoutPendingTimer: NodeJS.Timeout; if (globalThis.localStorage) { const savedState = localStorage.getItem('workoutRunes'); @@ -154,6 +156,18 @@ function createWorkoutRunes() { }, set workoutData(value) { workoutData = value; + if (value !== null) { + workoutPendingTimer = setTimeout( + () => { + settingsRunes.addNotification({ + title: 'Workout still pending', + description: 'Forgot to finish it?', + timestamp: Number(new Date()) + }); + }, + 1000 * 60 * 60 * 2 // TODO: customize this. auto infer from user workouts or settings option + ); + } else clearTimeout(workoutPendingTimer); }, get workoutExercises() { return workoutExercises;