Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.2 kB ยท 37 lines
TSX
1234567891011121314151617181920212223242526272829303132333435363738"use client";
import { useParams } from "next/navigation";import { type ReactNode, createContext, useContext } from "react";
type ChatSessionContextValue = { sessionId: number | undefined;};
const ChatSessionContext = createContext<ChatSessionContextValue | null>(null);
export function ChatSessionProvider({ children }: { children: ReactNode }) { const params = useParams<{ id?: string | string[] }>(); // Mirror the dynamic layout's `parseInt`-acceptance so the sidebar's // `active` highlight stays in sync. `parseInt` would truncate // "123abc" โ 123; the digit-only guard prevents that leak. const urlSessionId = typeof params.id === "string" && /^\d+$/.test(params.id) ? Number.parseInt(params.id, 10) || undefined : undefined;
return ( <ChatSessionContext.Provider value={{ sessionId: urlSessionId }}> {children} </ChatSessionContext.Provider> );}
export function useChatSessionContext(): ChatSessionContextValue { const ctx = useContext(ChatSessionContext); if (!ctx) { throw new Error( "useChatSessionContext must be used within <ChatSessionProvider>", ); } return ctx;}