[frontend/pages] Add user debug page
This commit is contained in:
parent
b79de70345
commit
0b8e3a8f2b
4 changed files with 164 additions and 0 deletions
62
Iceshrimp.Frontend/Components/JsonViewer.razor
Normal file
62
Iceshrimp.Frontend/Components/JsonViewer.razor
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
@using System.Text.Json
|
||||||
|
|
||||||
|
<div class="json">
|
||||||
|
@if (Element.ValueKind == JsonValueKind.Array)
|
||||||
|
{
|
||||||
|
@if (Element.GetArrayLength() == 0)
|
||||||
|
{
|
||||||
|
<span class="keyword">Empty</span>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var i = 0;
|
||||||
|
@foreach (var item in Element.EnumerateArray())
|
||||||
|
{
|
||||||
|
<dt>@i:</dt>
|
||||||
|
@RenderElement(item)
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Element.ValueKind == JsonValueKind.Object)
|
||||||
|
{
|
||||||
|
@foreach (var prop in Element.EnumerateObject())
|
||||||
|
{
|
||||||
|
@switch (prop.Value.ValueKind)
|
||||||
|
{
|
||||||
|
case JsonValueKind.Array:
|
||||||
|
<dt>@prop.Name []</dt>
|
||||||
|
break;
|
||||||
|
case JsonValueKind.Object:
|
||||||
|
<dt>@prop.Name {}</dt>
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
<dt>@prop.Name:</dt>
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
@RenderElement(prop.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter, EditorRequired] public required JsonElement Element { get; set; }
|
||||||
|
|
||||||
|
RenderFragment RenderElement(JsonElement element)
|
||||||
|
{
|
||||||
|
return element.ValueKind switch
|
||||||
|
{
|
||||||
|
JsonValueKind.True or JsonValueKind.False or JsonValueKind.Null or JsonValueKind.Undefined => (@<dd>
|
||||||
|
<span class="keyword">@element.ValueKind.ToString()</span></dd>),
|
||||||
|
JsonValueKind.Array or JsonValueKind.Object => (@<dd>
|
||||||
|
<JsonViewer Element="element"/>
|
||||||
|
</dd>),
|
||||||
|
JsonValueKind.Number => (@<dd><span class="number">@element.GetDouble()</span></dd>),
|
||||||
|
JsonValueKind.String => (element.GetString() is { } s && Uri.TryCreate(s, UriKind.Absolute, out var _)
|
||||||
|
? @<dd><a href="@s" target="_blank">@s</a></dd>
|
||||||
|
: @<dd><span class="string">"@element.GetString()?.ReplaceLineEndings("\\n")"</span></dd>),
|
||||||
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
16
Iceshrimp.Frontend/Components/JsonViewer.razor.css
Normal file
16
Iceshrimp.Frontend/Components/JsonViewer.razor.css
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
.json {
|
||||||
|
dt {
|
||||||
|
color: #66C3CC;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.keyword {
|
||||||
|
color: #6C95EB;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
.number {
|
||||||
|
color: #ED94C0;
|
||||||
|
}
|
||||||
|
.string {
|
||||||
|
color: #C9A26D;
|
||||||
|
}
|
||||||
|
}
|
72
Iceshrimp.Frontend/Pages/About.razor
Normal file
72
Iceshrimp.Frontend/Pages/About.razor
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
@page "/notes/{NoteId}/about"
|
||||||
|
@page "/{User}/about"
|
||||||
|
@using System.Text.Json
|
||||||
|
@using System.Text.RegularExpressions
|
||||||
|
@using Iceshrimp.Assets.PhosphorIcons
|
||||||
|
@using Iceshrimp.Frontend.Components
|
||||||
|
@using Iceshrimp.Frontend.Core.Miscellaneous
|
||||||
|
@using Iceshrimp.Frontend.Core.Services
|
||||||
|
@using Iceshrimp.Frontend.Localization
|
||||||
|
@using Microsoft.AspNetCore.Authorization
|
||||||
|
@using Microsoft.AspNetCore.Components.Sections
|
||||||
|
@using Microsoft.Extensions.Localization
|
||||||
|
@attribute [Authorize]
|
||||||
|
@inject ApiService Api;
|
||||||
|
@inject IStringLocalizer<Localization> Loc;
|
||||||
|
|
||||||
|
<HeadTitle Text="@Loc["About"]"/>
|
||||||
|
|
||||||
|
<SectionContent SectionName="top-bar">
|
||||||
|
<Icon Name="Icons.Info"></Icon>
|
||||||
|
@Loc["About"]
|
||||||
|
</SectionContent>
|
||||||
|
|
||||||
|
@if (State == State.Loaded)
|
||||||
|
{
|
||||||
|
@foreach (var document in Documents)
|
||||||
|
{
|
||||||
|
<details>
|
||||||
|
<summary>@document.Key</summary>
|
||||||
|
<JsonViewer Element="document.Value.RootElement"/>
|
||||||
|
</details>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter] public string? NoteId { get; set; }
|
||||||
|
[Parameter] public string? User { get; set; }
|
||||||
|
private State State { get; set; }
|
||||||
|
private Dictionary<string, JsonDocument> Documents { get; set; } = [];
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
if (NoteId != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (User != null)
|
||||||
|
{
|
||||||
|
var pattern = "^@([^@]+)@?(.+)?$";
|
||||||
|
var matches = Regex.Match(User, pattern);
|
||||||
|
var userResponse = await Api.Users.LookupUserAsync(matches.Groups[1].Value, matches.Groups[2].Value);
|
||||||
|
|
||||||
|
if (userResponse is null)
|
||||||
|
{
|
||||||
|
State = State.NotFound;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var profileResponse = await Api.Users.GetUserProfileAsync(userResponse.Id);
|
||||||
|
|
||||||
|
Documents.Add(Loc["User response"], JsonSerializer.SerializeToDocument(userResponse));
|
||||||
|
Documents.Add(Loc["Profile response"], JsonSerializer.SerializeToDocument(profileResponse));
|
||||||
|
|
||||||
|
State = State.Loaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
State = State.NotFound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Iceshrimp.Frontend/Pages/About.razor.css
Normal file
14
Iceshrimp.Frontend/Pages/About.razor.css
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
details {
|
||||||
|
padding: 1rem 1rem;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary {
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
background-color: var(--highlight-color);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary:hover {
|
||||||
|
background-color: var(--hover-color);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue