Skip to content

Commit

Permalink
Reformat and apply syntax style
Browse files Browse the repository at this point in the history
  • Loading branch information
veloek committed Sep 5, 2024
1 parent 1880de4 commit 8fb0af3
Show file tree
Hide file tree
Showing 64 changed files with 854 additions and 695 deletions.
10 changes: 7 additions & 3 deletions Tevling/Clients/IStravaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ namespace Tevling.Clients;
public interface IStravaClient
{
Task<TokenResponse> GetAccessTokenByAuthorizationCodeAsync(
string authorizationCode, CancellationToken ct = default);
string authorizationCode,
CancellationToken ct = default);

Task<TokenResponse> GetAccessTokenByRefreshTokenAsync(
string refreshToken, CancellationToken ct = default);
string refreshToken,
CancellationToken ct = default);

Task<DetailedActivity> GetActivityAsync(long stravaId, string accessToken,
Task<DetailedActivity> GetActivityAsync(
long stravaId,
string accessToken,
CancellationToken ct = default);

Task<SummaryActivity[]> GetAthleteActivitiesAsync(
Expand Down
22 changes: 15 additions & 7 deletions Tevling/Clients/StravaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ public StravaClient(
catch
{
string fallback = "https://www.strava.com/api/v3/";
_logger.LogWarning("Invalid BaseApiUri: '{BaseApiUrl}', using fallback: '{Fallback}'",
_stravaConfig.BaseApiUri, fallback);
_logger.LogWarning(
"Invalid BaseApiUri: '{BaseApiUrl}', using fallback: '{Fallback}'",
_stravaConfig.BaseApiUri,
fallback);
_httpClient.BaseAddress = new Uri(fallback);
}
}

public async Task<TokenResponse> GetAccessTokenByAuthorizationCodeAsync(
string authorizationCode, CancellationToken ct = default)
string authorizationCode,
CancellationToken ct = default)
{
FormUrlEncodedContent content = new(new[]
FormUrlEncodedContent content = new(
new[]
{
new KeyValuePair<string, string?>("client_id", _stravaConfig.ClientId.ToString()),
new KeyValuePair<string, string?>("client_secret", _stravaConfig.ClientSecret),
Expand All @@ -59,9 +63,11 @@ public async Task<TokenResponse> GetAccessTokenByAuthorizationCodeAsync(
}

public async Task<TokenResponse> GetAccessTokenByRefreshTokenAsync(
string refreshToken, CancellationToken ct = default)
string refreshToken,
CancellationToken ct = default)
{
FormUrlEncodedContent content = new(new[]
FormUrlEncodedContent content = new(
new[]
{
new KeyValuePair<string, string?>("client_id", _stravaConfig.ClientId.ToString()),
new KeyValuePair<string, string?>("client_secret", _stravaConfig.ClientSecret),
Expand All @@ -82,7 +88,9 @@ public async Task<TokenResponse> GetAccessTokenByRefreshTokenAsync(
}

public async Task<DetailedActivity> GetActivityAsync(
long stravaId, string accessToken, CancellationToken ct = default)
long stravaId,
string accessToken,
CancellationToken ct = default)
{
HttpRequestMessage request = new(HttpMethod.Get, $"activities/{stravaId}");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
Expand Down
2 changes: 1 addition & 1 deletion Tevling/Components/ActivityCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div class="activity-card-header d-flex flex-row align-items-center flex-wrap-reverse row-gap-1">
<div class="d-flex align-items-center flex-row column-gap-2 athlete-name-container me-1">
<Avatar Url="@Activity.Athlete?.ImgUrl" Size="40"/>
<Avatar Url="@Activity.Athlete?.ImgUrl" Size="40" />
<span class="athlete-name">@Activity.Athlete?.Name</span>
</div>
<span class="activity-time">@ActivityTime</span>
Expand Down
60 changes: 30 additions & 30 deletions Tevling/Components/ActivityCard.razor.css
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
.activity-card {
display: flex;
flex-direction: row;
border-radius: 1.5rem;
width: 34rem;
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.25);
transition: box-shadow 0.2s, max-height 1s ease-in-out;
column-gap: 1em;
margin-bottom: 1rem;
display: flex;
flex-direction: row;
border-radius: 1.5rem;
width: 34rem;
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.25);
transition: box-shadow 0.2s, max-height 1s ease-in-out;
column-gap: 1em;
margin-bottom: 1rem;
}

@media (min-width: 501px) {
.activity-card-body {
margin-left: 3rem;
}
.activity-card-body {
margin-left: 3rem;
}
}

@media (max-width: 500px) {
.activity-card {
width: 21rem;
}
.activity-card {
width: 21rem;
}

.activity-time,
.strava-link,
.athlete-name {
text-wrap: none;
}
.activity-time,
.strava-link,
.athlete-name {
text-wrap: none;
}

.athlete-name-container {
margin-bottom: 1rem;
}
.athlete-name-container {
margin-bottom: 1rem;
}
}

.activity-card-content {
width: 100%;
width: 100%;
}

.activity-time,
.strava-link {
font-size: smaller;
font-weight: 300;
font-size: smaller;
font-weight: 300;
}

.activity-time {
color: #737373;
color: #737373;
}

.activity-name {
font-weight: 600;
font-weight: 600;
}

.activity-description {
font-size: 0.9rem;
font-size: 0.9rem;
}

.page[data-bs-theme="dark"] .activity-card {
background-color: #121417;
background-color: #121417;
}

.page[data-bs-theme="light"] .activity-card {
background-color: white;
background-color: white;
}
2 changes: 1 addition & 1 deletion Tevling/Components/AthleteCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="d-flex align-items-center flex-row column-gap-2 athlete-name me-auto">
@if (Athlete.ImgUrl is not null)
{
<Avatar Url="@Athlete.ImgUrl" Size="30"/>
<Avatar Url="@Athlete.ImgUrl" Size="30" />
}
<span>@Athlete.Name</span>
</div>
Expand Down
8 changes: 3 additions & 5 deletions Tevling/Components/Avatar.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<div class="avatar">
<img src="@Url" width="@Size" height="@Size" alt="avatar"/>
<img src="@Url" width="@Size" height="@Size" alt="avatar" />
</div>

@code {
[Parameter]
public string? Url { get; set; }
[Parameter]
public int Size { get; set; }
[Parameter] public string? Url { get; set; }
[Parameter] public int Size { get; set; }
}
10 changes: 5 additions & 5 deletions Tevling/Components/Avatar.razor.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.avatar {
display: inline-flex;
align-items: center;
border-radius: 50%;
overflow: hidden;
height: fit-content;
display: inline-flex;
align-items: center;
border-radius: 50%;
overflow: hidden;
height: fit-content;
}
6 changes: 4 additions & 2 deletions Tevling/Components/ChallengeCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<a class="dropdown-item"
data-bs-toggle="modal"
data-bs-target="#deleteChallenge-@(Challenge.Id)"
@onclick:stopPropagation="true">Delete</a>
@onclick:stopPropagation="true">
Delete
</a>
</li>
</ul>
}
Expand Down Expand Up @@ -166,7 +168,7 @@
{
<h5 class="mb-3">The winner for @Challenge.Title is...</h5>
<div class="d-flex flex-row align-items-center column-gap-1 mb-3">
<Avatar Url="@Winner.ImgUrl" Size="30"/>
<Avatar Url="@Winner.ImgUrl" Size="30" />
<span>@Winner.Name</span>
</div>
<span>Great job! Congratulations on the victory! 🎉</span>
Expand Down
2 changes: 1 addition & 1 deletion Tevling/Components/ChallengeCard.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private string MeasurementIcon
ChallengeMeasurement.Distance => "bi-arrow-right",
ChallengeMeasurement.Time => "bi-stopwatch-fill",
ChallengeMeasurement.Elevation => "bi-arrow-up",
_ => "bi-question-circle"
_ => "bi-question-circle",
};
}
}
Expand Down
41 changes: 21 additions & 20 deletions Tevling/Components/ChallengeForm.razor
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
@using Tevling.Strava
<EditForm FormName="challenge" method="post" Model="@Challenge" OnValidSubmit="SubmitForm">
<div class="d-flex flex-row mb-3 column-gap-5 flex-wrap">
<div class="left-column me-5">
<div class="form-row mb-5">
<label>
Title
<InputText @bind-Value="@Challenge.Title" size="50" class="form-control"/>
<InputText @bind-Value="@Challenge.Title" size="50" class="form-control" />
</label>
</div>
<div class="form-row mb-5">
<label>
Description
<InputTextArea @bind-Value="@Challenge.Description" cols="50" rows="4" class="form-control"/>
<InputTextArea @bind-Value="@Challenge.Description" cols="50" rows="4" class="form-control" />
</label>
</div>
<div class="form-row mb-5">
<label class="me-4">
Start
<InputDate @bind-Value="@Challenge.Start" Type="InputDateType.Date"
max="@Challenge.End.ToString("yyyy-MM-dd")" class="form-control"/>
max="@Challenge.End.ToString("yyyy-MM-dd")" class="form-control" />
</label>
<label>
End
<InputDate @bind-Value="@Challenge.End" Type="InputDateType.Date"
min="@Challenge.Start.ToString("yyyy-MM-dd")" class="form-control"/>
min="@Challenge.Start.ToString("yyyy-MM-dd")" class="form-control" />
</label>
</div>
<div class="form-row mb-5 d-flex column-gap-5">
<div>
<h5 class="mb-3">Challenge type</h5>
<InputRadioGroup @bind-Value="@Challenge.Measurement">
@foreach (var measurement in Enum.GetValues<ChallengeMeasurement>())
@foreach (ChallengeMeasurement measurement in Enum.GetValues<ChallengeMeasurement>())
{
<div>
<InputRadio Value="@measurement" class="me-2 form-check-input"/><label>@measurement</label>
<InputRadio Value="@measurement" class="me-2 form-check-input" /><label>@measurement</label>
</div>
}
</InputRadioGroup>
Expand All @@ -41,18 +42,18 @@
<h5 class="mb-3">Challenge visibility</h5>
<InputRadioGroup @bind-Value="@Challenge.IsPrivate">
<div>
<InputRadio Value="false" class="form-check-input"/> <label>Public challenge</label>
<InputRadio Value="false" class="form-check-input" /> <label>Public challenge</label>
</div>
<div>
<InputRadio Value="true" class="form-check-input"/> <label>Private challenge</label>
<InputRadio Value="true" class="form-check-input" /> <label>Private challenge</label>
</div>
</InputRadioGroup>
</div>
</div>
<div class="form-row mb-2 activity-types-selection">
<h5 class="mb-3">Activity types</h5>
<div class="mb-3">
<DropdownSearch Items="@ActivityTypes" T="Strava.ActivityType"
<DropdownSearch Items="@ActivityTypes" T="ActivityType"
DisplayFunc="@ActivityTypeExt.ToString"
@bind-SelectedItems="@Challenge.ActivityTypes"
@ref="_dropdownSearchRefActivityTypes">
Expand All @@ -64,7 +65,7 @@
<a type="button" class="btn btn-primary selected-activity-type py-1">All activities</a>
}
<div class="d-flex flex-wrap column-gap-2 row-gap-1">
@foreach (var item in Challenge.ActivityTypes)
@foreach (ActivityType item in Challenge.ActivityTypes)
{
<a @onclick="() => DeselectActivityType(item)" type="button" class="btn btn-primary selected-activity-type">
@ActivityTypeExt.ToString(item)<i class="bi bi-x ms-1"></i>
Expand All @@ -73,12 +74,12 @@
</div>
</div>
</div>
<DataAnnotationsValidator/>
<ValidationSummary/>

<DataAnnotationsValidator />
<ValidationSummary />

</div>

@if (Challenge.IsPrivate)
{
<div class="right-column">
Expand All @@ -90,24 +91,24 @@
@ref="_dropdownSearchRefAthletes">
</DropdownSearch>
<div class="d-flex flex-column row-gap-1 mt-3">
@foreach (var athlete in Challenge.InvitedAthletes)
@foreach (Athlete? athlete in Challenge.InvitedAthletes)
{
<div class="d-flex selected-athlete column-gap-2">
<a @onclick="() => DeselectAthlete(athlete)" type="button">
<i class="bi bi-x-circle ms-1"></i>
</a>
<Avatar Url="@athlete.ImgUrl" Size="30"/>
<Avatar Url="@athlete.ImgUrl" Size="30" />
@AthletesDisplayFunc(athlete)
</div>
}
</div>
</div>
}
</div>

<div class="form-group mt-5 mb-5">
<button class="btn btn-primary" type="submit">@SubmitLabel</button>
<button class="btn btn-secondary" type="button" @onclick="Cancel">@CancelLabel</button>
</div>
</EditForm>

</EditForm>
6 changes: 3 additions & 3 deletions Tevling/Components/ChallengeForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ protected override void OnParametersSet()
Challenge.IsPrivate = EditChallenge.IsPrivate;
Challenge.CreatedBy = EditChallenge.CreatedById;
Challenge.InvitedAthletes = EditChallenge.InvitedAthletes?.ToList() ?? []
;
;
}
else
{
Challenge = new ChallengeFormModel
{
Start = DateTimeOffset.Now,
End = DateTimeOffset.Now.AddMonths(1),
CreatedBy = Athlete.Id
CreatedBy = Athlete.Id,
};
}
}
Expand All @@ -64,7 +64,7 @@ private async Task<IEnumerable<Athlete>> SearchAthletes(string searchText)
AthleteFilter filter = new()
{
SearchText = searchText,
NotIn = Challenge.InvitedAthletes.Select(a => a.Id).Append(Athlete.Id)
NotIn = Challenge.InvitedAthletes.Select(a => a.Id).Append(Athlete.Id),
};

Athlete[] result = await AthleteService.GetAthletesAsync(filter, new Paging(MaximumSuggestions));
Expand Down
Loading

0 comments on commit 8fb0af3

Please sign in to comment.