Add project files.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
@page "/weather"
|
||||
@attribute [StreamRendering]
|
||||
|
||||
<PageTitle>Weather</PageTitle>
|
||||
|
||||
<h1 class="text-3xl font-bold mb-4">Weather</h1>
|
||||
|
||||
<p class="mb-6 text-gray-700">This component demonstrates showing data.</p>
|
||||
|
||||
@if (forecasts == null)
|
||||
{
|
||||
<p class="italic text-gray-500">Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="overflow-x-auto shadow-sm ring-1 ring-black ring-opacity-5 rounded-lg bg-white">
|
||||
<table class="min-w-full text-left border-collapse">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3 border-b border-gray-300 text-sm font-semibold text-gray-900">Date</th>
|
||||
<th scope="col" class="px-6 py-3 border-b border-gray-300 text-sm font-semibold text-gray-900" aria-label="Temperature in Celsius">Temp. (C)</th>
|
||||
<th scope="col" class="px-6 py-3 border-b border-gray-300 text-sm font-semibold text-gray-900" aria-label="Temperature in Fahrenheit">Temp. (F)</th>
|
||||
<th scope="col" class="px-6 py-3 border-b border-gray-300 text-sm font-semibold text-gray-900">Summary</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-200">
|
||||
@foreach (var forecast in forecasts)
|
||||
{
|
||||
<tr class="hover:bg-gray-50 transition-colors">
|
||||
<td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">@forecast.Date.ToShortDateString()</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">@forecast.TemperatureC</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">@forecast.TemperatureF</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">@forecast.Summary</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private WeatherForecast[]? forecasts;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user