81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
namespace EnvelopeGenerator.ReceiverUI.Client.State;
|
|
|
|
/// <summary>
|
|
/// Hält den aktuellen Zustand des geladenen Umschlags.
|
|
///
|
|
/// WARUM ein eigenes State-Objekt?
|
|
/// - Mehrere Komponenten auf einer Seite brauchen die gleichen Daten
|
|
/// - Ohne State müsste jede Komponente die Daten selbst laden → doppelte API-Calls
|
|
/// - StateHasChanged() informiert automatisch alle Subscriber
|
|
///
|
|
/// PATTERN: "Observable State" — Services setzen den State, Komponenten reagieren darauf.
|
|
/// </summary>
|
|
public class EnvelopeState
|
|
{
|
|
private EnvelopePageStatus _status = EnvelopePageStatus.Loading;
|
|
private string? _errorMessage;
|
|
|
|
/// <summary>Aktueller Seitenstatus</summary>
|
|
public EnvelopePageStatus Status
|
|
{
|
|
get => _status;
|
|
private set
|
|
{
|
|
_status = value;
|
|
NotifyStateChanged();
|
|
}
|
|
}
|
|
|
|
/// <summary>Fehlermeldung (falls vorhanden)</summary>
|
|
public string? ErrorMessage
|
|
{
|
|
get => _errorMessage;
|
|
private set
|
|
{
|
|
_errorMessage = value;
|
|
NotifyStateChanged();
|
|
}
|
|
}
|
|
|
|
// --- Zustandsübergänge (öffentliche Methoden) ---
|
|
|
|
public void SetLoading() => Status = EnvelopePageStatus.Loading;
|
|
|
|
public void SetAccessCodeRequired()
|
|
{
|
|
ErrorMessage = null;
|
|
Status = EnvelopePageStatus.RequiresAccessCode;
|
|
}
|
|
|
|
public void SetTwoFactorRequired() => Status = EnvelopePageStatus.RequiresTwoFactor;
|
|
|
|
public void SetDocument() => Status = EnvelopePageStatus.ShowDocument;
|
|
|
|
public void SetError(string message)
|
|
{
|
|
ErrorMessage = message;
|
|
Status = EnvelopePageStatus.Error;
|
|
}
|
|
|
|
public void SetAlreadySigned() => Status = EnvelopePageStatus.AlreadySigned;
|
|
public void SetRejected() => Status = EnvelopePageStatus.Rejected;
|
|
public void SetNotFound() => Status = EnvelopePageStatus.NotFound;
|
|
|
|
// --- Event: Benachrichtigt Komponenten über Änderungen ---
|
|
public event Action? OnChange;
|
|
private void NotifyStateChanged() => OnChange?.Invoke();
|
|
}
|
|
|
|
/// <summary>Alle möglichen Zustände der Umschlag-Seite</summary>
|
|
public enum EnvelopePageStatus
|
|
{
|
|
Loading,
|
|
RequiresAccessCode,
|
|
RequiresTwoFactor,
|
|
ShowDocument,
|
|
AlreadySigned,
|
|
Rejected,
|
|
NotFound,
|
|
Expired,
|
|
Error
|
|
} |