|
|
|
@ -1,25 +1,25 @@ |
|
|
|
|
@page "/weather" |
|
|
|
|
@attribute [StreamRendering] |
|
|
|
|
@using MyBlazorApp.Services |
|
|
|
|
@inject WeatherForecastService ForecastService |
|
|
|
|
|
|
|
|
|
<PageTitle>Weather</PageTitle> |
|
|
|
|
<h3>Weather Forecast ☀️</h3> |
|
|
|
|
|
|
|
|
|
<h1>Weather</h1> |
|
|
|
|
|
|
|
|
|
<p>This component demonstrates showing data.</p> |
|
|
|
|
|
|
|
|
|
@if (forecasts == null) |
|
|
|
|
@if (isLoading) |
|
|
|
|
{ |
|
|
|
|
<p><em>Loading...</em></p> |
|
|
|
|
<p><em>불러오는 중...</em></p> |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
else if (forecasts is not null && forecasts.Any()) |
|
|
|
|
{ |
|
|
|
|
<div> |
|
|
|
|
<label class="text-info">앞으로 @(forecasts.Count())일에 대한 일기예보</label> |
|
|
|
|
</div> |
|
|
|
|
<table class="table"> |
|
|
|
|
<thead> |
|
|
|
|
<tr> |
|
|
|
|
<th>Date</th> |
|
|
|
|
<th>Temp. (C)</th> |
|
|
|
|
<th>Temp. (F)</th> |
|
|
|
|
<th>Summary</th> |
|
|
|
|
<th>날짜</th> |
|
|
|
|
<th>온도 (C)</th> |
|
|
|
|
<th>온도 (F)</th> |
|
|
|
|
<th>요약</th> |
|
|
|
|
</tr> |
|
|
|
|
</thead> |
|
|
|
|
<tbody> |
|
|
|
@ -35,30 +35,39 @@ else |
|
|
|
|
</tbody> |
|
|
|
|
</table> |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
<p>유효한 데이터가 없습니다.</p> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@code { |
|
|
|
|
private WeatherForecast[]? forecasts; |
|
|
|
|
private IEnumerable<WeatherForecast> forecasts; |
|
|
|
|
private bool isLoading = true; |
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync() |
|
|
|
|
{ |
|
|
|
|
// Simulate asynchronous loading to demonstrate streaming rendering |
|
|
|
|
await Task.Delay(500); |
|
|
|
|
|
|
|
|
|
var startDate = DateOnly.FromDateTime(DateTime.Now); |
|
|
|
|
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; |
|
|
|
|
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast |
|
|
|
|
{ |
|
|
|
|
Date = startDate.AddDays(index), |
|
|
|
|
TemperatureC = Random.Shared.Next(-20, 55), |
|
|
|
|
Summary = summaries[Random.Shared.Next(summaries.Length)] |
|
|
|
|
}).ToArray(); |
|
|
|
|
await LoadForecasts(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private class WeatherForecast |
|
|
|
|
private async Task LoadForecasts() |
|
|
|
|
{ |
|
|
|
|
public DateOnly Date { get; set; } |
|
|
|
|
public int TemperatureC { get; set; } |
|
|
|
|
public string? Summary { get; set; } |
|
|
|
|
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine("Call Forecasts"); |
|
|
|
|
forecasts = await ForecastService.GetForecastsAsync(); |
|
|
|
|
Console.WriteLine($"Received {forecasts.Count()} reulsts"); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine($"Error fetching data: {ex.Message}"); |
|
|
|
|
} |
|
|
|
|
finally |
|
|
|
|
{ |
|
|
|
|
isLoading = false; |
|
|
|
|
Console.WriteLine("Call StateHasChanged"); |
|
|
|
|
StateHasChanged(); |
|
|
|
|
Console.WriteLine("End StateHasChanged"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |