RoundRunningView med nytt event "Loaded" triggas endast en gg när sidan är renderad

This commit is contained in:
2025-10-20 16:46:38 +02:00
parent 2797162a93
commit ecd3e90dbf
5 changed files with 13 additions and 48 deletions

View File

@ -31,7 +31,6 @@ public partial class InfoPopupViewModel : ObservableObject, IQueryAttributable
[RelayCommand] [RelayCommand]
private async Task Cancel() private async Task Cancel()
{ {
//await _popupService.ClosePopupAsync(Shell.Current);
_popupEvent.RaiseInfoPopupClose(PopupId); _popupEvent.RaiseInfoPopupClose(PopupId);
} }

View File

@ -23,15 +23,12 @@ public partial class ParticipantViewModel : BaseViewModel
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
IPopupService popupService, IPopupService popupService,
IPopupEventHub popupEvent IPopupEventHub popupEvent
//,
//InfoPopupViewModel infoPopupViewModel
) : base() ) : base()
{ {
_Repository = repo; _Repository = repo;
_sharingService = sharingService; _sharingService = sharingService;
_popupService = popupService; _popupService = popupService;
_popupEvent = popupEvent; _popupEvent = popupEvent;
//_infoPopupViewModel = infoPopupViewModel;
ParticipantObject = new Participant(); ParticipantObject = new Participant();
ParticipantList = new ObservableCollection<Participant>(); ParticipantList = new ObservableCollection<Participant>();
IsSaveCommandEnabled = true; IsSaveCommandEnabled = true;
@ -55,13 +52,11 @@ public partial class ParticipantViewModel : BaseViewModel
#endregion #endregion
public bool PopupVisad { get; set; }
[ObservableProperty] [ObservableProperty]
private bool isSaveCommandEnabled; private bool isSaveCommandEnabled;
public bool PopupVisad { get; set; }
#region Get Method #region Get Method
public ObservableCollection<Participant> Get() public ObservableCollection<Participant> Get()
{ {
@ -131,25 +126,6 @@ public partial class ParticipantViewModel : BaseViewModel
} }
//[RelayCommand(CanExecute = nameof(IsSaveCommandEnabled))]
//private async Task<bool> Save()
//{
// if (_Repository == null || ParticipantObject == null)
// {
// return false;
// }
// var tmpTask = _Repository.Save(ParticipantObject);
// int tmp = tmpTask.GetAwaiter().GetResult();
// if (tmp != -1)
// {
// ParticipantObject = new Participant();
// this.Get();
// await Shell.Current.GoToAsync("..");
// }
// return tmp != -1;
//}
[RelayCommand] [RelayCommand]
private void DeleteAsync(Participant pp) private void DeleteAsync(Participant pp)
{ {
@ -173,11 +149,6 @@ public partial class ParticipantViewModel : BaseViewModel
}, loadingMessage: "Laddar data..."); }, loadingMessage: "Laddar data...");
} }
//private void ClosePopup()
//{
// _popupService.ClosePopupAsync(Shell.Current).GetAwaiter().GetResult();
//}
private async void infoPopupViewModel_ClosePopupRequested(object? sender, PopupCloseEventArgs e) private async void infoPopupViewModel_ClosePopupRequested(object? sender, PopupCloseEventArgs e)
{ {
if (e.PopupId != _activePopupId) if (e.PopupId != _activePopupId)

View File

@ -51,9 +51,6 @@ public partial class RoundRunningViewModel : ObservableObject
private readonly IPopupService _popupService; private readonly IPopupService _popupService;
private readonly IPopupEventHub _popupEvent; private readonly IPopupEventHub _popupEvent;
//private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
//private ObservableCollection<Participant> _ParticipantList = new();
[ObservableProperty] [ObservableProperty]
private ObservableCollection<RoundBuilderElement> roundElements; private ObservableCollection<RoundBuilderElement> roundElements;
[ObservableProperty] [ObservableProperty]
@ -72,11 +69,9 @@ public partial class RoundRunningViewModel : ObservableObject
} }
public void Get()
public ObservableCollection<RoundBuilderElement> Get()
{ {
if (_objectMessage.CurrentGroup != null) if (_objectMessage.CurrentGroup != null)
{ {
//CurrentGroup är satt från RoundStarting ViewModel //CurrentGroup är satt från RoundStarting ViewModel
@ -109,7 +104,6 @@ public partial class RoundRunningViewModel : ObservableObject
} }
TriggerRebuild(); TriggerRebuild();
} }
return RoundElements;
} }
[RelayCommand] [RelayCommand]
@ -248,8 +242,9 @@ public partial class RoundRunningViewModel : ObservableObject
if (player.PlayerPoints > 10000) if (player.PlayerPoints > 10000)
{ {
var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId); var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId);
var oldStatus = winner.Status;
winner.Status = GamePointStatus.Winning; winner.Status = GamePointStatus.Winning;
if (playerPointsOld < 10000) if (playerPointsOld < 10000 && oldStatus != winner.Status)
{ {
Show_a_Popup( Show_a_Popup(
player.PlayerName, player.PlayerName,
@ -265,7 +260,6 @@ public partial class RoundRunningViewModel : ObservableObject
} }
} }
} }
//oldPart = element.ParticipantId;
if (!PlayerColumns.Contains(player)) if (!PlayerColumns.Contains(player))
{ {

View File

@ -203,18 +203,15 @@ public partial class RoundStartingViewModel : ObservableObject
} }
[RelayCommand] [RelayCommand]
public async Task<bool> RoundSelected(RoundBuilderElement element) public async Task RoundSelected(RoundBuilderElement element)
{ {
bool goneOk = false;
var rbGroup = GameRoundList.FirstOrDefault(g => g.GameRoundId == element.GameRoundId); var rbGroup = GameRoundList.FirstOrDefault(g => g.GameRoundId == element.GameRoundId);
Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}"); Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}");
if (rbGroup != null) if (rbGroup != null)
{ {
_objectMessage.CurrentGroup = rbGroup; _objectMessage.CurrentGroup = rbGroup;
await Shell.Current.GoToAsync("//RoundRunningView"); await Shell.Current.GoToAsync("//RoundRunningView");
goneOk = true;
} }
return goneOk;
} }
[RelayCommand] [RelayCommand]

View File

@ -10,18 +10,22 @@ public partial class RoundRunningView : ContentPage
InitializeComponent(); InitializeComponent();
ViewModel = viewModel; ViewModel = viewModel;
ViewModel.RebuildRequested += ViewModel_RebuildRequested; ViewModel.RebuildRequested += ViewModel_RebuildRequested;
this.Loaded += OnPageLoaded;
}
private void OnPageLoaded(object? sender, EventArgs e)
{
ViewModel.Get();
} }
protected override void OnAppearing() protected override void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
BindingContext = ViewModel; BindingContext = ViewModel;
ViewModel.Get();
//BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
} }
private void ViewModel_RebuildRequested(object? sender, EventArgs e) private void ViewModel_RebuildRequested(object? sender, EventArgs e)
{ {
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten