From 01277c952721ed52b0bd259c61f30e2efa106706 Mon Sep 17 00:00:00 2001 From: Bamco Date: Wed, 25 Dec 2024 12:20:24 +0100 Subject: [PATCH] Fix self reflect --- .../self-reflect/self-reflect.component.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/journal/src/app/pages/exercises/self-reflect/self-reflect.component.ts b/apps/journal/src/app/pages/exercises/self-reflect/self-reflect.component.ts index ec1bb80e..023b30d6 100644 --- a/apps/journal/src/app/pages/exercises/self-reflect/self-reflect.component.ts +++ b/apps/journal/src/app/pages/exercises/self-reflect/self-reflect.component.ts @@ -32,7 +32,7 @@ function getEntryStatus(entries: SelfReflectEntry[], settings: SelfReflectSettin if (!settings) return { disabled: true, message: 'No settings found' } const questions = settings.questions.filter(question => question.frequency === frequency) - if (questions.length === 0) return { disabled: true, message: 'No questions activated - change in settings' } + if (questions.length === 0) return { disabled: true, message: 'No questions activated. Change frequency of a question' } if (entries.length === 0) return { disabled: false, message: `Ready for a new entry!` } const today = startOfDay(new Date()) @@ -46,6 +46,17 @@ function getEntryStatus(entries: SelfReflectEntry[], settings: SelfReflectSettin yearly: (date: Date) => getSelfReflectYear(date, 12, 24) } + const timeAgo = differenceInDays(today, lastEntry.createdAt) + const timeMap = { + daily: 1, + weekly: 7, + monthly: 30, + quarterly: 90, + yearly: 365 + } + + if (timeAgo > timeMap[frequency]) return { disabled: false, message: `Ready for a new entry!` } // This should fix that if the bug where getFrequency[frequency](today) !== getFrequency[frequency](lastEntry.createdAt) is both on the same date + if (getFrequency[frequency](today) !== getFrequency[frequency](lastEntry.createdAt)) return { disabled: false, message: `Ready for a new entry!` } const startOfFrequency = { @@ -80,11 +91,8 @@ function getEntryStatus(entries: SelfReflectEntry[], settings: SelfReflectSettin ReactiveFormsModule, RouterModule, HeaderComponent, - SelfReflectEntryComponent, - SelfReflectFrequencyPipe, PageLoadingComponent, SelfReflectReplaceFrequencyPipe, - SelfReflectCustomQuestionModalComponent, SelfReflectFilterEntriesPipe, IonButtons, IonButton,