diff --git a/Moonlight/Core/CoreFeature.cs b/Moonlight/Core/CoreFeature.cs index 3f8cbda7..25ada453 100644 --- a/Moonlight/Core/CoreFeature.cs +++ b/Moonlight/Core/CoreFeature.cs @@ -9,8 +9,10 @@ using Moonlight.Core.Database; using Moonlight.Core.Database.Entities; using Moonlight.Core.Implementations.Diagnose; using Moonlight.Core.Implementations.UI.Admin.AdminColumns; +using Moonlight.Core.Implementations.UI.Index; using Moonlight.Core.Interfaces; using Moonlight.Core.Interfaces.Ui.Admin; +using Moonlight.Core.Interfaces.UI.Index; using Moonlight.Core.Models; using Moonlight.Core.Models.Abstractions; using Moonlight.Core.Models.Abstractions.Feature; @@ -158,8 +160,9 @@ public class CoreFeature : MoonlightFeature await pluginService.RegisterImplementation(new FeatureDiagnoseAction()); await pluginService.RegisterImplementation(new LogDiagnoseAction()); - //Admin Page + // UI await pluginService.RegisterImplementation(new UserCount()); + await pluginService.RegisterImplementation(new GreetingMessages()); // Startup job services var startupJobService = app.Services.GetRequiredService(); diff --git a/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs b/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs new file mode 100644 index 00000000..a0c5c0e8 --- /dev/null +++ b/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs @@ -0,0 +1,20 @@ +using MoonCoreUI.Helpers; +using Moonlight.Core.Interfaces.UI.Index; +using Moonlight.Core.Models.Abstractions; +using Moonlight.Core.UI.Components.Cards; + +namespace Moonlight.Core.Implementations.UI.Index; + +public class GreetingMessages : IIndexPageComponent +{ + public Task Get() + { + var res = new UiComponent() + { + Component = ComponentHelper.FromType(), + Index = int.MinValue + }; + + return Task.FromResult(res); + } +} \ No newline at end of file diff --git a/Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs b/Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs new file mode 100644 index 00000000..50ae3976 --- /dev/null +++ b/Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs @@ -0,0 +1,8 @@ +using Moonlight.Core.Models.Abstractions; + +namespace Moonlight.Core.Interfaces.UI.Index; + +public interface IIndexPageComponent +{ + public Task Get(); +} \ No newline at end of file diff --git a/Moonlight/Core/UI/Components/Cards/TimeBasedGreetingMessages.razor b/Moonlight/Core/UI/Components/Cards/TimeBasedGreetingMessages.razor new file mode 100644 index 00000000..0d62e63f --- /dev/null +++ b/Moonlight/Core/UI/Components/Cards/TimeBasedGreetingMessages.razor @@ -0,0 +1,57 @@ +@using MoonCore.Services +@using Moonlight.Core.Configuration +@using Moonlight.Core.Services + +@inject IdentityService IdentityService +@inject ConfigService ConfigService + +
+
+ + @{ + var greeting = GetGreetingMessage(); + } + @greeting.Item1 + @IdentityService.CurrentUser.Username + @greeting.Item2 + +
+
+ +@code { + // For explanation: + // The first value is the actual message + // end second value is for question marks and so on + // + // and yes, this "feature" is kinda useless but still i wanted to implement + // it. - Masu + private (string, string) GetGreetingMessage() + { + var config = ConfigService.Get().Customisation; + + if (config.DisableTimeBasedGreetingMessages) + return ("Welcome back, ", ""); + + var time = DateTime.UtcNow.AddHours(config.GreetingTimezoneDifference); + + if (time.Hour >= 23 || time.Hour < 5) + return ("\ud83d\ude34 Still awake, ", "?"); + + if (time.Hour >= 5 && time.Hour < 10) + return ("\ud83d\ude04 Good morning, ", ""); + + if (time.Hour >= 10 && time.Hour < 14) + return ("\u2600\ufe0f Have a nice day, ", ""); + + if (time.Hour >= 14 && time.Hour < 16) + return ("\ud83d\ude03 Good afternoon, ", ""); + + if (time.Hour >= 16 && time.Hour < 22) + return ("\ud83c\udf25\ufe0f Have a nice evening, ", ""); + + if (time.Hour >= 22 && time.Hour < 23) + return ("\ud83c\udf19 Sleep well, ", ""); + + return ("Welcome back ", ""); + } +} \ No newline at end of file diff --git a/Moonlight/Core/UI/Views/Index.razor b/Moonlight/Core/UI/Views/Index.razor index 80e3838b..bc43335b 100644 --- a/Moonlight/Core/UI/Views/Index.razor +++ b/Moonlight/Core/UI/Views/Index.razor @@ -1,60 +1,33 @@ @page "/" - +@using Moonlight.Core.Interfaces.UI.Index +@using Moonlight.Core.Models.Abstractions @using Moonlight.Core.Services -@using MoonCore.Services -@using Moonlight.Core.Configuration -@inject IdentityService IdentityService -@inject ConfigService ConfigService - -
-
- - @{ - var greeting = GetGreetingMessage(); - } - @greeting.Item1 - @IdentityService.CurrentUser.Username - @greeting.Item2 - -
-
+@inject PluginService PluginService + + @foreach (var component in Components.OrderBy(x => x.Index)) + { +
+ @component.Component +
+ } +
+ @code { - // For explanation: - // The first value is the actual message - // end second value is for question marks and so on - // - // and yes, this "feature" is kinda useless but still i wanted to implement - // it. - Masu - private (string, string) GetGreetingMessage() + private List Components = new(); + + + private async Task Load(LazyLoader arg) { - var config = ConfigService.Get().Customisation; + await arg.SetText("Loading..."); - if (config.DisableTimeBasedGreetingMessages) - return ("Welcome back, ", ""); + var implementations = await PluginService.GetImplementations(); - var time = DateTime.UtcNow.AddHours(config.GreetingTimezoneDifference); - - if (time.Hour >= 23 || time.Hour < 5) - return ("\ud83d\ude34 Still awake, ", "?"); - - if (time.Hour >= 5 && time.Hour < 10) - return ("\ud83d\ude04 Good morning, ", ""); - - if (time.Hour >= 10 && time.Hour < 14) - return ("\u2600\ufe0f Have a nice day, ", ""); - - if (time.Hour >= 14 && time.Hour < 16) - return ("\ud83d\ude03 Good afternoon, ", ""); - - if (time.Hour >= 16 && time.Hour < 22) - return ("\ud83c\udf25\ufe0f Have a nice evening, ", ""); - - if (time.Hour >= 22 && time.Hour < 23) - return ("\ud83c\udf19 Sleep well, ", ""); - - return ("Welcome back ", ""); + foreach (var implementation in implementations) + { + Components.Add(await implementation.Get()); + } } } \ No newline at end of file