Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 86aaa37

Browse files
committed
Add navigation support and change initialization logic
1 parent a3447e2 commit 86aaa37

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/GitHub.App/Controllers/UIController.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace GitHub.Controllers
2222
{
2323
using App.Factories;
2424
using System.Globalization;
25+
using System.Windows.Controls;
2526
using StateMachineType = StateMachine<UIViewType, UIController.Trigger>;
2627

2728
/*
@@ -260,18 +261,9 @@ public void Jump(ViewWithData where)
260261
if (where.Flow != mainFlow)
261262
return;
262263

263-
if (uiStateMachine.IsInState(where.ViewType))
264-
{
265-
var objs = GetObjectsForFlow(activeFlow);
266-
var pair = objs[where.ViewType];
267-
pair.ViewModel.Initialize(where);
268-
}
269-
else
270-
{
271-
requestedTarget = where;
272-
if (activeFlow == where.Flow)
273-
Fire(Trigger.Next, where);
274-
}
264+
requestedTarget = where;
265+
if (activeFlow == where.Flow)
266+
Fire(Trigger.Next, where);
275267
}
276268

277269
public void Stop()
@@ -588,7 +580,7 @@ void RunView(UIViewType viewType, LoadDirection direction, ViewWithData arg = nu
588580
requestedTarget = null;
589581
}
590582

591-
bool firstTime = CreateViewAndViewModel(viewType);
583+
bool firstTime = CreateViewAndViewModel(viewType, arg);
592584
var view = GetObjectsForFlow(activeFlow)[viewType].View;
593585
transition.OnNext(new LoadData
594586
{
@@ -606,16 +598,14 @@ void RunView(UIViewType viewType, LoadDirection direction, ViewWithData arg = nu
606598
if (!firstTime)
607599
return;
608600

609-
SetupView(viewType, view, arg);
601+
SetupView(viewType, view);
610602
}
611603

612-
void SetupView(UIViewType viewType, IView view, ViewWithData arg = null)
604+
void SetupView(UIViewType viewType, IView view)
613605
{
614606
var list = GetObjectsForFlow(activeFlow);
615607
var pair = list[viewType];
616608

617-
pair.ViewModel.Initialize(arg);
618-
619609
// 2FA is set up when login is set up, so nothing to do
620610
if (viewType == UIViewType.TwoFactor)
621611
return;
@@ -670,7 +660,7 @@ void SetupView(UIViewType viewType, IView view, ViewWithData arg = null)
670660
/// </summary>
671661
/// <param name="viewType"></param>
672662
/// <returns>true if the View/ViewModel didn't exist and had to be created</returns>
673-
bool CreateViewAndViewModel(UIViewType viewType)
663+
bool CreateViewAndViewModel(UIViewType viewType, [AllowNull]ViewWithData data = null)
674664
{
675665
var list = GetObjectsForFlow(activeFlow);
676666
if (viewType == UIViewType.Login)
@@ -688,12 +678,16 @@ bool CreateViewAndViewModel(UIViewType viewType)
688678
{
689679
var d = list[viewType];
690680
if (d.View.ViewModel == null)
681+
{
682+
d.ViewModel.Initialize(data);
691683
d.View.DataContext = d.ViewModel;
684+
}
692685
}
693686

694687
if (!list.ContainsKey(viewType))
695688
{
696689
var d = factory.CreateViewAndViewModel(viewType);
690+
d.ViewModel.Initialize(data);
697691
d.View.DataContext = d.ViewModel;
698692
list.Add(viewType, d);
699693
return true;

0 commit comments

Comments
 (0)