Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OnAfterRenderAsync in ResourceLogsBase #415

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions src/Aspire.Dashboard/Components/Pages/ResourceLogsBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,43 @@ protected abstract IAsyncEnumerable<ResourceChanged<TResource>> WatchResources(
private CancellationTokenSource? _watchLogsTokenSource;
private string _status = LogStatus.Initializing;

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
_status = LoadingResourcesMessage;
}

var initialList = await GetResources(DashboardViewModelService);

foreach (var result in initialList)
{
_resourceNameMapping[result.Name] = result;
}

if (ResourceName is not null)
{
_selectedResource = initialList.FirstOrDefault(c => string.Equals(ResourceName, c.Name, StringComparison.Ordinal));
}
else if (initialList.Count > 0)
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_selectedResource = initialList[0];
}
var initialList = await GetResources(DashboardViewModelService);

await LoadLogsAsync();
foreach (var result in initialList)
{
_resourceNameMapping[result.Name] = result;
}

_ = Task.Run(async () =>
{
await foreach (var resourceChanged in WatchResources(DashboardViewModelService, initialList.Select(t => t.NamespacedName), _watchContainersTokenSource.Token))
if (ResourceName is not null)
{
_selectedResource = initialList.FirstOrDefault(c => string.Equals(ResourceName, c.Name, StringComparison.Ordinal));
}
else if (initialList.Count > 0)
{
await OnResourceListChangedAsync(resourceChanged.ObjectChangeType, resourceChanged.Resource);
_selectedResource = initialList[0];
}
});

await LoadLogsAsync();

_ = Task.Run(async () =>
{
await foreach (var resourceChanged in WatchResources(DashboardViewModelService, initialList.Select(t => t.NamespacedName), _watchContainersTokenSource.Token))
{
await OnResourceListChangedAsync(resourceChanged.ObjectChangeType, resourceChanged.Resource);
}
});

StateHasChanged();
}
}

private Task ClearLogsAsync()
Expand Down