Add common loading component

This has no specific issue associated, but reduces boilerplate in most page components
This commit is contained in:
2021-01-26 22:26:36 -05:00
parent 7f7eb191fb
commit a6fd891cc5
13 changed files with 299 additions and 300 deletions

View File

@@ -6,52 +6,44 @@
@inject IToastService toast
<PageTitle Title=@Title />
<h3>@Title</h3>
<ErrorList Errors=@ErrorMessages>
@if (Loading)
<Loading OnLoad=@RetrieveStory>
@if (IsNew)
{
<p>Loading...</p>
<p>
Congratulations on your employment! Your fellow citizens would enjoy hearing how it all came about; tell us
about it below! <em>(These will be visible to other users, but not to the general public.)</em>
</p>
}
else
{
@if (IsNew)
{
<p>
Congratulations on your employment! Your fellow citizens would enjoy hearing how it all came about; tell us
about it below! <em>(These will be visible to other users, but not to the general public.)</em>
</p>
}
<EditForm Model=@Form OnValidSubmit=@SaveStory>
<div class="form-row">
<div class="col">
<div class="form-check">
<InputCheckbox id="fromHere" class="form-check-input" @bind-Value=@Form.FromHere />
<label for="fromHere" class="form-check-label">I found my employment here</label>
</div>
<EditForm Model=@Form OnValidSubmit=@SaveStory>
<div class="form-row">
<div class="col">
<div class="form-check">
<InputCheckbox id="fromHere" class="form-check-input" @bind-Value=@Form.FromHere />
<label for="fromHere" class="form-check-label">I found my employment here</label>
</div>
</div>
<div class="form-row">
<div class="col">
<div class="form-group">
<label for="story" class="jjj-label">The Success Story</label>
<MarkdownEditor Id="story" @bind-Text=@Form.Story />
</div>
</div>
<div class="form-row">
<div class="col">
<div class="form-group">
<label for="story" class="jjj-label">The Success Story</label>
<MarkdownEditor Id="story" @bind-Text=@Form.Story />
</div>
</div>
<div class="form-row">
<div class="col">
<br>
<button type="submit" class="btn btn-outline-primary">Save</button>
@if (IsNew)
{
<p>
<em>(Saving this will set &ldquo;Seeking Employment&rdquo; to &ldquo;No&rdquo; on your profile.)</em>
</p>
}
</div>
</div>
<div class="form-row">
<div class="col">
<br>
<button type="submit" class="btn btn-outline-primary">Save</button>
@if (IsNew)
{
<p>
<em>(Saving this will set &ldquo;Seeking Employment&rdquo; to &ldquo;No&rdquo; on your profile.)</em>
</p>
}
</div>
</EditForm>
}
</ErrorList>
</div>
</EditForm>
</Loading>

View File

@@ -16,11 +16,6 @@ namespace JobsJobsJobs.Client.Pages.SuccessStory
[Parameter]
public string? Id { get; set; }
/// <summary>
/// Whether we are loading information
/// </summary>
private bool Loading { get; set; } = true;
/// <summary>
/// The page title / header
/// </summary>
@@ -37,11 +32,10 @@ namespace JobsJobsJobs.Client.Pages.SuccessStory
private bool IsNew => Form.Id == "new";
/// <summary>
/// Error messages from API access
/// Retrieve the story
/// </summary>
private IList<string> ErrorMessages { get; } = new List<string>();
protected override async Task OnInitializedAsync()
/// <param name="errors">A collection to use in reporting errors that may occur</param>
public async Task RetrieveStory(ICollection<string> errors)
{
if (Id != null)
{
@@ -58,14 +52,13 @@ namespace JobsJobsJobs.Client.Pages.SuccessStory
}
else if (story.IsOk)
{
ErrorMessages.Add($"The success story {Id} does not exist");
errors.Add($"The success story {Id} does not exist");
}
else
{
ErrorMessages.Add(story.Error);
errors.Add(story.Error);
}
}
Loading = false;
}
/// <summary>

View File

@@ -3,15 +3,10 @@
@inject AppState state
<PageTitle Title="Success Stories" />
<h3>Success Stories</h3>
<ErrorList Errors=@ErrorMessages>
@if (Loading)
{
<p>Loading...</p>
}
else if (Stories.Any())
<Loading OnLoad=@LoadStories>
@if (Stories.Any())
{
<table class="table table-sm table-hover">
<thead>
@@ -43,4 +38,4 @@
{
<p>There are no success stories recorded <em>(yet)</em></p>
}
</ErrorList>
</Loading>

View File

@@ -1,30 +1,22 @@
using JobsJobsJobs.Shared.Api;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace JobsJobsJobs.Client.Pages.SuccessStory
{
public partial class ListStories : ComponentBase
{
/// <summary>
/// Whether we are still loading data
/// </summary>
private bool Loading { get; set; } = true;
/// <summary>
/// The story entries
/// </summary>
private IEnumerable<StoryEntry> Stories { get; set; } = default!;
/// <summary>
/// Error messages encountered
/// Load all success stories
/// </summary>
private IList<string> ErrorMessages { get; set; } = new List<string>();
protected override async Task OnInitializedAsync()
/// <param name="errors">The collection into which errors can be reported</param>
public async Task LoadStories(ICollection<string> errors)
{
ServerApi.SetJwt(http, state);
var stories = await ServerApi.RetrieveMany<StoryEntry>(http, "success/list");
@@ -35,10 +27,8 @@ namespace JobsJobsJobs.Client.Pages.SuccessStory
}
else
{
ErrorMessages.Add(stories.Error);
errors.Add(stories.Error);
}
Loading = false;
}
}
}