Do page singletones.

This commit is contained in:
Kolosov Alexandr 2024-06-14 17:05:05 +05:00
parent d7d2fcd0a6
commit 044618e690
5 changed files with 47 additions and 19 deletions

View File

@ -10,6 +10,12 @@ public record DependenciesState(HeaderContainer Header, DashboardContainer Dashb
public class DependenciesPage : PageBase
{
private DependenciesPage()
{
}
public static DependenciesPage Instance { get; } = new();
private DependenciesStore _store;
private DependenciesState _state;
@ -48,7 +54,7 @@ public class DependenciesPage : PageBase
canvas.Draw(layout);
}
public void LoadDependencies()
public override void Load()
{
Initial();
var projects = _state.Dashboard.GetContent();

View File

@ -6,4 +6,5 @@ interface IPage
void Initial();
void Render();
void Bind();
void Load();
}

View File

@ -12,6 +12,8 @@ public abstract class PageBase : IPage
Render();
}
public abstract void Load();
public abstract void Initial();
public abstract void Render();

View File

@ -10,6 +10,12 @@ namespace TUI.Pages;
public class WelcomePage : PageBase
{
private WelcomePage()
{
}
public static WelcomePage Instance { get; } = new();
public override void Initial()
{
}
@ -30,7 +36,11 @@ public class WelcomePage : PageBase
canvas.Draw(layout);
}
public override void Load()
{
}
public override void Bind()
{
}

View File

@ -4,14 +4,12 @@
Console.Clear();
Console.CursorVisible = false;
// var settings = Settings.Init();
var welcomePage = new WelcomePage();
var welcomePage = WelcomePage.Instance;
welcomePage.Open();
Thread.Sleep(500);
var dependenciesPage = new DependenciesPage();
dependenciesPage.Open();
IPage currentPage = DependenciesPage.Instance;
currentPage.Open();
ConsoleKeyInfo? key = null;
@ -19,19 +17,32 @@ ConsoleKeyInfo? key = null;
var waitCommand = true;
do
{
if (key?.Key == ConsoleKey.Q)
switch (key?.Key)
{
waitCommand = false;
continue;
case ConsoleKey.Q:
waitCommand = false;
break;
case ConsoleKey.R:
key = null;
currentPage.Load();
break;
case ConsoleKey.D1:
key = null;
currentPage = DependenciesPage.Instance;
Console.Clear();
currentPage.Render();
break;
case ConsoleKey.D0:
key = null;
currentPage = WelcomePage.Instance;
Console.Clear();
currentPage.Render();
break;
default:
key = Console.ReadKey(true);
break;
}
if (key?.Key == ConsoleKey.R)
{
dependenciesPage.LoadDependencies();
key = null;
continue;
}
//
// if (display.CommandLine.IsFocused)
// {
// switch (key.Key)
@ -67,8 +78,6 @@ do
// break;
// }
// }
key = Console.ReadKey(true);
} while (waitCommand);
Console.Clear();