2025-07-07 22:30:33 -04:00
|
|
|
import React, { createContext, useMemo } from "react";
|
|
|
|
|
import { useLocation } from "react-router-dom";
|
2025-07-09 18:29:50 -04:00
|
|
|
import { lsKeys } from "@/util/env";
|
2025-07-07 22:30:33 -04:00
|
|
|
|
|
|
|
|
function useIsDebugMode() {
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
return useMemo(
|
|
|
|
|
() => location.pathname.includes("debug"),
|
|
|
|
|
[location.pathname],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-09 18:29:50 -04:00
|
|
|
function getCurrentBrowserSessionId() {
|
|
|
|
|
const stored = localStorage.getItem(lsKeys.optimisticBrowserSession);
|
|
|
|
|
let browserSessionId: string | null = null;
|
|
|
|
|
try {
|
|
|
|
|
const parsed = JSON.parse(stored ?? "");
|
|
|
|
|
const { browser_session_id } = parsed;
|
|
|
|
|
browserSessionId = browser_session_id as string;
|
|
|
|
|
} catch {
|
|
|
|
|
// pass
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return browserSessionId;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-07 22:30:33 -04:00
|
|
|
export type DebugStoreContextType = {
|
|
|
|
|
isDebugMode: boolean;
|
2025-07-09 18:29:50 -04:00
|
|
|
getCurrentBrowserSessionId: () => string | null;
|
2025-07-07 22:30:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const DebugStoreContext = createContext<
|
|
|
|
|
DebugStoreContextType | undefined
|
|
|
|
|
>(undefined);
|
|
|
|
|
|
|
|
|
|
export const DebugStoreProvider: React.FC<{ children: React.ReactNode }> = ({
|
|
|
|
|
children,
|
|
|
|
|
}) => {
|
|
|
|
|
const isDebugMode = useIsDebugMode();
|
|
|
|
|
|
|
|
|
|
return (
|
2025-07-09 18:29:50 -04:00
|
|
|
<DebugStoreContext.Provider
|
|
|
|
|
value={{ isDebugMode, getCurrentBrowserSessionId }}
|
|
|
|
|
>
|
2025-07-07 22:30:33 -04:00
|
|
|
{children}
|
|
|
|
|
</DebugStoreContext.Provider>
|
|
|
|
|
);
|
|
|
|
|
};
|