Skip to content

Commit 73b0b7e

Browse files
Still load calendar if mood category is missing but now hide colors if disabled
1 parent 85e90c5 commit 73b0b7e

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

JournalApp/Components/Pages/MoodGrid/MoodGridPage.razor

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,30 @@
150150

151151
_moodCategory ??= await db.Categories.SingleOrDefaultAsync(x => x.Guid == new Guid("D90D89FB-F5B9-47CF-AE4E-3EC0D635E783"));
152152

153-
if (_moodCategory == null)
153+
var moodPoints = new Dictionary<DateOnly, DataPoint>();
154+
if (_moodCategory == null || !_moodCategory.Enabled)
154155
{
155-
logger.LogError($"Mood category doesn't exist so we can't load the year.");
156-
return;
156+
logger.LogError("Mood category doesn't exist or is disabled so we won't load any points.");
157+
}
158+
else
159+
{
160+
var query = db.Points
161+
.Where(p => !p.Deleted && p.Day.Date.Year == SelectedYear && p.Day.Date <= tomorrow && p.Category.Guid == _moodCategory.Guid)
162+
.Select(
163+
p => new
164+
{
165+
Date = p.Day.Date,
166+
Point = p,
167+
}
168+
);
169+
170+
// Sort into dictionary here instead of during the query so we can handle
171+
// duplicate dates, if that has erroneously happened, without crashing.
172+
foreach (var x in query)
173+
moodPoints[x.Date] = x.Point;
174+
175+
logger.LogDebug($"Found {moodPoints.Count} mood points");
157176
}
158-
159-
var query = db.Points
160-
.Where(p => !p.Deleted && p.Day.Date.Year == SelectedYear && p.Day.Date <= tomorrow && p.Category.Guid == _moodCategory.Guid)
161-
.Select(
162-
p => new
163-
{
164-
Date = p.Day.Date,
165-
Point = p,
166-
}
167-
);
168-
169-
// Sort into dictionary here instead of during the query so we can handle
170-
// duplicate dates, if that has erroneously happened, without crashing.
171-
var moodPoints = new Dictionary<DateOnly, DataPoint>();
172-
foreach (var x in query)
173-
moodPoints[x.Date] = x.Point;
174-
175-
logger.LogDebug($"Found {moodPoints.Count} mood points");
176177

177178
_gridYear = new GridYear(SelectedYear, System.Globalization.CultureInfo.CurrentCulture, moodPoints);
178179
logger.LogDebug("Created grid year");

0 commit comments

Comments
 (0)