Skip to content

Commit

Permalink
Update application
Browse files Browse the repository at this point in the history
  • Loading branch information
seesharprun committed Oct 22, 2024
1 parent e1263bb commit 93063ba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/web/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<ImportMap />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet />
<PageTitle>
Azure Cosmos DB for NoSQL
</PageTitle>
</head>

<body data-bs-theme="dark">
Expand Down
59 changes: 35 additions & 24 deletions src/web/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
@page "/"
@using System.Text
@inject IDemoService demoService
@rendermode InteractiveServer

<PageTitle>
Azure Cosmos DB for NoSQL | .NET Quickstart
</PageTitle>

<pre class="bg-light text-dark fw-light font-monospace mt-5 p-2">
@_console.ToString()
@ConsoleText
</pre>

<section class="d-flex justify-content-center">
<div class="list-group py-2">
<button type="button" class="list-group-item list-group-item-action @(_runAgainEnabled ? "" : "disabled") active" aria-current="true" @onclick="RunAgain">
<button type="button" class="list-group-item list-group-item-action @(RunAgainEnabled ? "" : "disabled") active" aria-current="true" @onclick="RunAgainAsync">
<i class="bi bi-arrow-clockwise me-2"></i>
Restart
</button>
Expand Down Expand Up @@ -45,13 +46,24 @@
@code {
private StringBuilder _console = new();

private bool _runAgainEnabled = false;
private string ConsoleText
{
get => _console.ToString();
}

protected override void OnInitialized() => GenerateQueryDataAsync();
private bool RunAgainEnabled { get; set; }

protected override async Task OnInitializedAsync()
{
await GenerateQueryDataAsync();
}

private void RunAgain() => GenerateQueryDataAsync();
private async Task RunAgainAsync()
{
await GenerateQueryDataAsync();
}

private async void GenerateQueryDataAsync()
private async Task GenerateQueryDataAsync()
{
await SetRunAgain(false);
await ClearConsoleAsync();
Expand All @@ -62,25 +74,24 @@

await WriteToConsoleAync("Current Status:\tStopping...");
await SetRunAgain(true);
}

async Task WriteToConsoleAync(string message)
{
_console.AppendLine(message);
await InvokeAsync(StateHasChanged);
await Task.Delay(TimeSpan.FromSeconds(0.75));
}

async Task ClearConsoleAsync()
{
_console.Clear();
await InvokeAsync(StateHasChanged);
}

async Task SetRunAgain(bool state)
{
_runAgainEnabled = state;
await InvokeAsync(StateHasChanged);
}
private async Task WriteToConsoleAync(string message)
{
_console.AppendLine(message);
await InvokeAsync(StateHasChanged);
}

private async Task ClearConsoleAsync()
{
_console.Clear();
await InvokeAsync(StateHasChanged);
}

private async Task SetRunAgain(bool state)
{
RunAgainEnabled = state;
await InvokeAsync(StateHasChanged);
}
}

0 comments on commit 93063ba

Please sign in to comment.