Instant env switch: invalidate all queries on environment change
Some checks failed
Deploy to Server / deploy (push) Failing after 37s
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>
This commit is contained in:
37
admin-ui/src/lib/EnvironmentContext.tsx
Normal file
37
admin-ui/src/lib/EnvironmentContext.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
"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);
|
||||
}
|
||||
Reference in New Issue
Block a user