v0.2.12-pre.002-fix.001
This commit is contained in:
@@ -1,23 +1,29 @@
|
||||
// file: crates/ksp-app-solprices-desk/frontend/ts/main.ts
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
import "bootstrap";
|
||||
import ResizeObserver from "resize-observer-polyfill";
|
||||
import "simplebar";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import type { RuntimeStatusDto } from "./bindings/ksp_app_solprices_desk/dto_common/RuntimeStatusDto.ts";
|
||||
import { frontendDebug, frontendInfo, frontendTrace, installFrontendConsoleBridge } from "./frontend_log";
|
||||
import { frontendDebug, frontendInfo, frontendTrace, frontendWarn, installFrontendConsoleBridge } from "./frontend_log";
|
||||
import { invokeKsp } from "./invoke";
|
||||
|
||||
(window as Window & typeof globalThis & { ResizeObserver?: typeof ResizeObserver }).ResizeObserver = ResizeObserver;
|
||||
installFrontendConsoleBridge("main");
|
||||
|
||||
const viewTitles: Record<string, string> = {
|
||||
type ViewId = "prices" | "diagnostics";
|
||||
|
||||
const viewTitles: Record<ViewId, string> = {
|
||||
prices: "Prices",
|
||||
diagnostics: "Diagnostics",
|
||||
};
|
||||
|
||||
function activateView(viewId: string): void {
|
||||
if (!(viewId in viewTitles)) {
|
||||
return;
|
||||
}
|
||||
function isViewId(value: string | undefined): value is ViewId {
|
||||
return value === "prices" || value === "diagnostics";
|
||||
}
|
||||
|
||||
function activateView(viewId: ViewId, source: "startup" | "user"): void {
|
||||
document.querySelectorAll<HTMLElement>("[data-view-panel]").forEach(panel => {
|
||||
panel.hidden = panel.dataset.viewPanel !== viewId;
|
||||
});
|
||||
@@ -28,7 +34,22 @@ function activateView(viewId: string): void {
|
||||
if (header) {
|
||||
header.textContent = viewTitles[viewId];
|
||||
}
|
||||
frontendDebug("main", "SOL Prices Desk view activated", { viewId });
|
||||
document.title = `SOL Prices Desk — ${viewTitles[viewId]}`;
|
||||
if (source !== "startup") {
|
||||
frontendDebug("main", "SOL Prices Desk view activated", { viewId, source });
|
||||
}
|
||||
}
|
||||
|
||||
function bindNavigation(): void {
|
||||
document.querySelectorAll<HTMLButtonElement>("[data-view]").forEach(button => {
|
||||
button.addEventListener("click", () => {
|
||||
const viewId = button.dataset.view;
|
||||
if (isViewId(viewId)) {
|
||||
activateView(viewId, "user");
|
||||
}
|
||||
});
|
||||
});
|
||||
frontendTrace("main", "SOL Prices Desk navigation handlers installed");
|
||||
}
|
||||
|
||||
function renderRuntimeStatus(status: RuntimeStatusDto): void {
|
||||
@@ -45,10 +66,6 @@ function renderRuntimeStatus(status: RuntimeStatusDto): void {
|
||||
element.textContent = value;
|
||||
}
|
||||
}
|
||||
const badge = document.querySelector<HTMLElement>("#runtimeVersionBadge");
|
||||
if (badge) {
|
||||
badge.textContent = status.applicationVersion;
|
||||
}
|
||||
const diagnostic = document.querySelector<HTMLElement>("#runtimeDiagnostic");
|
||||
if (diagnostic) {
|
||||
diagnostic.hidden = status.startupDiagnostic === null;
|
||||
@@ -60,19 +77,26 @@ function renderRuntimeStatus(status: RuntimeStatusDto): void {
|
||||
});
|
||||
}
|
||||
|
||||
async function initializeMain(): Promise<void> {
|
||||
frontendInfo("main", "SOL Prices Desk scaffold frontend loaded");
|
||||
document.querySelectorAll<HTMLButtonElement>("[data-view]").forEach(button => {
|
||||
button.addEventListener("click", () => {
|
||||
const viewId = button.dataset.view;
|
||||
if (viewId) {
|
||||
activateView(viewId);
|
||||
}
|
||||
});
|
||||
});
|
||||
const status = await invokeKsp<RuntimeStatusDto>("main", "runtime_status");
|
||||
async function loadRuntimeStatus(): Promise<void> {
|
||||
const status = await invokeKsp<RuntimeStatusDto>("main", "get_runtime_status");
|
||||
renderRuntimeStatus(status);
|
||||
activateView("prices");
|
||||
}
|
||||
|
||||
async function initializeMain(): Promise<void> {
|
||||
const windowLabel = getCurrentWindow().label;
|
||||
frontendInfo("main", "SOL Prices Desk main frontend loaded", { windowLabel });
|
||||
bindNavigation();
|
||||
activateView("prices", "startup");
|
||||
try {
|
||||
await loadRuntimeStatus();
|
||||
} catch {
|
||||
const diagnostic = document.querySelector<HTMLElement>("#runtimeDiagnostic");
|
||||
if (diagnostic) {
|
||||
diagnostic.hidden = false;
|
||||
diagnostic.textContent = "Le statut runtime initial n'a pas pu être chargé.";
|
||||
}
|
||||
frontendWarn("main", "SOL Prices Desk startup runtime status load failed");
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
Reference in New Issue
Block a user