-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPersistentAttributeProductView.razor
More file actions
36 lines (29 loc) · 1.26 KB
/
PersistentAttributeProductView.razor
File metadata and controls
36 lines (29 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@inject GalacticRelicsService GalacticRelicsService
<div class="p-3">
<h3 class="display-5 mb-0">@(CategoryName ?? "All Products")</h3>
<CategoryPicker @bind-CategoryId="selectedCategoryId"
Categories="Categories" />
<ProductGrid Products="Products"
CategoryId="selectedCategoryId" />
</div>
@code {
[SupplyParameterFromPersistentComponentState]
public List<Product>? Products { get; set; }
[SupplyParameterFromPersistentComponentState]
public List<Category>? Categories { get; set; }
int? selectedCategoryId = null;
string? CategoryName => Categories?.FirstOrDefault(c => c.Id == selectedCategoryId)?.Name;
/*
* Using the [SupplyParameterFromPersistentComponentState] attribute above
* makes the values of those properties persistent across prerendering and
* interactive rendering with no additional code.
*
* By the time the code gets to this point in WASM, the properties should
* have a value from persistent state, so ??= avoids fetching the data again
*/
protected override async Task OnInitializedAsync()
{
Products ??= await GalacticRelicsService.GetProductsAsync();
Categories ??= await GalacticRelicsService.GetCategoriesAsync();
}
}