Skip to content

Commit 7ccdc01

Browse files
committed
Revert "Undo samples"
This reverts commit 1d90ea3.
1 parent ef9314c commit 7ccdc01

File tree

7 files changed

+53
-8
lines changed

7 files changed

+53
-8
lines changed

src/Components/Components/test/ComponentStatePersistenceManagerFilteringTests.cs

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using BlazorUnitedApp.Client.Data;
5+
using BlazorUnitedApp.Client.Pages;
46
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
57

68
var builder = WebAssemblyHostBuilder.CreateDefault(args);
79

10+
builder.Services.AddSingleton<ClientWeatherForecastService>();
11+
812
await builder.Build().RunAsync();

src/Components/Samples/BlazorUnitedApp/Data/WeatherForecastService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ public class WeatherForecastService
1010
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
1111
};
1212

13-
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
13+
public async Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
1414
{
15-
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
15+
await Task.Yield();
16+
return await Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
1617
{
1718
Date = startDate.AddDays(index),
1819
TemperatureC = Random.Shared.Next(-20, 55),

src/Components/Samples/BlazorUnitedApp/Pages/FetchData.razor

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
@page "/fetchdata"
1+
@page "/fetchdata/"
22
@using BlazorUnitedApp.Data
33
@inject WeatherForecastService ForecastService
4+
@inject NavigationManager NavigationManager
5+
@rendermode InteractiveServer
46

57
<PageTitle>Weather forecast</PageTitle>
68

79
<h1>Weather forecast</h1>
810

911
<p>This component demonstrates fetching data from a service.</p>
1012

11-
@if (forecasts == null)
13+
@if (Forecasts == null)
1214
{
1315
<p><em>Loading...</em></p>
1416
}
@@ -24,7 +26,7 @@ else
2426
</tr>
2527
</thead>
2628
<tbody>
27-
@foreach (var forecast in forecasts)
29+
@foreach (var forecast in Forecasts)
2830
{
2931
<tr>
3032
<td>@forecast.Date.ToShortDateString()</td>
@@ -37,11 +39,41 @@ else
3739
</table>
3840
}
3941

42+
<p>Current Url = @Page</p>
43+
44+
<ul>
45+
<li>
46+
<a href="fetchdata/?page=0">Page 0</a>
47+
</li>
48+
<li>
49+
<a href="fetchdata/?page=1">Page 1</a>
50+
</li>
51+
<li>
52+
<a href="fetchdata/?page=2">Page 2</a>
53+
</li>
54+
</ul>
55+
4056
@code {
41-
private WeatherForecast[]? forecasts;
57+
[PersistentState]
58+
[UpdateStateOnEnhancedNavigation(true)]
59+
public WeatherForecast[]? Forecasts { get; set; }
60+
61+
public string Page { get; set; } = "";
4262

4363
protected override async Task OnInitializedAsync()
4464
{
45-
forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
65+
// Extract the page from the query string
66+
var uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
67+
var query = System.Web.HttpUtility.ParseQueryString(uri.Query);
68+
var pageParam = query["page"];
69+
int pageIndex = 1 + (int.TryParse(pageParam, out int parsedPage) ? parsedPage : 0);
70+
pageIndex *= 7;
71+
72+
Forecasts ??= await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now).AddDays(pageIndex));
73+
}
74+
75+
protected override void OnParametersSet()
76+
{
77+
Page = NavigationManager.Uri;
4678
}
4779
}

src/Components/Samples/BlazorUnitedApp/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using BlazorUnitedApp;
5+
using BlazorUnitedApp.Client.Data;
56
using BlazorUnitedApp.Data;
67

78
var builder = WebApplication.CreateBuilder(args);
@@ -12,6 +13,7 @@
1213
.AddInteractiveServerComponents();
1314

1415
builder.Services.AddSingleton<WeatherForecastService>();
16+
builder.Services.AddSingleton<ClientWeatherForecastService>();
1517

1618
var app = builder.Build();
1719

@@ -30,6 +32,7 @@
3032

3133
app.MapStaticAssets();
3234
app.MapRazorComponents<App>()
35+
.AddAdditionalAssemblies(typeof(BlazorUnitedApp.Client.Pages.ClientFetchData).Assembly)
3336
.AddInteractiveServerRenderMode()
3437
.AddInteractiveWebAssemblyRenderMode();
3538

src/Components/Samples/BlazorUnitedApp/Routes.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Router AppAssembly="@typeof(App).Assembly">
1+
<Router AppAssembly="@typeof(App).Assembly" AdditionalAssemblies="[typeof(BlazorUnitedApp.Client.Pages.ClientFetchData).Assembly]">
22
<Found Context="routeData">
33
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
44
<FocusOnNavigate RouteData="@routeData" Selector="h1" />

src/Components/Samples/BlazorUnitedApp/Shared/NavMenu.razor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
<span class="bi bi-list-nested" aria-hidden="true"></span> Web assembly
3030
</NavLink>
3131
</div>
32+
<div class="nav-item px-3">
33+
<NavLink class="nav-link" href="clientfetchdata">
34+
<span class="bi bi-list-nested" aria-hidden="true"></span> Client Fetch Data
35+
</NavLink>
36+
</div>
3237
</nav>
3338
</div>
3439

0 commit comments

Comments
 (0)