Skip to content

Commit

Permalink
implement aside on main pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Mar 14, 2024
1 parent 50cc5fc commit 2183e75
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 158 deletions.
2 changes: 1 addition & 1 deletion MyApp/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ loadMetadata({

<Header />

<div class="min-h-screen">
<div class="min-h-screen sm:px-4 lg:px-6">
<main role="main">
@Body
</main>
Expand Down
23 changes: 14 additions & 9 deletions MyApp/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@

<PageTitle>pvq.app</PageTitle>

@if (Html != null)
{
@BlazorHtml.Raw(Html)
}
else
{
<HomeTab Tab=@Tab Posts=@Posts />
}

<div class="flex flex-wrap justify-center">
<div>
@if (Html != null)
{
@BlazorHtml.Raw(Html)
}
else
{
<HomeTab Tab=@Tab Posts=@Posts />
}
</div>
<Aside />
</div>

@code {
string? Html;

Expand Down
108 changes: 54 additions & 54 deletions MyApp/Components/Pages/Questions/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,75 @@
@inject IDbConnectionFactory DbFactory

<PageTitle>@Title</PageTitle>

@if (posts != null)
{
<div class="mt-8 mb-20 mx-auto max-w-5xl px-4">
<div class="mb-4">
<h1 class="text-4xl font-bold tracking-tight text-gray-900 dark:text-gray-100 sm:text-5xl">
<span class="block xl:inline">@Title</span>
</h1>
</div>


@if (posts.Count > 0)
<div class="flex flex-wrap justify-center">
<div>
@if (posts != null)
{
<div class="py-2 flex justify-end">
<QuestionViewTabs Path=@Path Tabs=@Tabs Active=@Tab/>
</div>
<div class="mt-8 mb-20 mx-auto sm:max-w-4xl xl:max-w-5xl">
<div class="mb-4">
<h1 class="text-4xl font-bold tracking-tight text-gray-900 dark:text-gray-100 sm:text-5xl">
<span class="block xl:inline">@Title</span>
</h1>
</div>

@if (total > PageSize)
{
<PagesNav class="border-b" Path=@Path PageSize=@PageSize Total=@total Page=@Math.Max(1, Page ?? 1) />
}

<QuestionPosts Posts=@posts />

@if (total > PageSize)
{
<PagesNav class="border-t" Path=@Path PageSize=@PageSize Total=@total Page=@Math.Max(1, Page ?? 1) />
}
}
else
{
<div class="mt-8 text-lg">
This search return no results.

@if (posts.Count > 0)
{
<div class="py-2 flex justify-end">
<QuestionViewTabs Path=@Path Tabs=@Tabs Active=@Tab/>
</div>

@if (total > PageSize)
{
<PagesNav class="border-b" Path=@Path PageSize=@PageSize Total=@total Page=@Math.Max(1, Page ?? 1)/>
}

<QuestionPosts Posts=@posts/>

@if (total > PageSize)
{
<PagesNav class="border-t" Path=@Path PageSize=@PageSize Total=@total Page=@Math.Max(1, Page ?? 1)/>
}
}
else
{
<div class="mt-8 text-lg">
This search return no results.
</div>
}
</div>
}
</div>
}
else
{
<div class="mt-3 mb-20 mx-auto max-w-fit">
@if (error != null)
{
<ErrorSummary Status=@error />
}
else
{
<Loading />
<div class="mt-3 mb-20 mx-auto max-w-fit">
@if (error != null)
{
<ErrorSummary Status=@error/>
}
else
{
<Loading/>
}
</div>
}
</div>
}
<Aside/>
</div>

@code {
string Path => "/questions".AddQueryParam("q", Q);
int? Skip => Page > 1 ? (Page - 1) * PageSize : 0;
string Title => "All Questions" + (!string.IsNullOrEmpty(Q) ? $" with '{Q}'" : "");

static string[] Tabs = ["most-votes", "most-views", "most-recent"];

[SupplyParameterFromQuery]
string? Q { get; set; }
[SupplyParameterFromQuery] string? Q { get; set; }

[SupplyParameterFromQuery]
string? Tab { get; set; }
[SupplyParameterFromQuery] string? Tab { get; set; }

[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery] int? Page { get; set; }

[SupplyParameterFromQuery]
int? PageSize { get; set; }
[SupplyParameterFromQuery] int? PageSize { get; set; }

List<Post>? posts;
ResponseStatus? error = null;
Expand All @@ -93,12 +93,12 @@ else
{
q.WhereSearch(Q);
}

posts = await db.SelectAsync(q
.OrderByView(Tab)
.Skip(Page > 1 ? (Page - 1) * PageSize : 0)
.Take(PageSize.ToPageSize()));

total = db.Count(q);
}
catch (Exception ex)
Expand All @@ -110,4 +110,4 @@ else
protected override Task OnInitializedAsync() => Load();

protected override Task OnParametersSetAsync() => Load();
}
}
71 changes: 39 additions & 32 deletions MyApp/Components/Pages/Questions/Question.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,55 @@

<PageTitle>@title</PageTitle>

@if (Html != null)
{
@BlazorHtml.Raw(Html)
}
else if (question?.Post?.Title != null)
{
<QuestionPost Question="question" />
}
else
{
<div class="mt-3 mb-20 mx-auto max-w-fit">
@if (error != null)
<div class="flex flex-wrap justify-center">
<div>
@if (Html != null)
{
<ErrorSummary Status=@error />
@BlazorHtml.Raw(Html)
}
else if (question?.Post?.Title != null)
{
<QuestionPost Question="question"/>
}
else
{
<Loading />
<div class="mt-3 mb-20 mx-auto max-w-fit">
@if (error != null)
{
<ErrorSummary Status=@error/>
}
else
{
<Loading/>
}
</div>
}
</div>
}
<Aside/>
</div>

@code {
[Parameter]
public required int Id { get; set; }
[Parameter] public required int Id { get; set; }

[Parameter]
public required string Slug { get; set; }
[Parameter] public required string Slug { get; set; }

QuestionAndAnswers? question;
ResponseStatus? error;
AuthorInfo? author;

string title = "";
string? Html;

async Task load()
{
title = Slug.Replace("-"," ").ToTitleCase();
title = Slug.Replace("-", " ").ToTitleCase();
Html = await RendererCache.GetQuestionPostHtmlAsync(Id);

if (!string.IsNullOrEmpty(Html))
{
var attrPrefix = "<template id=\"Post\">";
var json = Html.IndexOf(attrPrefix, StringComparison.Ordinal) >= 0
? Html.RightPart(attrPrefix).LeftPart("</template>")
var json = Html.IndexOf(attrPrefix, StringComparison.Ordinal) >= 0
? Html.RightPart(attrPrefix).LeftPart("</template>")
: null;

if (json != null)
Expand All @@ -64,28 +67,31 @@ else
return;
}
}

MessageProducer.Publish(new RenderComponent {

MessageProducer.Publish(new RenderComponent
{
IfQuestionModified = Id
});
return;
}

var questionFiles = await R2.GetQuestionFilesAsync(Id);
question = await questionFiles.ToQuestionAndAnswers();
if (question?.Post?.Body != null)
{
title = question.Post.Title;
question.PostComments = [
new Comment {
question.PostComments =
[
new Comment
{
Body = "You may want to check out the [ins and outs of C# enums](https://github.com/steaks/codeducky/blob/master/blogs/enums.md), which discusses this as well as other useful enum tidbits",
CreatedBy = "mistral",
CreatedDate = DateTime.Now.Add(-TimeSpan.FromHours(25))
}
];

MessageProducer.Publish(new RenderComponent { Question = question });

var slug = question.Post.Slug.GenerateSlug(200);
if (slug != Slug)
{
Expand All @@ -95,7 +101,8 @@ else
}
else
{
error = new ResponseStatus {
error = new ResponseStatus
{
ErrorCode = "NotFound",
Message = "Question not found"
};
Expand All @@ -105,4 +112,4 @@ else
protected override Task OnInitializedAsync() => load();

protected override Task OnParametersSetAsync() => load();
}
}
Loading

0 comments on commit 2183e75

Please sign in to comment.