diff --git a/JournalApp/Components/Pages/MoodGrid/MoodGridPage.razor b/JournalApp/Components/Pages/MoodGrid/MoodGridPage.razor index 637bdca..2dfa40c 100644 --- a/JournalApp/Components/Pages/MoodGrid/MoodGridPage.razor +++ b/JournalApp/Components/Pages/MoodGrid/MoodGridPage.razor @@ -150,29 +150,30 @@ _moodCategory ??= await db.Categories.SingleOrDefaultAsync(x => x.Guid == new Guid("D90D89FB-F5B9-47CF-AE4E-3EC0D635E783")); - if (_moodCategory == null) + var moodPoints = new Dictionary(); + if (_moodCategory == null || !_moodCategory.Enabled) { - logger.LogError($"Mood category doesn't exist so we can't load the year."); - return; + logger.LogError("Mood category doesn't exist or is disabled so we won't load any points."); + } + else + { + var query = db.Points + .Where(p => !p.Deleted && p.Day.Date.Year == SelectedYear && p.Day.Date <= tomorrow && p.Category.Guid == _moodCategory.Guid) + .Select( + p => new + { + Date = p.Day.Date, + Point = p, + } + ); + + // Sort into dictionary here instead of during the query so we can handle + // duplicate dates, if that has erroneously happened, without crashing. + foreach (var x in query) + moodPoints[x.Date] = x.Point; + + logger.LogDebug($"Found {moodPoints.Count} mood points"); } - - var query = db.Points - .Where(p => !p.Deleted && p.Day.Date.Year == SelectedYear && p.Day.Date <= tomorrow && p.Category.Guid == _moodCategory.Guid) - .Select( - p => new - { - Date = p.Day.Date, - Point = p, - } - ); - - // Sort into dictionary here instead of during the query so we can handle - // duplicate dates, if that has erroneously happened, without crashing. - var moodPoints = new Dictionary(); - foreach (var x in query) - moodPoints[x.Date] = x.Point; - - logger.LogDebug($"Found {moodPoints.Count} mood points"); _gridYear = new GridYear(SelectedYear, System.Globalization.CultureInfo.CurrentCulture, moodPoints); logger.LogDebug("Created grid year");