Files
Nexus.Reader/src/NexusReader.UI.Shared/Services/KnowledgeGraphService.cs
T

44 lines
1.1 KiB
C#

using NexusReader.Application.Queries.Graph;
namespace NexusReader.UI.Shared.Services;
public sealed class KnowledgeGraphService : IKnowledgeGraphService
{
public GraphDataDto? CurrentGraphData { get; private set; }
public string? ActiveNodeId { get; private set; }
public bool IsLoading { get; private set; }
public event Action? OnGraphUpdated;
public event Action<string>? OnActiveNodeChanged;
public event Action<bool>? OnLoadingChanged;
public void UpdateGraph(GraphDataDto newData)
{
CurrentGraphData = newData;
IsLoading = false;
OnLoadingChanged?.Invoke(false);
OnGraphUpdated?.Invoke();
}
public void SetActiveNode(string nodeId)
{
if (ActiveNodeId == nodeId) return;
ActiveNodeId = nodeId;
OnActiveNodeChanged?.Invoke(nodeId);
}
public void SetLoading(bool isLoading)
{
IsLoading = isLoading;
OnLoadingChanged?.Invoke(isLoading);
}
public void Clear()
{
CurrentGraphData = null;
ActiveNodeId = null;
IsLoading = false;
OnGraphUpdated?.Invoke();
}
}