diff --git a/Moonlight/App/Models/Forms/Community/AddPostForm.cs b/Moonlight/App/Models/Forms/Community/AddPostForm.cs new file mode 100644 index 00000000..c4dded80 --- /dev/null +++ b/Moonlight/App/Models/Forms/Community/AddPostForm.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; + +namespace Moonlight.App.Models.Forms.Community; + +public class AddPostForm +{ + [Required(ErrorMessage = "You need to enter a title")] + [MaxLength(40, ErrorMessage = "The title can only be 40 characters long")] + [MinLength(8, ErrorMessage = "The title must at least have 8 characters")] + public string Title { get; set; } = ""; + + [Required(ErrorMessage = "You need to enter post content")] + [MaxLength(2048, ErrorMessage = "The post content can only be 2048 characters long")] + [MinLength(8, ErrorMessage = "The post content must at least have 8 characters")] + public string Content { get; set; } = ""; +} \ No newline at end of file diff --git a/Moonlight/App/Services/Interop/ModalService.cs b/Moonlight/App/Services/Interop/ModalService.cs index 45d1984f..fcff73e2 100644 --- a/Moonlight/App/Services/Interop/ModalService.cs +++ b/Moonlight/App/Services/Interop/ModalService.cs @@ -11,11 +11,11 @@ public class ModalService JsRuntime = jsRuntime; } - public async Task Show(string id) + public async Task Show(string id, bool focus = true) // Focus can be specified to fix issues with other components { try { - await JsRuntime.InvokeVoidAsync("moonlight.modals.show", id); + await JsRuntime.InvokeVoidAsync("moonlight.modals.show", id, focus); } catch (Exception) { diff --git a/Moonlight/Shared/Components/Forms/TextEditor.razor b/Moonlight/Shared/Components/Forms/TextEditor.razor index f02e4387..54e1f59b 100644 --- a/Moonlight/Shared/Components/Forms/TextEditor.razor +++ b/Moonlight/Shared/Components/Forms/TextEditor.razor @@ -8,6 +8,13 @@ -
+
@code { [Parameter] public string InitialContent { get; set; } + + [Parameter] + public string CssClasses { get; set; } = ""; + + [Parameter] + public string Styles { get; set; } = ""; // We added this parameter to allow custom heights to be set private string Id; private bool IsInitialized = false; diff --git a/Moonlight/Shared/Components/Modals/Community/CreatePostModal.razor b/Moonlight/Shared/Components/Modals/Community/CreatePostModal.razor new file mode 100644 index 00000000..3607ed90 --- /dev/null +++ b/Moonlight/Shared/Components/Modals/Community/CreatePostModal.razor @@ -0,0 +1,64 @@ +@using Moonlight.App.Models.Forms.Community +@using Moonlight.App.Services +@using Moonlight.App.Services.Community +@using Moonlight.App.Database.Enums + +@inject PostService PostService +@inject IdentityService IdentityService +@inject ToastService ToastService + + + + + + + + + +@code +{ + [Parameter] + public Func? OnUpdate { get; set; } + + [Parameter] + public PostType PostType { get; set; } + + private AddPostForm Form = new(); + private SmartModal Modal; + + public async Task Show() + { + Form = new(); + await Modal.Show(false); + } + + private async Task Submit() + { + await PostService.Create( + IdentityService.CurrentUser, + Form.Title, + Form.Content, + PostType + ); + + await Modal.Hide(); + await ToastService.Success("Successfully created post"); + + if (OnUpdate != null) + await OnUpdate.Invoke(); + } +} \ No newline at end of file diff --git a/Moonlight/Shared/Components/Navigations/CommunityNavigation.razor b/Moonlight/Shared/Components/Navigations/CommunityNavigation.razor new file mode 100644 index 00000000..4000e033 --- /dev/null +++ b/Moonlight/Shared/Components/Navigations/CommunityNavigation.razor @@ -0,0 +1,41 @@ +
+
+

+ Post channels +

+
+
+
+
+ +
+ +
+
+
+
+ +
+
+ Events +
+
+
+
+
+ +
+
+ Projects +
+
+
+
+ +@code +{ + [Parameter] + public int Index { get; set; } +} \ No newline at end of file diff --git a/Moonlight/Shared/Components/Partials/SmartModal.razor b/Moonlight/Shared/Components/Partials/SmartModal.razor index 5697cc21..4ef560ce 100644 --- a/Moonlight/Shared/Components/Partials/SmartModal.razor +++ b/Moonlight/Shared/Components/Partials/SmartModal.razor @@ -27,12 +27,12 @@ Id = GetHashCode(); } - public async Task Show() + public async Task Show(bool focus = true) // Focus can be specified to fix issues with other components { ShouldShow = true; await InvokeAsync(StateHasChanged); - await ModalService.Show("modal" + Id); + await ModalService.Show("modal" + Id, focus); } public async Task Hide() diff --git a/Moonlight/Shared/Views/Community/Events.razor b/Moonlight/Shared/Views/Community/Events.razor new file mode 100644 index 00000000..e0e6beb4 --- /dev/null +++ b/Moonlight/Shared/Views/Community/Events.razor @@ -0,0 +1,67 @@ +@page "/community/events" + +@using Moonlight.App.Repositories +@using Moonlight.App.Database.Entities.Community +@using Microsoft.EntityFrameworkCore +@using Moonlight.App.Database.Enums +@using Moonlight.App.Models.Enums +@using Moonlight.App.Services +@using Moonlight.Shared.Components.Community +@using Moonlight.Shared.Components.Modals.Community + +@inject IdentityService IdentityService +@inject Repository PostRepository + +
+
+ + + @if (IdentityService.Permissions[Permission.AdminCommunity]) + { +
+ +
+ } +
+
+
+
+ Planned events and current happenings can be found here. + If you want to know what will happen in the future or is going on now have a look at the posts below +
+
+ +
+ + @foreach (var post in Posts) + { + +
+ } +
+
+
+
+ +@if (IdentityService.Permissions[Permission.AdminCommunity]) +{ + +} + +@code +{ + private LazyLoader LazyLoader; + private CreatePostModal CreateModal; + private Post[] Posts; + + private Task Load(LazyLoader _) + { + Posts = PostRepository + .Get() + .Include(x => x.Author) + .Where(x => x.Type == PostType.Event) + .ToArray(); + + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Community/Index.razor b/Moonlight/Shared/Views/Community/Index.razor index 65ee3da7..316e1b31 100644 --- a/Moonlight/Shared/Views/Community/Index.razor +++ b/Moonlight/Shared/Views/Community/Index.razor @@ -3,32 +3,64 @@ @using Moonlight.App.Repositories @using Moonlight.App.Database.Entities.Community @using Microsoft.EntityFrameworkCore +@using Moonlight.App.Database.Enums +@using Moonlight.App.Models.Enums +@using Moonlight.App.Services @using Moonlight.Shared.Components.Community +@using Moonlight.Shared.Components.Modals.Community @inject Repository PostRepository +@inject IdentityService IdentityService
- - @foreach (var post in Posts) +
+ + + @if (IdentityService.Permissions[Permission.AdminCommunity]) { - -
+
+ +
} - +
+
+
+
+ These announcements provide you with the latest news and information. + The posts here have been created by an admin and can contain valuable information + so consider reading it from time to time +
+
+ + + @foreach (var post in Posts) + { + +
+ } +
+
+@if (IdentityService.Permissions[Permission.AdminCommunity]) +{ + +} + @code { private LazyLoader LazyLoader; + private CreatePostModal CreateModal; private Post[] Posts; - + private Task Load(LazyLoader _) { Posts = PostRepository .Get() .Include(x => x.Author) + .Where(x => x.Type == PostType.Announcement) .ToArray(); - + return Task.CompletedTask; } -} +} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Community/Projects.razor b/Moonlight/Shared/Views/Community/Projects.razor new file mode 100644 index 00000000..ae63f7e7 --- /dev/null +++ b/Moonlight/Shared/Views/Community/Projects.razor @@ -0,0 +1,59 @@ +@page "/community/projects" + +@using Moonlight.App.Repositories +@using Moonlight.App.Database.Entities.Community +@using Microsoft.EntityFrameworkCore +@using Moonlight.App.Database.Enums +@using Moonlight.Shared.Components.Community +@using Moonlight.Shared.Components.Modals.Community + +@inject Repository PostRepository + +
+
+ + +
+ +
+
+
+
+
+ You have a interesting project or a fun game server you want to share with the community? + You can share it here. Please keep in mind to follow basic rules and dont offend anyone. + Be nice and respectful +
+
+ +
+ + @foreach (var post in Posts) + { + +
+ } +
+
+
+
+ + + +@code +{ + private LazyLoader LazyLoader; + private CreatePostModal CreateModal; + private Post[] Posts; + + private Task Load(LazyLoader _) + { + Posts = PostRepository + .Get() + .Include(x => x.Author) + .Where(x => x.Type == PostType.Project) + .ToArray(); + + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/Moonlight/wwwroot/js/moonlight.js b/Moonlight/wwwroot/js/moonlight.js index 657bc9c5..b59aeca3 100644 --- a/Moonlight/wwwroot/js/moonlight.js +++ b/Moonlight/wwwroot/js/moonlight.js @@ -23,9 +23,12 @@ window.moonlight = { } }, modals: { - show: function (id) + show: function (id, focus) { - let modal = new bootstrap.Modal(document.getElementById(id)); + let modal = new bootstrap.Modal(document.getElementById(id), { + focus: focus + }); + modal.show(); }, hide: function (id)