Files
GMW/src/routes/uiStateRoutes.ts
T

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-05-14 19:46:47 +07:00
import type { Router } from "express";
import express from "express";
import type { SharedUIState, SharedUIStatePatch } from "../state/uiState.js";
2026-05-14 19:46:47 +07:00
2026-05-19 14:11:09 +07:00
export { SharedUIState, SharedUIStatePatch };
2026-05-14 19:46:47 +07:00
export interface UIStateRouteOptions {
getSharedUIState: () => SharedUIState;
2026-05-19 14:11:09 +07:00
patchSharedUIState: (
patch: SharedUIStatePatch,
) => Promise<SharedUIState> | SharedUIState;
2026-05-14 19:46:47 +07:00
}
export function createUIStateRoutes(options: UIStateRouteOptions): Router {
const router = express.Router();
const { getSharedUIState, patchSharedUIState } = options;
// GET /api/ui-state - Get current UI state
router.get("/ui-state", (_req, res, next) => {
try {
const state = getSharedUIState();
res.json(state);
} catch (error) {
next(error);
}
});
// POST /api/ui-state - Update UI state
2026-05-19 14:11:09 +07:00
router.post("/ui-state", async (req, res, next) => {
2026-05-14 19:46:47 +07:00
try {
const patch = req.body as SharedUIStatePatch;
2026-05-19 14:11:09 +07:00
const updated = await patchSharedUIState(patch);
2026-05-14 19:46:47 +07:00
res.json(updated);
} catch (error) {
next(error);
}
});
return router;
}