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 public class DependenciesPage : PageBase
{ {
private DependenciesPage()
{
}
public static DependenciesPage Instance { get; } = new();
private DependenciesStore _store; private DependenciesStore _store;
private DependenciesState _state; private DependenciesState _state;
@ -48,7 +54,7 @@ public class DependenciesPage : PageBase
canvas.Draw(layout); canvas.Draw(layout);
} }
public void LoadDependencies() public override void Load()
{ {
Initial(); Initial();
var projects = _state.Dashboard.GetContent(); var projects = _state.Dashboard.GetContent();

View File

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

View File

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

View File

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

View File

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