Skip to content

Commit

Permalink
create a timer to remind user if workout left pending for too long
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAsh5114 committed Aug 5, 2024
1 parent ef78ecd commit 57155d8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/routes/workouts/manage/workoutRunes.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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');
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 57155d8

Please sign in to comment.