From 044618e690d349b456c16b097d8114ee3bf9bbbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=BE=D1=81=D0=BE=D0=B2?= Date: Fri, 14 Jun 2024 17:05:05 +0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Do=20page=20singletones.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TUI/Pages/DependenciesPage.cs | 8 +++++- src/TUI/Pages/IPage.cs | 1 + src/TUI/Pages/PageBase.cs | 2 ++ src/TUI/Pages/WelcomePage.cs | 12 ++++++++- src/TUI/Program.cs | 43 +++++++++++++++++++------------ 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/TUI/Pages/DependenciesPage.cs b/src/TUI/Pages/DependenciesPage.cs index c558011..71b84f6 100644 --- a/src/TUI/Pages/DependenciesPage.cs +++ b/src/TUI/Pages/DependenciesPage.cs @@ -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(); diff --git a/src/TUI/Pages/IPage.cs b/src/TUI/Pages/IPage.cs index 13894e8..61028ef 100644 --- a/src/TUI/Pages/IPage.cs +++ b/src/TUI/Pages/IPage.cs @@ -6,4 +6,5 @@ interface IPage void Initial(); void Render(); void Bind(); + void Load(); } \ No newline at end of file diff --git a/src/TUI/Pages/PageBase.cs b/src/TUI/Pages/PageBase.cs index 2c9e357..91aa0e7 100644 --- a/src/TUI/Pages/PageBase.cs +++ b/src/TUI/Pages/PageBase.cs @@ -12,6 +12,8 @@ public abstract class PageBase : IPage Render(); } + public abstract void Load(); + public abstract void Initial(); public abstract void Render(); diff --git a/src/TUI/Pages/WelcomePage.cs b/src/TUI/Pages/WelcomePage.cs index 0c651d2..a556b65 100644 --- a/src/TUI/Pages/WelcomePage.cs +++ b/src/TUI/Pages/WelcomePage.cs @@ -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() { } diff --git a/src/TUI/Program.cs b/src/TUI/Program.cs index 0f91ded..682e0a6 100644 --- a/src/TUI/Program.cs +++ b/src/TUI/Program.cs @@ -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(); \ No newline at end of file