130 lines
4.0 KiB
Plaintext
130 lines
4.0 KiB
Plaintext
@using RobotNet10.ScriptEditor.Clients
|
|
@using RobotNet10.ScriptEditor.Components
|
|
@using RobotNet10.ScriptEngine.Shared
|
|
@using MudBlazor
|
|
@inject ScriptManagerHubClient ScriptManagerClient
|
|
@inject ISnackbar Snackbar
|
|
@implements IDisposable
|
|
|
|
<SidebarAccordionItem TabName="missions" Label="MISSIONS">
|
|
<HeaderActions>
|
|
<IconButton Icon="refresh" Title="Refresh" OnClick="HandleRefresh" />
|
|
</HeaderActions>
|
|
<ChildContent>
|
|
@if (_missions == null || _missions.Count == 0)
|
|
{
|
|
<div class="missions-empty-state">
|
|
<MudText Typo="Typo.body2" Class="text-secondary">
|
|
@if (_isLoading)
|
|
{
|
|
<span>Loading missions...</span>
|
|
}
|
|
else if (_currentState == ScriptEngineState.Ready || _currentState == ScriptEngineState.Running)
|
|
{
|
|
<span>No missions available</span>
|
|
}
|
|
else
|
|
{
|
|
<span>Missions available when engine is Ready or Running</span>
|
|
}
|
|
</MudText>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<div class="missions-list">
|
|
@foreach (var mission in _missions)
|
|
{
|
|
<MissionItem @key="@mission.Name" Mission="@mission" />
|
|
}
|
|
</div>
|
|
}
|
|
</ChildContent>
|
|
</SidebarAccordionItem>
|
|
|
|
@code {
|
|
private List<ScriptMissionDto> _missions = new();
|
|
private ScriptEngineState _currentState = ScriptEngineState.Initializing;
|
|
private bool _isLoading = false;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
// Subscribe to state changes
|
|
ScriptManagerClient.StateChanged += OnStateChanged;
|
|
_currentState = ScriptManagerClient.State;
|
|
|
|
// Load missions if state is already Ready or Running
|
|
if (_currentState == ScriptEngineState.Ready || _currentState == ScriptEngineState.Running)
|
|
{
|
|
_ = LoadMissionsAsync();
|
|
}
|
|
}
|
|
|
|
protected override void OnAfterRender(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
// Ensure we have the latest state
|
|
_currentState = ScriptManagerClient.State;
|
|
if (_currentState == ScriptEngineState.Ready || _currentState == ScriptEngineState.Running)
|
|
{
|
|
_ = LoadMissionsAsync();
|
|
}
|
|
}
|
|
}
|
|
|
|
private async void OnStateChanged(ScriptEngineState newState)
|
|
{
|
|
_currentState = newState;
|
|
|
|
if (newState == ScriptEngineState.Ready || newState == ScriptEngineState.Running)
|
|
{
|
|
await LoadMissionsAsync();
|
|
}
|
|
else
|
|
{
|
|
// Clear missions when not in Ready or Running state
|
|
_missions.Clear();
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private async Task LoadMissionsAsync()
|
|
{
|
|
if (!ScriptManagerClient.IsConnected)
|
|
return;
|
|
|
|
try
|
|
{
|
|
_isLoading = true;
|
|
StateHasChanged();
|
|
|
|
var missions = await ScriptManagerClient.GetScriptMissionsAsync();
|
|
_missions = missions?.ToList() ?? new List<ScriptMissionDto>();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"Failed to load missions: {ex.Message}", Severity.Error);
|
|
_missions = new List<ScriptMissionDto>();
|
|
}
|
|
finally
|
|
{
|
|
_isLoading = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private async Task HandleRefresh(MouseEventArgs e)
|
|
{
|
|
if (_currentState == ScriptEngineState.Ready || _currentState == ScriptEngineState.Running)
|
|
{
|
|
await LoadMissionsAsync();
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
ScriptManagerClient.StateChanged -= OnStateChanged;
|
|
}
|
|
}
|