Skip to content

Commit

Permalink
Async Read a Inicializace
Browse files Browse the repository at this point in the history
  • Loading branch information
Hijtec committed Nov 20, 2024
1 parent fe980f6 commit 42f3dbf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ToDoList/src/ToDoList.Frontend/Clients/IToDoItemsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace ToDoList.Frontend.Clients;

public interface IToDoItemsClient
{
public List<ToDoItemView> ReadItems();
public Task<List<ToDoItemView>> ReadItemsAsync();
}
6 changes: 3 additions & 3 deletions ToDoList/src/ToDoList.Frontend/Clients/ToDoItemsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace ToDoList.Frontend.Clients;

public class ToDoItemsClient(HttpClient httpClient) : IToDoItemsClient
{
public List<ToDoItemView> ReadItems()
public async Task<List<ToDoItemView>> ReadItemsAsync()
{
var toDoItemsView = new List<ToDoItemView>();
var response = httpClient.GetFromJsonAsync<List<ToDoItemGetResponseDto>>("api/ToDoItems");
var response = await httpClient.GetFromJsonAsync<List<ToDoItemGetResponseDto>>("api/ToDoItems");

toDoItemsView = response.Result.Select(dto => new ToDoItemView
toDoItemsView = response.Select(dto => new ToDoItemView

Check warning on line 13 in ToDoList/src/ToDoList.Frontend/Clients/ToDoItemsClient.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'IEnumerable<ToDoItemView> Enumerable.Select<ToDoItemGetResponseDto, ToDoItemView>(IEnumerable<ToDoItemGetResponseDto> source, Func<ToDoItemGetResponseDto, ToDoItemView> selector)'.
{
ToDoItemId = dto.Id,
Name = dto.Name,
Expand Down
26 changes: 17 additions & 9 deletions ToDoList/src/ToDoList.Frontend/Components/Dashboard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,30 @@
<td></td>
</tr>

@foreach (var toDoItem in toDoItems)
@if (toDoItems is null)
{
<tr>
<td>@toDoItem.ToDoItemId</td>
<td>@toDoItem.Name</td>
<td>@toDoItem.Description</td>
<td>@toDoItem.IsCompleted</td>
</tr>
<p>Nacitam...</p>
}

@if (toDoItems is not null)
{
@foreach (var toDoItem in toDoItems)
{
<tr>
<td>@toDoItem.ToDoItemId</td>
<td>@toDoItem.Name</td>
<td>@toDoItem.Description</td>
<td>@toDoItem.IsCompleted</td>
</tr>
}
}
</table>

@code
{
protected override void OnInitialized()
protected override async Task OnInitializedAsync()
{
toDoItems = ToDoItemsClient.ReadItems();
toDoItems = await ToDoItemsClient.ReadItemsAsync();
}

private List<ToDoItemView>? toDoItems;
Expand Down

0 comments on commit 42f3dbf

Please sign in to comment.