feat(panel): re-fetch server after state change

This commit is contained in:
CyberL1 2024-05-30 11:24:20 +02:00
parent 82e3abd103
commit 10f547723c

View File

@ -17,14 +17,20 @@ else
@server.State @server.State
</div> </div>
<div class="buttons"> <div class="buttons">
<button class="btn btn-success" @onclick="StartServer"> @if (server.State == "CLOSED")
<i class="bi-caret-right-fill"></i> {
Start <button class="btn btn-success" @onclick="StartServer">
</button> <i class="bi-caret-right-fill"></i>
<button class="btn btn-danger" @onclick="StopServer"> Start
<i class="bi-stop-circle-fill"></i> </button>
Stop }
</button> else
{
<button class="btn btn-danger" @onclick="StopServer">
<i class="bi-stop-circle-fill"></i>
Stop
</button>
}
</div> </div>
</div> </div>
@ -47,6 +53,11 @@ else
private List<string> logs = []; private List<string> logs = [];
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{
await GetServer();
}
public async Task GetServer()
{ {
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ADMIN_KEY")); httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ADMIN_KEY"));
@ -75,7 +86,9 @@ else
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ADMIN_KEY")); httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ADMIN_KEY"));
await JS.InvokeVoidAsync("serverLogsStream.start", DotNetObjectReference.Create(this), wId);
await httpClient.PutAsync($"http://localhost:8080/api/admin/servers/{wId}/open", new StringContent("")); await httpClient.PutAsync($"http://localhost:8080/api/admin/servers/{wId}/open", new StringContent(""));
await GetServer();
} }
public async Task StopServer() public async Task StopServer()
@ -84,5 +97,6 @@ else
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ADMIN_KEY")); httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ADMIN_KEY"));
await httpClient.PutAsync($"http://localhost:8080/api/admin/servers/{wId}/close", new StringContent("")); await httpClient.PutAsync($"http://localhost:8080/api/admin/servers/{wId}/close", new StringContent(""));
await GetServer();
} }
} }