diff --git a/SocialCoder.Web/Client/Components/AuthenticatedComponent.cs b/SocialCoder.Web/Client/Components/AuthenticatedComponent.cs new file mode 100644 index 0000000..017dffe --- /dev/null +++ b/SocialCoder.Web/Client/Components/AuthenticatedComponent.cs @@ -0,0 +1,23 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Components; +using SocialCoder.Web.Client.Services.Implementations; + +namespace SocialCoder.Web.Client.Components; + +public class AuthenticatedComponent : ComponentBase +{ + [Inject] protected IdentityAuthenticationStateProvider AuthProvider { get; set; } + + protected ClaimsPrincipal User { get; private set; } + protected string Name { get; private set; } + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + + var auth = await AuthProvider.GetAuthenticationStateAsync(); + + User = auth.User ?? new(); + Name = auth.User?.Identity?.Name ?? string.Empty; + } +} \ No newline at end of file diff --git a/SocialCoder.Web/Client/Shared/Components/TextEditor.razor b/SocialCoder.Web/Client/Shared/Components/TextEditor.razor new file mode 100644 index 0000000..e374470 --- /dev/null +++ b/SocialCoder.Web/Client/Shared/Components/TextEditor.razor @@ -0,0 +1,79 @@ +@inherits AuthenticatedComponent + + + + + @* Header *@ + + @Title + + + @* Text input *@ + + + + + @* Footer *@ + + + + Discard + + + @SubmitButtonText + + + + + + + +@code { + string _text; + MudTextField _field; + + [Parameter] + public int MaxCharacters { get; set; } = 1000; + + [Parameter] + public string Title { get; set; } = "Leave a Reply"; + + [Parameter] + public string SubmitButtonText { get; set; } = "Post Reply"; + + [Parameter] + public EventCallback OnSubmit { get; set; } + + [Parameter] + public EventCallback OnDiscard { get; set; } + + [Parameter] + public string PlaceholderTextFormat { get; set; } = "Hi {0}, share your thoughts here!"; + + private string PlaceholderText => string.Format(PlaceholderTextFormat, Name); + + async Task Discard() + { + _text = string.Empty; + + if (OnDiscard.HasDelegate) + await OnDiscard.InvokeAsync(); + } +} \ No newline at end of file diff --git a/SocialCoder.Web/Client/_Imports.razor b/SocialCoder.Web/Client/_Imports.razor index 33a693f..49f99ef 100644 --- a/SocialCoder.Web/Client/_Imports.razor +++ b/SocialCoder.Web/Client/_Imports.razor @@ -15,4 +15,5 @@ @using SocialCoder.Web.Client.Shared.Components @using SocialCoder.Web.Shared.Enums @using SocialCoder.Web.Client.Services.Contracts -@using SocialCoder.Web.Client.Services.Implementations \ No newline at end of file +@using SocialCoder.Web.Client.Services.Implementations +@using SocialCoder.Web.Client.Components \ No newline at end of file