2026-05-14 19:46:47 +07:00
|
|
|
import type { Router } from "express";
|
|
|
|
|
import express from "express";
|
|
|
|
|
import { createChildLogger } from "../logger";
|
|
|
|
|
|
|
|
|
|
const logger = createChildLogger("ui-state-routes");
|
|
|
|
|
|
|
|
|
|
export interface SharedUIState {
|
2026-05-15 15:58:38 +07:00
|
|
|
selectedVoiceGuild: string;
|
2026-05-14 19:46:47 +07:00
|
|
|
selectedVoiceChannel: string;
|
2026-05-15 15:58:38 +07:00
|
|
|
selectedTextGuild: string;
|
2026-05-14 19:46:47 +07:00
|
|
|
selectedTextChannel: string;
|
2026-05-16 21:42:28 +07:00
|
|
|
activeTab: "voice" | "messages" | "media" | "review";
|
2026-05-14 19:46:47 +07:00
|
|
|
isListening: boolean;
|
|
|
|
|
isStreaming: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-15 15:58:38 +07:00
|
|
|
export type SharedUIStatePatch = Partial<SharedUIState> & {
|
|
|
|
|
selectedGuild?: string;
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-14 19:46:47 +07:00
|
|
|
export interface UIStateRouteOptions {
|
|
|
|
|
getSharedUIState: () => SharedUIState;
|
2026-05-15 15:58:38 +07:00
|
|
|
patchSharedUIState: (patch: SharedUIStatePatch) => 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
|
|
|
|
|
router.post("/ui-state", (req, res, next) => {
|
|
|
|
|
try {
|
2026-05-15 15:58:38 +07:00
|
|
|
const patch = req.body as SharedUIStatePatch;
|
2026-05-14 19:46:47 +07:00
|
|
|
const updated = patchSharedUIState(patch);
|
|
|
|
|
res.json(updated);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
next(error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return router;
|
|
|
|
|
}
|