refactor(frontend): extract shared stores and components into packages

- Create @multica/fetch package for HTTP client and URL config
- Migrate hub store and hub-init hook to @multica/store
- Move HubSidebar component to @multica/ui for web/desktop reuse
- Update web app imports to use shared packages
- Remove counter store example and its component-example usage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Naiyuan Qing 2026-02-02 10:37:17 +08:00
parent 46b7906272
commit 63861d03c6
15 changed files with 143 additions and 127 deletions

View file

@ -0,0 +1,15 @@
let consoleUrl = "http://localhost:4000"
let gatewayUrl = "http://localhost:3000"
export function setConfig(config: { consoleUrl?: string; gatewayUrl?: string }) {
if (config.consoleUrl) consoleUrl = config.consoleUrl
if (config.gatewayUrl) gatewayUrl = config.gatewayUrl
}
export function getConsoleUrl(): string {
return consoleUrl
}
export function getGatewayUrl(): string {
return gatewayUrl
}

View file

@ -0,0 +1,28 @@
import { getConsoleUrl } from "./config"
export class HttpError extends Error {
constructor(
public status: number,
public statusText: string,
) {
super(`HTTP ${status}: ${statusText}`)
}
}
async function request<T>(method: string, path: string, body?: unknown): Promise<T> {
const res = await fetch(`${getConsoleUrl()}${path}`, {
method,
headers: body ? { "Content-Type": "application/json" } : undefined,
body: body ? JSON.stringify(body) : undefined,
})
if (!res.ok) throw new HttpError(res.status, res.statusText)
return res.json()
}
/** Console REST API */
export const consoleApi = {
get: <T>(path: string) => request<T>("GET", path),
post: <T>(path: string, body?: unknown) => request<T>("POST", path, body),
put: <T>(path: string, body: unknown) => request<T>("PUT", path, body),
delete: <T>(path: string) => request<T>("DELETE", path),
}

View file

@ -0,0 +1,2 @@
export { setConfig, getConsoleUrl, getGatewayUrl } from "./config"
export { consoleApi, HttpError } from "./http-client"