Skip to content

Commit

Permalink
Add dummy avatar image for users w/o profile pic
Browse files Browse the repository at this point in the history
  • Loading branch information
veloek committed Sep 5, 2024
1 parent c4219a8 commit 4c8ee19
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
3 changes: 2 additions & 1 deletion Tevling/Components/ChallengeCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
@if (ShowScoreBoard && ScoreBoard != null)
{
<ul class="list-group list-group-flush list-group-numbered overflow-auto" style="max-height: 14rem">
@{var i = 0;}
@foreach (AthleteScore score in ScoreBoard.Scores)
{
<li class="list-group-item d-flex justify-content-between">
<span>@score.Name</span>
<span>@(++i == 1 ? "🥇" : i == 2 ? "🥈" : i == 3 ? "🥉" : "") @score.Name</span>
<span class="score">@score.Score</span>
</li>
}
Expand Down
66 changes: 33 additions & 33 deletions Tevling/Services/ChallengeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ public async Task<Challenge[]> GetChallengesAsync(int currentAthleteId, Challeng
.Where(challenge => filter.OnlyJoinedChallenges
? challenge.Athletes!.Any(a => a.Id == currentAthleteId)
: !challenge.IsPrivate
|| challenge.InvitedAthletes!.Any(a => a.Id == currentAthleteId)
|| challenge.CreatedById == currentAthleteId)
|| challenge.InvitedAthletes!.Any(a => a.Id == currentAthleteId)
|| challenge.CreatedById == currentAthleteId)
.Where(challenge => !filter.ByAthleteId.HasValue
|| challenge.Athletes!.Any(athlete => athlete.Id == filter.ByAthleteId.Value) == true
|| challenge.CreatedById == filter.ByAthleteId.Value)
|| challenge.Athletes!.Any(athlete => athlete.Id == filter.ByAthleteId.Value) == true
|| challenge.CreatedById == filter.ByAthleteId.Value)
// TODO: Filter out outdated challenges when DB supports it
// (Time to switch to PostgreSQL?)
// .Where(challenge => filter.IncludeOutdatedChallenges
// || challenge.End.UtcDateTime.Date >= DateTimeOffset.UtcNow.Date)
.Where(c => string.IsNullOrWhiteSpace(filter.SearchText)
// TODO: Use EF.Functions.ILike when switching to PostgreSQL
// to keep the search text case-insensitive
|| EF.Functions.Like(c.Title, $"%{filter.SearchText}%"))
// TODO: Use EF.Functions.ILike when switching to PostgreSQL
// to keep the search text case-insensitive
|| EF.Functions.Like(c.Title, $"%{filter.SearchText}%"))
.OrderByDescending(challenge => challenge.Start)
.ThenBy(challenge => challenge.Title)
.ThenBy(challenge => challenge.Id)
Expand Down Expand Up @@ -110,13 +110,13 @@ public async Task<Challenge> UpdateChallengeAsync(int challengeId, ChallengeForm
using DataContext dataContext = await _dataContextFactory.CreateDbContextAsync(ct);

Challenge challenge = await dataContext.Challenges
.Include(c => c.Athletes)
.Include(c => c.CreatedBy)
.Include(c => c.InvitedAthletes)
.AsSplitQuery()
.AsTracking()
.FirstOrDefaultAsync(c => c.Id == challengeId, ct)
?? throw new Exception($"Unknown challenge ID {challengeId}");
.Include(c => c.Athletes)
.Include(c => c.CreatedBy)
.Include(c => c.InvitedAthletes)
.AsSplitQuery()
.AsTracking()
.FirstOrDefaultAsync(c => c.Id == challengeId, ct)
?? throw new Exception($"Unknown challenge ID {challengeId}");

_logger.LogInformation("Updating challenge ID {ChallengeId}", challengeId);

Expand Down Expand Up @@ -155,16 +155,16 @@ public async Task<Challenge> JoinChallengeAsync(int athleteId, int challengeId,
using DataContext dataContext = await _dataContextFactory.CreateDbContextAsync(ct);

Challenge challenge = await dataContext.Challenges
.Include(c => c.Athletes)
.Include(c => c.CreatedBy)
.AsTracking()
.FirstOrDefaultAsync(c => c.Id == challengeId, ct)
?? throw new Exception($"Challenge ID {challengeId} not found");
.Include(c => c.Athletes)
.Include(c => c.CreatedBy)
.AsTracking()
.FirstOrDefaultAsync(c => c.Id == challengeId, ct)
?? throw new Exception($"Challenge ID {challengeId} not found");

Athlete athlete = await dataContext.Athletes
.AsTracking()
.FirstOrDefaultAsync(a => a.Id == athleteId, ct)
?? throw new Exception($"Athlete ID {athleteId} not found");
.AsTracking()
.FirstOrDefaultAsync(a => a.Id == athleteId, ct)
?? throw new Exception($"Athlete ID {athleteId} not found");

challenge.Athletes!.Add(athlete);

Expand All @@ -180,11 +180,11 @@ public async Task<Challenge> LeaveChallengeAsync(int athleteId, int challengeId,
using DataContext dataContext = await _dataContextFactory.CreateDbContextAsync(ct);

Challenge challenge = await dataContext.Challenges
.Include(c => c.Athletes)
.Include(c => c.CreatedBy)
.AsTracking()
.FirstOrDefaultAsync(c => c.Id == challengeId, ct)
?? throw new Exception($"Challenge ID {challengeId} not found");
.Include(c => c.Athletes)
.Include(c => c.CreatedBy)
.AsTracking()
.FirstOrDefaultAsync(c => c.Id == challengeId, ct)
?? throw new Exception($"Challenge ID {challengeId} not found");

Athlete? athlete = challenge.Athletes!.FirstOrDefault(a => a.Id == athleteId);

Expand All @@ -202,9 +202,9 @@ public async Task DeleteChallengeAsync(int challengeId, CancellationToken ct = d
using DataContext dataContext = await _dataContextFactory.CreateDbContextAsync(ct);

Challenge challenge = await dataContext.Challenges
.Include(c => c.Athletes) // TODO: Is this necessary?
.FirstOrDefaultAsync(c => c.Id == challengeId, ct)
?? throw new Exception($"Unknown challenge ID {challengeId}");
.Include(c => c.Athletes) // TODO: Is this necessary?
.FirstOrDefaultAsync(c => c.Id == challengeId, ct)
?? throw new Exception($"Unknown challenge ID {challengeId}");

_logger.LogInformation("Deleting challenge ID {ChallengeId}", challengeId);
_ = await dataContext.RemoveChallengeAsync(challenge, ct);
Expand Down Expand Up @@ -245,9 +245,9 @@ operation which EFCore requires.
a.Athlete,
Activities = a.Activities!
.Where(a => a.Details.StartDate >= result.Challenge.Start
&& a.Details.StartDate < result.Challenge.End
&& (result.Challenge.ActivityTypes.Count == 0
|| result.Challenge.ActivityTypes.Contains(a.Details.Type)))
&& a.Details.StartDate < result.Challenge.End
&& (result.Challenge.ActivityTypes.Count == 0
|| result.Challenge.ActivityTypes.Contains(a.Details.Type)))
})
.Select(a => new
{
Expand Down
Binary file added Tevling/wwwroot/avatar/athlete/large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4c8ee19

Please sign in to comment.