Some checks failed
Deploy to Server / deploy (push) Failing after 37s
EnvironmentContext holds current env as React state. On change, QueryInvalidatorOnEnvChange calls queryClient.invalidateQueries() so all content/list pages refetch immediately without manual reload. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
38 lines
933 B
TypeScript
38 lines
933 B
TypeScript
"use client";
|
|
|
|
import { createContext, useContext, useState, useEffect, type ReactNode } from "react";
|
|
import { getCurrentEnvironment, setCurrentEnvironment } from "@/lib/api";
|
|
|
|
type EnvironmentContextType = {
|
|
environment: string | null;
|
|
setEnvironment: (env: string) => void;
|
|
};
|
|
|
|
const EnvironmentContext = createContext<EnvironmentContextType>({
|
|
environment: null,
|
|
setEnvironment: () => {},
|
|
});
|
|
|
|
export function EnvironmentProvider({ children }: { children: ReactNode }) {
|
|
const [environment, setEnv] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
setEnv(getCurrentEnvironment());
|
|
}, []);
|
|
|
|
function setEnvironment(env: string) {
|
|
setCurrentEnvironment(env);
|
|
setEnv(env);
|
|
}
|
|
|
|
return (
|
|
<EnvironmentContext.Provider value={{ environment, setEnvironment }}>
|
|
{children}
|
|
</EnvironmentContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useEnvironment() {
|
|
return useContext(EnvironmentContext);
|
|
}
|