diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx index 8d468eb4..780ad64d 100644 --- a/apps/web/app/layout.tsx +++ b/apps/web/app/layout.tsx @@ -1,6 +1,6 @@ import type { Metadata } from "next"; import { Geist, Geist_Mono, Inter, Playfair_Display } from "next/font/google"; -import { setConfig } from "@multica/fetch"; +import { useGatewayStore } from "@multica/store"; import "@multica/ui/globals.css"; import { SidebarProvider, @@ -11,9 +11,10 @@ import { ThemeProvider } from "@multica/ui/components/theme-provider"; import { Toaster } from "@multica/ui/components/ui/sonner"; import { HubSidebar } from "@multica/ui/components/hub-sidebar"; -setConfig({ - gatewayUrl: process.env.NEXT_PUBLIC_GATEWAY_URL ?? "http://localhost:3000", -}); +const gatewayUrl = process.env.NEXT_PUBLIC_GATEWAY_URL; +if (gatewayUrl) { + useGatewayStore.getState().setGatewayUrl(gatewayUrl); +} const inter = Inter({ subsets: ["latin"], variable: "--font-sans" }); diff --git a/apps/web/package.json b/apps/web/package.json index 09bac1ef..954a4008 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -9,7 +9,6 @@ "lint": "eslint" }, "dependencies": { - "@multica/fetch": "workspace:*", "@multica/sdk": "workspace:*", "@multica/store": "workspace:*", "@multica/ui": "workspace:*", diff --git a/packages/store/package.json b/packages/store/package.json index e79cdef1..61a1b936 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -8,7 +8,6 @@ "./*": "./src/*.ts" }, "dependencies": { - "@multica/fetch": "workspace:*", "@multica/sdk": "workspace:*", "react": "catalog:", "sonner": "^2.0.7", diff --git a/packages/store/src/gateway.ts b/packages/store/src/gateway.ts index f7cf4958..fb70f6c0 100644 --- a/packages/store/src/gateway.ts +++ b/packages/store/src/gateway.ts @@ -1,9 +1,11 @@ import { create } from "zustand" import { GatewayClient, type ConnectionState, type DeviceInfo, type SendErrorResponse } from "@multica/sdk" -import { getGatewayUrl } from "@multica/fetch" import { useMessagesStore } from "./messages" +const DEFAULT_GATEWAY_URL = "http://localhost:3000" + interface GatewayState { + gatewayUrl: string connectionState: ConnectionState hubId: string | null hubs: DeviceInfo[] @@ -11,6 +13,7 @@ interface GatewayState { } interface GatewayActions { + setGatewayUrl: (url: string) => void connect: (deviceId: string) => void disconnect: () => void setHubId: (hubId: string) => void @@ -24,16 +27,19 @@ export type GatewayStore = GatewayState & GatewayActions let client: GatewayClient | null = null export const useGatewayStore = create()((set, get) => ({ + gatewayUrl: DEFAULT_GATEWAY_URL, connectionState: "disconnected", hubId: null, hubs: [], lastError: null, + setGatewayUrl: (url) => set({ gatewayUrl: url }), + connect: (deviceId) => { if (client) return client = new GatewayClient({ - url: getGatewayUrl(), + url: get().gatewayUrl, deviceId, deviceType: "client", }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6272ecc3..c576814f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -214,9 +214,6 @@ importers: '@hugeicons/react': specifier: ^1.1.4 version: 1.1.4(react@19.2.3) - '@multica/fetch': - specifier: workspace:* - version: link:../../packages/fetch '@multica/sdk': specifier: workspace:* version: link:../../packages/sdk @@ -285,9 +282,6 @@ importers: packages/store: dependencies: - '@multica/fetch': - specifier: workspace:* - version: link:../fetch '@multica/sdk': specifier: workspace:* version: link:../sdk