Implement SignalR integration and refactor WeatherPage

Added SignalR for real-time progress updates during weather data fetch. Refactored WeatherPage to use a new reusable WeatherGrid component and SignalRHelper. Improved loading UI with a radial progress indicator.
This commit is contained in:
2025-02-09 02:00:06 +01:00
parent 72b7902b55
commit c4071786ea
7 changed files with 184 additions and 65 deletions

View File

@@ -15,9 +15,10 @@ builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin()
policy.WithOrigins("http://localhost:5173")
.AllowAnyHeader()
.AllowAnyMethod();
.AllowAnyMethod()
.AllowCredentials();
});
});
@@ -41,6 +42,14 @@ var summaries = new[]
app.MapGet("/weatherforecast", async () =>
{
var hub = app.Services.GetRequiredService<IHubContext<WeatherUpdateHub>>();
for (var i = 0; i < 100; i++)
{
await hub.Clients.All.SendAsync("ProgressUpdate", "None", $$"""{"percentage": "{{i}}", "message": "{{DateTime.Now.Millisecond}}"}""");
await Task.Delay(100);
}
var forecast = Enumerable.Range(1, 2500).Select(index =>
new WeatherForecast
(

View File

@@ -18,7 +18,7 @@ namespace Api.SignalR
logger.LogInformation("Background service sending message at: {Time}", DateTime.Now);
// Send a message to all connected clients.
await hubContext.Clients.User("user1234").SendAsync(
await hubContext.Clients.All.SendAsync(
"ReceiveMessage", // This is the client method name.
"Background Service", // Example sender.
$"Hello from the background task at {DateTime.Now:F}", // The message.