@page "/{UserType}/Devices"
@if (_isInitialized) {
Devices (@WhoAmI.UserId#@WhoAmI.DeviceId[..5])
Create new device
Reload Devices
Log out
Delete account
@foreach (var device in CurrentDevices) {
ID: @device.Id
@if (device.Id == WhoAmI.DeviceId) {
(current)
}
Name: @device.Name
First seen: @device.CreatedAt.ToLocalTime()
Last seen: @device.LastSeen.ToLocalTime()
Log out
}
}
@code {
private bool _isInitialized;
[Parameter]
public string UserType { get; set; } = string.Empty;
private SafeNSoundClient Client { get; set; } = null!;
private RegisterDto Auth { get; set; } = null!;
private WhoAmI WhoAmI { get; set; } = null!;
private List CurrentDevices { get; set; } = null!;
protected override async Task OnInitializedAsync() {
if (UserType is not "User" and not "Monitor" and not "Admin") {
NavigationManager.NavigateTo("/");
return;
}
Client = UserType switch {
"User" => App.UserClient,
"Monitor" => App.MonitorClient,
"Admin" => App.AdminClient,
_ => throw new InvalidOperationException("Invalid UserType")
};
Auth = UserType switch {
"User" => App.UserAuth,
"Monitor" => App.MonitorAuth,
"Admin" => App.AdminAuth,
_ => throw new InvalidOperationException("Invalid UserType")
};
WhoAmI = await Client.WhoAmI();
await ReloadDevices();
_isInitialized = true;
}
private async Task CreateDevice() {
await Authentication.Login(Auth);
await ReloadDevices();
}
private async Task DeleteDevice(DeviceDto device) {
await Client.DeleteDevice(device.Id!);
await ReloadDevices();
}
private async Task ReloadDevices() {
CurrentDevices = await Client.GetDevices();
StateHasChanged();
}
private async Task DeleteAccount() {
await Client.DeleteAccount(Auth);
}
private async Task Logout() {
await Client.LogOut();
}
}