refactor: move Mastodon status to partial

This commit is contained in:
Oliver Booth 2024-05-05 13:48:01 +01:00
parent 2ec2c0befc
commit 435cae95db
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
2 changed files with 43 additions and 38 deletions

View File

@ -1,49 +1,12 @@
@page
@using Humanizer
@using OliverBooth.Common.Data.Mastodon
@using OliverBooth.Common.Services
@model Index
@inject IMastodonService MastodonService
@{
ViewData["Title"] = "Blog";
IMastodonStatus latestStatus = MastodonService.GetLatestStatus();
}
<div class="card text-center mastodon-update-card">
<div class="card-body">
@Html.Raw(latestStatus.Content)
@foreach (MediaAttachment attachment in latestStatus.MediaAttachments)
{
switch (attachment.Type)
{
case AttachmentType.Audio:
<p>
<audio controls="controls" src="@attachment.Url"></audio>
</p>
break;
case AttachmentType.Video:
<p>
<video controls="controls" class="figure-img img-fluid" src="@attachment.Url"></video>
</p>
break;
case AttachmentType.Image:
case AttachmentType.GifV:
<p>
<img class="figure-img img-fluid" src="@attachment.Url">
</p>
break;
}
}
</div>
<div class="card-footer text-muted">
<abbr title="@latestStatus.CreatedAt.ToString("F")">@latestStatus.CreatedAt.Humanize()</abbr>
&bull;
<a href="@latestStatus.OriginalUri" target="_blank">View on Mastodon</a>
</div>
</div>
@await Html.PartialAsync("Partials/_MastodonStatus")
<div id="all-blog-posts">
@await Html.PartialAsync("_LoadingSpinner")

View File

@ -0,0 +1,42 @@
@using Humanizer
@using OliverBooth.Common.Data.Mastodon
@using OliverBooth.Common.Services
@inject IMastodonService MastodonService
@{
IMastodonStatus latestStatus = MastodonService.GetLatestStatus();
}
<div class="card text-center mastodon-update-card">
<div class="card-body">
@Html.Raw(latestStatus.Content)
@foreach (MediaAttachment attachment in latestStatus.MediaAttachments)
{
switch (attachment.Type)
{
case AttachmentType.Audio:
<p>
<audio controls="controls" src="@attachment.Url"></audio>
</p>
break;
case AttachmentType.Video:
<p>
<video controls="controls" class="figure-img img-fluid" src="@attachment.Url"></video>
</p>
break;
case AttachmentType.Image:
case AttachmentType.GifV:
<p>
<img class="figure-img img-fluid" src="@attachment.Url">
</p>
break;
}
}
</div>
<div class="card-footer text-muted">
<abbr title="@latestStatus.CreatedAt.ToString("F")">@latestStatus.CreatedAt.Humanize()</abbr>
&bull;
<a href="@latestStatus.OriginalUri" target="_blank">View on Mastodon</a>
</div>
</div>