summary refs log tree commit diff
path: root/testFrontend/SafeNSound.Frontend
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-06-01 11:13:55 +0200
committerRory& <root@rory.gay>2025-06-01 11:13:55 +0200
commit4e12e02bc805170e6b03d33e0ef894b2a3021fb3 (patch)
treea525a35cfcc28f80bbe33d152fe483d14d8b23d1 /testFrontend/SafeNSound.Frontend
parentUpdate test client (diff)
downloadnodejs-final-assignment-4e12e02bc805170e6b03d33e0ef894b2a3021fb3.tar.xz
Add alarm endpoints, basic budget routes, spend history
Diffstat (limited to 'testFrontend/SafeNSound.Frontend')
-rw-r--r--testFrontend/SafeNSound.Frontend/App.razor8
-rw-r--r--testFrontend/SafeNSound.Frontend/Layout/NavMenu.razor4
-rw-r--r--testFrontend/SafeNSound.Frontend/Pages/Alarm.razor36
-rw-r--r--testFrontend/SafeNSound.Frontend/Pages/Auth.razor4
-rw-r--r--testFrontend/SafeNSound.Frontend/Pages/Weather.razor60
-rw-r--r--testFrontend/SafeNSound.Frontend/_Imports.razor3
6 files changed, 50 insertions, 65 deletions
diff --git a/testFrontend/SafeNSound.Frontend/App.razor b/testFrontend/SafeNSound.Frontend/App.razor

index c7730d1..13c8280 100644 --- a/testFrontend/SafeNSound.Frontend/App.razor +++ b/testFrontend/SafeNSound.Frontend/App.razor
@@ -9,4 +9,10 @@ <p role="alert">Sorry, there's nothing at this address.</p> </LayoutView> </NotFound> -</Router> \ No newline at end of file +</Router> + +@code { + + public static SafeNSoundClient? Client { get; set; } + +} \ No newline at end of file diff --git a/testFrontend/SafeNSound.Frontend/Layout/NavMenu.razor b/testFrontend/SafeNSound.Frontend/Layout/NavMenu.razor
index 2a0fd8a..b688610 100644 --- a/testFrontend/SafeNSound.Frontend/Layout/NavMenu.razor +++ b/testFrontend/SafeNSound.Frontend/Layout/NavMenu.razor
@@ -15,8 +15,8 @@ </NavLink> </div> <div class="nav-item px-3"> - <NavLink class="nav-link" href="counter"> - <span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter + <NavLink class="nav-link" href="/Alarm"> + <span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Alarm </NavLink> </div> <div class="nav-item px-3"> diff --git a/testFrontend/SafeNSound.Frontend/Pages/Alarm.razor b/testFrontend/SafeNSound.Frontend/Pages/Alarm.razor new file mode 100644
index 0000000..9b90ef4 --- /dev/null +++ b/testFrontend/SafeNSound.Frontend/Pages/Alarm.razor
@@ -0,0 +1,36 @@ +@page "/Alarm" + +<h1>Alarm</h1> + +<br/><br/> + +@if (Exception != null) { + <div class="alert alert-danger"> + <strong>Error:</strong><br/> + <pre> + @Exception + </pre> + </div> +} + +@if (Result != null) { + <div class="alert alert-success"> + <strong>Result:</strong><br/> + <pre> + @Result.ToJson(indent: true) + </pre> + </div> +} + +@code { + private Exception? Exception { get; set; } + private object? Result { get; set; } + + protected override async Task OnInitializedAsync() { + if (App.Client is null) { + NavigationManager.NavigateTo("/Auth"); + return; + } + } + +} \ No newline at end of file diff --git a/testFrontend/SafeNSound.Frontend/Pages/Auth.razor b/testFrontend/SafeNSound.Frontend/Pages/Auth.razor
index 3db77a1..c58a996 100644 --- a/testFrontend/SafeNSound.Frontend/Pages/Auth.razor +++ b/testFrontend/SafeNSound.Frontend/Pages/Auth.razor
@@ -73,11 +73,13 @@ Result = null; Exception = null; try { - Result = await Authentication.Login(new() { + SafeNSoundAuthResult result; + Result = result = await Authentication.Login(new() { Username = Username, Password = Password, Email = Email }); + App.Client = new SafeNSoundClient(Config, result.AccessToken); } catch (Exception ex) { Exception = ex; diff --git a/testFrontend/SafeNSound.Frontend/Pages/Weather.razor b/testFrontend/SafeNSound.Frontend/Pages/Weather.razor deleted file mode 100644
index a0ca515..0000000 --- a/testFrontend/SafeNSound.Frontend/Pages/Weather.razor +++ /dev/null
@@ -1,60 +0,0 @@ -@page "/weather" -@inject HttpClient Http - -<PageTitle>Weather</PageTitle> - -<h1>Weather</h1> - -<p>This component demonstrates fetching data from the server.</p> - -@if (forecasts == null) -{ - <p> - <em>Loading...</em> - </p> -} -else -{ - <table class="table"> - <thead> - <tr> - <th>Date</th> - <th aria-label="Temperature in Celsius">Temp. (C)</th> - <th aria-label="Temperature in Farenheit">Temp. (F)</th> - <th>Summary</th> - </tr> - </thead> - <tbody> - @foreach (var forecast in forecasts) - { - <tr> - <td>@forecast.Date.ToShortDateString()</td> - <td>@forecast.TemperatureC</td> - <td>@forecast.TemperatureF</td> - <td>@forecast.Summary</td> - </tr> - } - </tbody> - </table> -} - -@code { - private WeatherForecast[]? forecasts; - - protected override async Task OnInitializedAsync() - { - forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json"); - } - - public class WeatherForecast - { - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public string? Summary { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - } - -} \ No newline at end of file diff --git a/testFrontend/SafeNSound.Frontend/_Imports.razor b/testFrontend/SafeNSound.Frontend/_Imports.razor
index 0103f88..18a240e 100644 --- a/testFrontend/SafeNSound.Frontend/_Imports.razor +++ b/testFrontend/SafeNSound.Frontend/_Imports.razor
@@ -14,4 +14,5 @@ @using ArcaneLibs.Extensions @inject SafeNSoundAuthentication Authentication -@inject SafeNSoundConfiguration Config \ No newline at end of file +@inject SafeNSoundConfiguration Config +@inject NavigationManager NavigationManager \ No newline at end of file