Skip to content

Commit

Permalink
Still load calendar if mood category is missing but now hide colors i…
Browse files Browse the repository at this point in the history
…f disabled
  • Loading branch information
danielchalmers committed Feb 7, 2024
1 parent 85e90c5 commit 73b0b7e
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions JournalApp/Components/Pages/MoodGrid/MoodGridPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateOnly, DataPoint>();
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<DateOnly, DataPoint>();
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");
Expand Down

0 comments on commit 73b0b7e

Please sign in to comment.