Refactor StundenViewModel: simplify Title property, make RefreshProperties public, and update startup logic in StundenPage to refresh data after login.

This commit is contained in:
2025-12-26 17:39:12 +01:00
parent 5148280c36
commit a4f586d445
2 changed files with 15 additions and 15 deletions

View File

@@ -51,13 +51,7 @@ public partial class StundenViewModel : ObservableObject, IQueryAttributable, IN
/// </summary>
[ObservableProperty] private List<DayTime> dayTimes = new List<DayTime>();
/// <summary>
/// Der Titel der Stundenübersicht ist der aktuelle Benutzername
/// </summary>
public string Title {
get => _settings.Name + " " + _settings.Surname;
set;
}
public string Title => _settings.Name + " " + _settings.Surname;
[ObservableProperty] private Hours hours;
@@ -181,13 +175,13 @@ public partial class StundenViewModel : ObservableObject, IQueryAttributable, IN
// Task task = LoadDay(DateTime.Today);
// Beim Startup NICHT direkt im CTOR laden (kann Startup/Navigation blockieren)
// Stattdessen via Dispatcher "nach" dem Aufbau starten:
MainThread.BeginInvokeOnMainThread(async () => {
try {
await LoadDay(DateTime.Today);
} catch (Exception ex) {
AlertEvent?.Invoke(this, ex.Message);
}
});
// MainThread.BeginInvokeOnMainThread(async () => {
// try {
// await LoadDay(DateTime.Today);
// } catch (Exception ex) {
// AlertEvent?.Invoke(this, ex.Message);
// }
// });
}
@@ -338,7 +332,7 @@ public partial class StundenViewModel : ObservableObject, IQueryAttributable, IN
/// <summary>
/// Refreshes all properties
/// </summary>
private void RefreshProperties() {
public void RefreshProperties() {
OnPropertyChanged(nameof(Hours));
OnPropertyChanged(nameof(Title));
OnPropertyChanged(nameof(Nominal));

View File

@@ -58,6 +58,12 @@ public partial class StundenPage : ContentPage {
} catch (Exception ex) {
await DisplayAlert("Fehler:", ex.Message, "OK");
}
} else {
// Wenn eingeloggt, sicherstellen dass die Daten aktuell sind (besonders nach dem Login)
if (BindingContext is StundenViewModel vm) {
vm.RefreshProperties(); // Aktualisiert den Titel (Name/Vorname)
await vm.LoadDay(vm.DateToday);
}
}
}