Skip to content

Commit

Permalink
Merge pull request #262 from pticostaricags/development
Browse files Browse the repository at this point in the history
merge "development" into "main"
  • Loading branch information
efonsecab authored Dec 20, 2024
2 parents 393da2d + e44d7fc commit cad9812
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
@attribute [Route($"{FairPlayCombined.Common.Constants.Routes.FairPlayBlogsRoutes.PublicRoutes.ViewBlogPost}/{{BlogPostId:long}}")]
@using FairPlayCombined.WebComponents.SocialMedia
@attribute [Route($"{FairPlayCombined.Common.Constants.Routes.FairPlayBlogsRoutes.PublicRoutes.ViewBlogPost}/{{BlogPostId:long}}")]
@attribute [Route($"/Public/Blog/{{BlogName}}/Post/{{BlogPostTitle}}")]

@implements IAsyncDisposable

<PageTitle>
@Localizer![ViewBlogPostTextKey]
@Localizer![ViewBlogPostTextKey] - @this.BlogPostModel?.Title
</PageTitle>

<h3>
@Localizer![ViewBlogPostTextKey]
@this.BlogPostModel?.Title
</h3>

<div style="text-align:center;">
@this.BlogPostModel?.Title
</div>
@if (this.BlogPostModel != null)
{
<div>
<SharePage Description="@this.BlogPostModel.Title" Url="@this.NavigationManager!.Uri"></SharePage>
</div>
<div style="text-align:center;">
<img src="@($"{NavigationManager!.BaseUri}api/blogpost/{this.BlogPostModel.BlogPostId}/thumbnail")" width="300" />
</div>
}
<div style="text-align:center;">
<BlazoredTextEditor ReadOnly="true" @ref="@QuillHtml" Placeholder="@String.Empty">
<ToolbarContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Blazored.TextEditor;
using FairPlayBlogs.SharedUI.Components.Pages.User;
using FairPlayCombined.Common.CustomAttributes;
using FairPlayCombined.Interfaces.FairPlayBlogs;
using FairPlayCombined.Models.FairPlayBlogs.BlogPost;
Expand All @@ -13,12 +12,18 @@ public partial class ViewBlogPost
{
[Parameter]
public long BlogPostId { get; set; }
[Parameter]
public string? BlogName { get; set; }
[Parameter]
public string? BlogPostTitle { get; set; }
[Inject]
private IBlogPostService? BlogPostService { get; set; }
[Inject]
private IToastService? ToastService { get; set; }
[Inject]
private IStringLocalizer<ViewBlogPost>? Localizer { get; set; }
[Inject]
private NavigationManager? NavigationManager { get; set; }
private readonly CancellationTokenSource cancellationTokenSource = new();
private bool IsBusy { get; set; }
private BlogPostModel? BlogPostModel { get; set; }
Expand All @@ -30,8 +35,20 @@ protected override async Task OnInitializedAsync()
{
this.IsBusy = true;
StateHasChanged();
this.BlogPostModel = await this.BlogPostService!
.GetBlogPostByIdAsync(this.BlogPostId, this.cancellationTokenSource.Token);
if (this.BlogName?.Length > 0 && this.BlogPostTitle?.Length > 0)
{
var decodedBlogName = System.Net.WebUtility.UrlDecode(this.BlogName);
var decodedBlogPostTitle = System.Net.WebUtility.UrlDecode(this.BlogPostTitle);
decodedBlogName = decodedBlogName.Replace("-", " ");
decodedBlogPostTitle = decodedBlogPostTitle.Replace("-", " ");
this.BlogPostModel = await this.BlogPostService!
.GetBlogPostByBlogNameAndPostTitleAsync(decodedBlogName, decodedBlogPostTitle, this.cancellationTokenSource.Token);
}
else
{
this.BlogPostModel = await this.BlogPostService!
.GetBlogPostByIdAsync(this.BlogPostId, this.cancellationTokenSource.Token);
}
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
</BlazoredTextEditor>
</div>
</div>
<div>
<FluentLabel Typo="Typography.Body">@Localizer![PublishTextKey]</FluentLabel>
<FluentCheckbox CheckStateChanged="OnPostStatusChanged"></FluentCheckbox>
</div>
<div>
<FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent">
@Localizer![SaveTextKey]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ await this.BlogPostService!
}
}

private void OnPostStatusChanged(bool? value)
{
if (value == true)
{
this.CreateBlogPostModel.BlogPostStatusId = (int)BlogPostStatus.Published;
}
else
{
this.CreateBlogPostModel.BlogPostStatusId = (int)BlogPostStatus.Draft;
}
}

public async ValueTask DisposeAsync()
{
await this.cancellationTokenSource.CancelAsync();
Expand All @@ -116,6 +128,8 @@ public async ValueTask DisposeAsync()
public const string PreviewTextTextKey = "PreviewTextText";
[ResourceKey(defaultValue: "Content")]
public const string ContentTextKey = "ContentText";
[ResourceKey(defaultValue:"Publish")]
public const string PublishTextKey = "PublishText";
#endregion Resource Keys
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
</span>
</strong>
</div>
<div style="text-align:center;">
@context.PreviewText
</div>
<div style="text-align:center;">
<FluentAnchor IconStart="@(new Icons.Regular.Size20.Link())"
Href="@($"{FairPlayCombined.Common.Constants.Routes.FairPlayBlogsRoutes.PublicRoutes.ViewBlogPost}/{context.BlogPostId}")">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Task<long> CreateBlogPostAsync(CreateBlogPostModel createModel,
CancellationToken cancellationToken);
Task<BlogPostModel[]> GetAllBlogPostAsync(CancellationToken cancellationToken);
Task<BlogPostModel> GetBlogPostByIdAsync(long id, CancellationToken cancellationToken);
Task<BlogPostModel?> GetBlogPostByBlogNameAndPostTitleAsync(string blogName, string blogPostTitle, CancellationToken cancellationToken);
Task DeleteBlogPostByIdAsync(long id, CancellationToken cancellationToken);
Task<PaginationOfT<BlogPostModel>> GetPaginatedBlogPostAsync(
PaginationRequest paginationRequest, CancellationToken cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ namespace FairPlayCombined.Services.FairPlayBlogs;
>]
public partial class BlogPostService : BaseService, IBlogPostService
{
public async Task<BlogPostModel?> GetBlogPostByBlogNameAndPostTitleAsync(
string blogName, string blogPostTitle, CancellationToken cancellationToken)
{
var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
var result = await dbContext.BlogPost
.Where(p => p.Blog.Name == blogName && p.Title == blogPostTitle)
.AsNoTracking()
.Select(p => new BlogPostModel
{
BlogPostId = p.BlogPostId,
BlogId = p.BlogId,
Title = p.Title,
PreviewText = p.PreviewText,
Content = p.Content,
ThumbnailPhotoId = p.ThumbnailPhotoId,
BlogPostStatusId = p.BlogPostStatusId,

})
.SingleOrDefaultAsync(cancellationToken);
return result;
}

public async Task<PaginationOfT<BlogPostModel>> GetPaginatedBlogPostByBlogIdAsync(
long blogId, PaginationRequest paginationRequest, CancellationToken cancellationToken)
{
Expand Down

0 comments on commit cad9812

Please sign in to comment.