Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Oct 30, 2024
1 parent 9c82e7a commit fc3aff4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<BitText>@Localizer[nameof(AppStrings.CurrentSession)]</BitText>
<BitCard FullWidth>
<BitPersona PrimaryText="@(currentSession.Device ?? Localizer[nameof(AppStrings.UnknownDevice)])"
SecondaryText="@currentSession.Address"
TertiaryText="@($"{currentSession.IP} - {currentSession.LastSeenOn}")"
Size="BitPersonaSize.Size48"
Presence="@GetPresence(currentSession.LastSeenOn)"
Styles="@(new() { Image = "width:50%;height:50%" })"
ImageInitials=""
ImageUrl="@($"/_content/Boilerplate.Client.Core/images/os/{GetImageUrl(currentSession.Device)}")" />
SecondaryText="@currentSession.Address"
TertiaryText="@($"{currentSession.IP} - {GetLastSeenOn(currentSession.RenewedOn)}")"
Size="BitPersonaSize.Size48"
Presence="@GetPresence(currentSession.RenewedOn)"
Styles="@(new() { Image = "width:50%;height:50%" })"
ImageInitials=""
ImageUrl="@($"/_content/Boilerplate.Client.Core/images/os/{GetImageUrl(currentSession.Device)}")" />
</BitCard>
}

Expand All @@ -28,9 +28,9 @@
<BitStack Horizontal VerticalAlign="BitAlignment.Center">
<BitPersona Class="session-persona"
PrimaryText="@(session.Device ?? Localizer[nameof(AppStrings.UnknownDevice)])"
SecondaryText="@($"{session.Address} ({session.IP}) - {session.LastSeenOn}")"
SecondaryText="@($"{session.Address} ({session.IP}) - {GetLastSeenOn(session.RenewedOn)}")"
Size="BitPersonaSize.Size48"
Presence="@GetPresence(session.LastSeenOn)"
Presence="@GetPresence(session.RenewedOn)"
Styles="@(new() { Image = "width:50%;height:50%" })"
ImageInitials="@(session.IsValid ? "" : "")"
ImageUrl="@($"/_content/Boilerplate.Client.Core/images/os/{GetImageUrl(session.Device)}")" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,17 @@ private static string GetImageUrl(string? device)
return "apple.png";
}

private static BitPersonaPresence GetPresence(string? lastSeenOn)
private BitPersonaPresence GetPresence(DateTimeOffset renewedOn)
{
return lastSeenOn == AppStrings.Online ? BitPersonaPresence.Online
: lastSeenOn == AppStrings.Recently ? BitPersonaPresence.Away
: BitPersonaPresence.Offline;
return DateTimeOffset.UtcNow - renewedOn < TimeSpan.FromMinutes(5) ? BitPersonaPresence.Online
: DateTimeOffset.UtcNow - renewedOn < TimeSpan.FromMinutes(15) ? BitPersonaPresence.Away
: BitPersonaPresence.Offline;
}

private string GetLastSeenOn(DateTimeOffset renewedOn)
{
return DateTimeOffset.UtcNow - renewedOn < TimeSpan.FromMinutes(5) ? Localizer[nameof(AppStrings.Online)]
: DateTimeOffset.UtcNow - renewedOn < TimeSpan.FromMinutes(15) ? Localizer[nameof(AppStrings.Recently)]
: renewedOn.ToLocalTime().ToString("g");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
Styles="@(new() { Label = todo.IsDone ? "text-decoration:line-through" : "" })"
DefaultValue="todo.IsDone"
OnChange="() => ToggleIsDone(todo)" />
<BitText Typography="BitTypography.Body2">@todo.Date.ToLocalTime().ToString("yyyy MMMM dd, HH:mm:ss")</BitText>
<BitText Typography="BitTypography.Body2">@todo.Date.ToLocalTime().ToString("F")</BitText>
</BitStack>

<BitStack Horizontal AutoWidth Gap="0.5rem">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,17 @@ public async Task<List<UserSessionDto>> GetUserSessions(CancellationToken cancel
?? throw new ResourceNotFoundException();

return user.Sessions
.OrderByDescending(s => s.RenewedOn)
.Select(us =>
{
var dto = us.Map();

var lastSeenDateTime = us.RenewedOn ?? us.StartedOn;
dto.RenewedOn = us.RenewedOn ?? us.StartedOn;

dto.LastSeenOn = DateTimeOffset.UtcNow - lastSeenDateTime < TimeSpan.FromMinutes(5)
? Localizer[nameof(AppStrings.Online)]
: DateTimeOffset.UtcNow - lastSeenDateTime < TimeSpan.FromMinutes(15)
? Localizer[nameof(AppStrings.Recently)]
: lastSeenDateTime.Humanize(culture: CultureInfo.CurrentUICulture);

dto.IsValid = DateTimeOffset.UtcNow - lastSeenDateTime < AppSettings.Identity.RefreshTokenExpiration;
dto.IsValid = DateTimeOffset.UtcNow - dto.RenewedOn < AppSettings.Identity.RefreshTokenExpiration;

return dto;
})
.OrderByDescending(us => us.RenewedOn)
.ToList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class UserSessionDto

public string? Address { get; set; }

public string? LastSeenOn { get; set; }
public DateTimeOffset RenewedOn { get; set; }

public bool IsValid { get; set; }
}

0 comments on commit fc3aff4

Please sign in to comment.