Scaffold Blazor frontend host and root components

This commit is contained in:
2026-02-25 11:58:25 +01:00
parent bb2395aa9b
commit a8ee637374
7 changed files with 105 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
@using Microsoft.AspNetCore.Components.Web
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<title>RpgRoller</title>
<link rel="stylesheet" href="/styles.css" />
<HeadOutlet @rendermode="InteractiveServer" />
</head>
<body>
<Routes @rendermode="InteractiveServer" />
<script src="/js/rpgroller-api.js"></script>
<script src="_framework/blazor.web.js"></script>
</body>
</html>

View File

@@ -0,0 +1,4 @@
@inherits LayoutComponentBase
@attribute [ExcludeFromCodeCoverage]
@Body

View File

@@ -0,0 +1,7 @@
@page "/"
@attribute [ExcludeFromCodeCoverage]
<main class="app-shell">
<h1>RpgRoller</h1>
<p class="status-line">Frontend migration in progress: Blazor shell is active.</p>
</main>

View File

@@ -0,0 +1,6 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
</Router>

View File

@@ -0,0 +1,9 @@
@using System.Diagnostics.CodeAnalysis
@using RpgRoller
@using RpgRoller.Contracts
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using static Microsoft.AspNetCore.Components.Web.RenderMode

View File

@@ -3,14 +3,17 @@ using RpgRoller.Hosting;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRpgRollerCore(builder.Configuration, builder.Environment);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
var app = builder.Build();
app.InitializeRpgRollerState();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapRpgRollerApi();
app.MapRazorComponents<RpgRoller.Components.App>()
.AddInteractiveServerRenderMode();
app.Run();
public partial class Program;

View File

@@ -0,0 +1,57 @@
window.rpgRollerApi = (() => {
async function request(method, url, body) {
const options = {
method,
credentials: "same-origin",
headers: {
Accept: "application/json"
}
};
if (body !== null && body !== undefined) {
options.headers["Content-Type"] = "application/json";
options.body = JSON.stringify(body);
}
let response;
try {
response = await fetch(url, options);
}
catch (error) {
return {
ok: false,
status: 0,
error: "Network error. Check your connection and retry."
};
}
let parsed = null;
const text = await response.text();
if (text) {
try {
parsed = JSON.parse(text);
}
catch {
parsed = null;
}
}
if (!response.ok) {
return {
ok: false,
status: response.status,
error: parsed && typeof parsed.error === "string" ? parsed.error : "Request failed."
};
}
return {
ok: true,
status: response.status,
data: parsed
};
}
return {
request
};
})();