diff options
| author | Marijn Besseling <njirambem@gmail.com> | 2025-09-21 17:47:15 +0200 |
|---|---|---|
| committer | Marijn Besseling <njirambem@gmail.com> | 2025-09-21 17:47:45 +0200 |
| commit | 93f038ffa95f1c2f4780c684a1b780666b086882 (patch) | |
| tree | 7d96bb172a74ccab873286730f644805321e8e89 /Blog/Components/_Shared | |
| parent | da78a550c829653bdf6029578ff75be250addc0d (diff) | |
Add BRP Test data
Diffstat (limited to 'Blog/Components/_Shared')
| -rw-r--r-- | Blog/Components/_Shared/JsonRender.razor | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Blog/Components/_Shared/JsonRender.razor b/Blog/Components/_Shared/JsonRender.razor new file mode 100644 index 0000000..17e08a1 --- /dev/null +++ b/Blog/Components/_Shared/JsonRender.razor | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | @using System.Text.Json | ||
| 2 | @using Blog.Components.Pages | ||
| 3 | @code { | ||
| 4 | |||
| 5 | [Parameter] | ||
| 6 | public JsonElement? Element { get; set; } | ||
| 7 | } | ||
| 8 | @if (Element is { } element) | ||
| 9 | { | ||
| 10 | @switch (element.ValueKind) | ||
| 11 | { | ||
| 12 | case JsonValueKind.Object: | ||
| 13 | { | ||
| 14 | <ul> | ||
| 15 | @foreach (var property in element.EnumerateObject()) | ||
| 16 | { | ||
| 17 | <li> | ||
| 18 | <span class="name">@property.Name</span> | ||
| 19 | <JsonRender Element="property.Value"/> | ||
| 20 | </li> | ||
| 21 | } | ||
| 22 | </ul> | ||
| 23 | break; | ||
| 24 | } | ||
| 25 | case JsonValueKind.Array: | ||
| 26 | { | ||
| 27 | <ol> | ||
| 28 | @foreach (var item in element.EnumerateArray()) | ||
| 29 | { | ||
| 30 | <li> | ||
| 31 | <JsonRender Element="item"></JsonRender> | ||
| 32 | </li> | ||
| 33 | } | ||
| 34 | </ol> | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | case JsonValueKind.String: | ||
| 38 | { | ||
| 39 | string value = element.GetString() ?? string.Empty; | ||
| 40 | @if (BRP.LooksLikeBSN(value)) | ||
| 41 | { | ||
| 42 | <NavLink href=@BRP.Url(value)>@value</NavLink> | ||
| 43 | } | ||
| 44 | else | ||
| 45 | { | ||
| 46 | <span>@value</span> | ||
| 47 | } | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||