Adopt b2b.next's client patterns: services, page state, feedback
Ported from the owner's b2b.next and adapted from MudBlazor to the daisyUI
components:
- LocalizableComponentBase provides CascadingState, Navigation, Toast,
IsLoading/IsDefaultDisabled, WhenOnline/StartOnlinePolling, and after-render
jobs that actually run.
- CascadingState starts with initialised state and polls the online status
with a PeriodicTimer. It reports errors through ILoggingService plus a toast,
and disposes what it holds.
- New pieces:
- ToastService + ToastHost, the snackbar, with AddResponseError/Success/
Warning/Exception in SUtility;
- ErrorViewer, which shows the validation messages plus AdditionalError(s);
- LoggingService, which writes to the console and the IndexedDB client log.
- HttpService is rebuilt and registered:
- auth levels Get/Post/Delete, *Anon and *TotallyAnon;
- retry with backoff;
- classified failures (FailureCodes) instead of exceptions;
- HTTP 410 on cancel;
- the "default" client.
ReadWebResult and DefaultReadFromJsonAsync read its responses.
- ClientJsonContext is source-generated, and SUtility.DefaultSerializer and
Blazored.LocalStorage use it.
- WebResult gains a C# 14 IsInvalid extension property.
The code follows the imported rules:
- Every service and async helper takes a CancellationToken last.
- Primary constructors replace constructor-plus-fields.
- MessagesService and IStorage return Task<WebResult> / Task<List<T>>.
MessagesService is still mock, building its results in memory; the seed
feed and thread moved to Faker.
- Index and ExpandMessage follow the page pattern: an offline guard with
WhenOnline, LoadData, and early returns with toasts on the results they used
to ignore. ExpandMessage reloads on route change and shows "not found"
instead of a null message.
- Model and state collections are [], and the fake identity defaults moved
out of the models.
- Components:
- no ?. chains over initialised state;
- [Inject] instead of @inject;
- IsDefaultDisabled on the actions;
- autocomplete on every text input;
- Localizer[key, args] instead of string.Format;
- the localizer no longer leaks its inner _pLocalizer.
- Settings → General gains a language picker (English/Italiano), and
SetDefaultCulture limits the culture to those two.
Bugs fixed along the way:
- A compose with untouched (null) content passed the empty check.
- File errors were joined with <br/> and rendered as markup.
- ClientLogs.ErrorMessage() threw on warnings.
- CoalescingStringLocalizer[key, args] showed a raw "{0}" for missing keys.
- AppStatusService exposed a call to a JS function that doesn't exist.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
1 parent
ca060f25fb
commit
95428430c0
55 files changed
+1844
-1337
No files matched your search
@@ -1,4 +1,4 @@
|
||||
@inherits DComponentBase
|
||||
@inherits DComponentBase
|
||||
|
||||
@* daisyUI Accordion: https://daisyui.com/components/accordion/ . Instead of daisyUI's radio group, the open item is an
|
||||
index in C# (@bind-Active, -1 = none). Each DAccordionItem registers itself through the cascading value and renders a
|
||||
@@ -19,7 +19,7 @@
|
||||
/// <summary>Join the items into one block (join join-vertical, join-item).</summary>
|
||||
[Parameter] public bool Joined { get; set; }
|
||||
|
||||
readonly List<DAccordionItem> items = new();
|
||||
readonly List<DAccordionItem> items = [];
|
||||
|
||||
string CssClass => Cx(Joined ? "join join-vertical rounded-box neo-raised" : "flex flex-col gap-2", Class);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
@code {
|
||||
[Parameter] public string Src { get; set; }
|
||||
// "" on purpose (the documented exception to "no string defaults"): an empty alt marks a decorative image.
|
||||
[Parameter] public string Alt { get; set; } = "";
|
||||
/// <summary>Shown in the frame when there is no Src, e.g. initials with Placeholder.</summary>
|
||||
[Parameter] public RenderFragment ChildContent { get; set; }
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@inherits DComponentBase
|
||||
@inject NavigationManager NavigationManager
|
||||
@inherits DComponentBase
|
||||
|
||||
@* daisyUI Carousel: https://daisyui.com/components/carousel/ . A scroll-snap strip of DCarouselItem children; the
|
||||
user scrolls or swipes it. Give each item w-full for one slide at a time. ShowNavigation (previous/next on every
|
||||
@@ -25,6 +24,7 @@
|
||||
</CascadingValue>
|
||||
|
||||
@code {
|
||||
[Inject] NavigationManager NavigationManager { get; set; }
|
||||
[Parameter] public RenderFragment ChildContent { get; set; }
|
||||
[Parameter] public DCarouselSnap Snap { get; set; }
|
||||
[Parameter] public DDirection Direction { get; set; }
|
||||
@@ -36,7 +36,7 @@
|
||||
[Parameter] public string NextText { get; set; } = "Next slide";
|
||||
[Parameter] public string SlideText { get; set; } = "Slide";
|
||||
|
||||
readonly List<DCarouselItem> items = new();
|
||||
readonly List<DCarouselItem> items = [];
|
||||
readonly string uid = "d" + Guid.NewGuid().ToString("N")[..8];
|
||||
|
||||
RenderFragment Strip => @<div @attributes="AdditionalAttributes" class="@CssClass">@ChildContent</div>;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
@code {
|
||||
[Parameter] public IEnumerable<string> Images { get; set; }
|
||||
// "" on purpose (the documented exception to "no string defaults"): an empty alt marks a decorative image.
|
||||
[Parameter] public string Alt { get; set; } = "";
|
||||
[Parameter] public RenderFragment ChildContent { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@inherits DComponentBase
|
||||
@inherits DComponentBase
|
||||
|
||||
@* daisyUI Tab: https://daisyui.com/components/tab/ . Each DTab child registers itself through the cascading value;
|
||||
DTabs renders the tab buttons and the active tab's content. The active tab is an index (@bind-Active). *@
|
||||
@@ -35,7 +35,7 @@
|
||||
[Parameter] public bool Bottom { get; set; }
|
||||
[Parameter] public string ContentClass { get; set; } = "pt-4";
|
||||
|
||||
readonly List<DTab> tabs = new();
|
||||
readonly List<DTab> tabs = [];
|
||||
|
||||
string CssClass => Cx("tabs", VariantClass, SizeClass, Bottom ? "tabs-bottom" : null, Class);
|
||||
|
||||
|
||||
Reference in new issue
Block a user