1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-31 03:09:44 +02:00

feat(edge-devices): set specific page to view [EE-2082] (#6869)

This commit is contained in:
Chaim Lev-Ari 2022-05-23 10:57:22 +03:00 committed by GitHub
parent 12cddbd896
commit b031a30f62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 892 additions and 639 deletions

View file

@ -0,0 +1,43 @@
import {
createContext,
useContext,
useMemo,
useReducer,
PropsWithChildren,
} from 'react';
import { EnvironmentId } from 'Portainer/environments/types';
interface RowContextState {
environmentId: EnvironmentId;
isLoading: boolean;
toggleIsLoading(): void;
}
const RowContext = createContext<RowContextState | null>(null);
export interface RowProviderProps {
environmentId: EnvironmentId;
}
export function RowProvider({
environmentId,
children,
}: PropsWithChildren<RowProviderProps>) {
const [isLoading, toggleIsLoading] = useReducer((state) => !state, false);
const state = useMemo(
() => ({ isLoading, toggleIsLoading, environmentId }),
[isLoading, toggleIsLoading, environmentId]
);
return <RowContext.Provider value={state}>{children}</RowContext.Provider>;
}
export function useRowContext() {
const context = useContext(RowContext);
if (!context) {
throw new Error('should be nested under RowProvider');
}
return context;
}