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:
thepraandClaude Opus 5.5 committed 2026-10-03 15:26:21 +02:00
1 parent ca060f25fb
commit 95428430c0
55 files changed
+1844 -1337

No files matched your search

+5 -5
View File
@@ -2,10 +2,10 @@
{
public class BoostingUser
{
public string UserId { get; set; } = "45f14fa8-c40f-4121-997c-ef2542196a50";
public string UserName { get; set; } = "@loosy@letsrulethe.world";
public string DisplayName { get; set; } = "loosy";
public string PictureUrl { get; set; } = "https://letsrulethe.world/media/ddd91d51-dc12-4b82-86a2-2a28cc959183/L51ZAL4QEL07";
public string ProfileUrl { get; set; } = "https://letsrulethe.world/users/loosy";
public string UserId { get; set; }
public string UserName { get; set; }
public string DisplayName { get; set; }
public string PictureUrl { get; set; }
public string ProfileUrl { get; set; }
}
}
+9 -11
View File
@@ -7,21 +7,19 @@
public string WarningMessage { get; set; }
public ClientLogException Exception { get; set; }
public DateTime TimeStamp { get; set; } = DateTime.Now;
/// <summary>The entry as HTML for a log viewer: the warning text, or the exception's details.</summary>
public string ErrorMessage()
{
if (Exception.InnerExceptionMessage != null)
{
return @$"<b>Type</b>: {Exception.Type ?? "N/A"} <b>HelpLink</b>: {Exception.HelpLink ?? "N/A"} <b>HResult</b>: {Exception.HResult ?? "N/A"}<br>
<b>Source</b>: {Exception.Source ?? "N/A"} <b>StackTrace</b>: {Exception.StackTrace ?? "N/A"} <b>MemberName</b>: {Exception.TargetSiteName ?? "N/A"}<br>
<b>Message</b>: {Exception.Message ?? "N/A"}<br>
<b>InnerExceptionMessage</b>:{Exception.InnerExceptionMessage ?? "N/A"}";
}
else
{
return @$"<b>Type</b>: {Exception.Type ?? "N/A"} <b>HelpLink</b>: {Exception.HelpLink ?? "N/A"} <b>HResult</b>: {Exception.HResult ?? "N/A"}<br>
if (Exception is null)
return WarningMessage;
var details = @$"<b>Type</b>: {Exception.Type ?? "N/A"} <b>HelpLink</b>: {Exception.HelpLink ?? "N/A"} <b>HResult</b>: {Exception.HResult ?? "N/A"}<br>
<b>Source</b>: {Exception.Source ?? "N/A"} <b>StackTrace</b>: {Exception.StackTrace ?? "N/A"} <b>MemberName</b>: {Exception.TargetSiteName ?? "N/A"}<br>
<b>Message</b>: {Exception.Message ?? "N/A"}";
}
if (Exception.InnerExceptionMessage is null)
return details;
return $"{details}<br>\n<b>InnerExceptionMessage</b>:{Exception.InnerExceptionMessage}";
}
}
+20
View File
@@ -0,0 +1,20 @@
namespace decePubClient.Models;
/// <summary>
/// WebResult.ErrorCode values HttpService sets when a request fails before or outside the server, so the UI can tell a
/// connectivity problem (shown as a warning) from a real error.
/// </summary>
public static class FailureCodes
{
public const string Cancelled = "CANCELLED";
public const string DeviceOffline = "DEVICE-OFFLINE";
public const string Timeout = "TIMEOUT";
public const string ApiUnreachable = "API-UNREACHABLE";
public const string RetriesExhausted = "RETRIES-EXHAUSTED";
public const string ServerError = "SERVER-ERROR";
public const string ClientError = "CLIENT-ERROR";
public const string Unauthorized = "UNAUTHORIZED";
public static bool IsConnectivity(string errorCode) =>
errorCode is DeviceOffline or Timeout or ApiUnreachable or RetriesExhausted;
}
+1 -1
View File
@@ -6,6 +6,6 @@
public string Url { get; set; }
public string ContentType { get; set; }
public string AltText { get; set; }
public byte[] Blob { get; set; } //TODO TEMPORARY
public byte[] Blob { get; set; } = []; //TODO TEMPORARY
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ namespace decePubClient.Models
public int BoostsCounter { get; set; } = 0;
public bool IsBoostedByCurrentUser { get; set; } = false;
public BoostingUser BoostingUser { get; set; }
public List<Media> Medias { get; set; } = new();
public List<Media> Medias { get; set; } = [];
public DateTime CreatedAt { get; set; }
[Bindable(false), JsonIgnore]
+1 -1
View File
@@ -19,7 +19,7 @@ public class MessageForm
public string Title { get; set; }
[StringLength(5_000, ErrorMessageResourceName = ValidationNames.MaxLength, ErrorMessageResourceType = typeof(ErrorMessages))]
public string Content { get; set; }
public List<UploadMedia> Media { get; set; } = new();
public List<UploadMedia> Media { get; set; } = [];
[JsonIgnore, Bindable(false)]
public MediaType MediaType { get; set; } = MediaType.Images;
+6 -6
View File
@@ -2,11 +2,11 @@
{
public class MessageUser
{
public string UserId { get; set; } = "45f14fa8-c40f-4121-997c-ef2542196a50";
public string UserName { get; set; } = "@loosy@letsrulethe.world";
public string DisplayName { get; set; } = "loosy";
public string PictureUrl { get; set; } = "https://letsrulethe.world/media/ddd91d51-dc12-4b82-86a2-2a28cc959183/L51ZAL4QEL07";
public string BackgroundUrl { get; set; } = "https://letsrulethe.world/media/9a3cc6c4-1018-4f41-86c7-f3e63e362bf4/EXM8RUK10B0Z";
public string ProfileUrl { get; set; } = "https://letsrulethe.world/users/loosy";
public string UserId { get; set; }
public string UserName { get; set; }
public string DisplayName { get; set; }
public string PictureUrl { get; set; }
public string BackgroundUrl { get; set; }
public string ProfileUrl { get; set; }
}
}
+3 -3
View File
@@ -6,12 +6,12 @@ namespace decePubClient.Models
{
public class PublicCacheData
{
public IReadOnlyList<ViewLanguage> Languages { get; set; } = new List<ViewLanguage>();
public List<MediaDeviceInfo> QrCodeDevices { get; set; } = new();
public IReadOnlyList<ViewLanguage> Languages { get; set; } = [];
public List<MediaDeviceInfo> QrCodeDevices { get; set; } = [];
public string LastPage { get; set; }
public string CurrentSubPage { get; set; }
public PageSettings PageSettings { get; set; } = new();
public bool ShowLogs { get; set; } = false;
public IReadOnlyDictionary<string, string> Policies { get; set; } = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>());
public IReadOnlyDictionary<string, string> Policies { get; set; } = ReadOnlyDictionary<string, string>.Empty;
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ public class UploadMedia
public string ContentType { get; set; }
public string FileName { get; set; }
public string AltText { get; set; }
public byte[] Blob { get; set; }
public byte[] Blob { get; set; } = [];
[JsonIgnore, Bindable(false)]
public string Base64Preview { get; set; }
+26 -7
View File
@@ -2,15 +2,34 @@
{
public class User
{
public string Id { get; set; } = "45f14fa8-c40f-4121-997c-ef2542196a50";
public string Id { get; set; }
public bool IsAuthenticated { get; set; } = false;
public List<UserClaim> Claims { get; set; } = new();
public List<UserClaim> Claims { get; set; } = [];
public string UserName { get; set; } = "@loosy@letsrulethe.world";
public string DisplayName { get; set; } = "loosy";
public string PictureUrl { get; set; } = "https://letsrulethe.world/media/ddd91d51-dc12-4b82-86a2-2a28cc959183/L51ZAL4QEL07";
public string BackgroundUrl { get; set; } = "https://letsrulethe.world/media/9a3cc6c4-1018-4f41-86c7-f3e63e362bf4/EXM8RUK10B0Z";
public string ProfileUrl { get; set; } = "https://letsrulethe.world/users/loosy";
public string UserName { get; set; }
public string DisplayName { get; set; }
public string PictureUrl { get; set; }
public string BackgroundUrl { get; set; }
public string ProfileUrl { get; set; }
public MessageUser ToMessageUser() => new()
{
UserId = Id,
UserName = UserName,
DisplayName = DisplayName,
PictureUrl = PictureUrl,
BackgroundUrl = BackgroundUrl,
ProfileUrl = ProfileUrl
};
public BoostingUser ToBoostingUser() => new()
{
UserId = Id,
UserName = UserName,
DisplayName = DisplayName,
PictureUrl = PictureUrl,
ProfileUrl = ProfileUrl
};
}
public class UserClaim
+11
View File
@@ -0,0 +1,11 @@
namespace decePubClient.Models;
/// <summary>ASP.NET Core's validation ProblemDetails, as the server returns it for an invalid request body.</summary>
public class ValidationErrors
{
public string Type { get; set; }
public string Title { get; set; }
public int Status { get; set; }
public Dictionary<string, string[]> Errors { get; set; } = [];
public string TraceId { get; set; }
}