feat: make automatisch info available
This commit is contained in:
38
packages/web/src/contexts/AutomatischInfo.tsx
Normal file
38
packages/web/src/contexts/AutomatischInfo.tsx
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { useQuery } from '@apollo/client';
|
||||||
|
|
||||||
|
import { GET_AUTOMATISCH_INFO } from 'graphql/queries/get-automatisch-info';
|
||||||
|
|
||||||
|
export type AutomatischInfoContextParams = {
|
||||||
|
isCloud: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AutomatischInfoContext =
|
||||||
|
React.createContext<AutomatischInfoContextParams>({
|
||||||
|
isCloud: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
type AutomatischInfoProviderProps = {
|
||||||
|
children: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AutomatischInfoProvider = (
|
||||||
|
props: AutomatischInfoProviderProps
|
||||||
|
): React.ReactElement => {
|
||||||
|
const { children } = props;
|
||||||
|
const { data } = useQuery(GET_AUTOMATISCH_INFO);
|
||||||
|
|
||||||
|
const isCloud = data?.getAutomatischInfo?.isCloud || false;
|
||||||
|
|
||||||
|
const value = React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
isCloud,
|
||||||
|
};
|
||||||
|
}, [isCloud]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AutomatischInfoContext.Provider value={value}>
|
||||||
|
{children}
|
||||||
|
</AutomatischInfoContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
10
packages/web/src/graphql/queries/get-automatisch-info.ts
Normal file
10
packages/web/src/graphql/queries/get-automatisch-info.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { gql } from '@apollo/client';
|
||||||
|
|
||||||
|
export const GET_AUTOMATISCH_INFO = gql`
|
||||||
|
query GetAutomatischInfo {
|
||||||
|
getAutomatischInfo {
|
||||||
|
isCloud
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
14
packages/web/src/hooks/useAutomatischInfo.ts
Normal file
14
packages/web/src/hooks/useAutomatischInfo.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { AutomatischInfoContext } from 'contexts/AutomatischInfo';
|
||||||
|
|
||||||
|
type UseAutomatischInfoReturn = {
|
||||||
|
isCloud: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function useAutomatischInfo(): UseAutomatischInfoReturn {
|
||||||
|
const automatischInfoContext = React.useContext(AutomatischInfoContext);
|
||||||
|
|
||||||
|
return {
|
||||||
|
isCloud: automatischInfoContext.isCloud,
|
||||||
|
};
|
||||||
|
}
|
7
packages/web/src/hooks/useCloud.ts
Normal file
7
packages/web/src/hooks/useCloud.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import useAutomatischInfo from './useAutomatischInfo';
|
||||||
|
|
||||||
|
export default function useCloud(): boolean {
|
||||||
|
const { isCloud } = useAutomatischInfo();
|
||||||
|
|
||||||
|
return isCloud;
|
||||||
|
}
|
@@ -5,6 +5,7 @@ import IntlProvider from 'components/IntlProvider';
|
|||||||
import ApolloProvider from 'components/ApolloProvider';
|
import ApolloProvider from 'components/ApolloProvider';
|
||||||
import SnackbarProvider from 'components/SnackbarProvider';
|
import SnackbarProvider from 'components/SnackbarProvider';
|
||||||
import { AuthenticationProvider } from 'contexts/Authentication';
|
import { AuthenticationProvider } from 'contexts/Authentication';
|
||||||
|
import { AutomatischInfoProvider } from 'contexts/AutomatischInfo';
|
||||||
import Router from 'components/Router';
|
import Router from 'components/Router';
|
||||||
import routes from 'routes';
|
import routes from 'routes';
|
||||||
import reportWebVitals from './reportWebVitals';
|
import reportWebVitals from './reportWebVitals';
|
||||||
@@ -13,11 +14,13 @@ ReactDOM.render(
|
|||||||
<SnackbarProvider>
|
<SnackbarProvider>
|
||||||
<AuthenticationProvider>
|
<AuthenticationProvider>
|
||||||
<ApolloProvider>
|
<ApolloProvider>
|
||||||
<IntlProvider>
|
<AutomatischInfoProvider>
|
||||||
<ThemeProvider>
|
<IntlProvider>
|
||||||
<Router>{routes}</Router>
|
<ThemeProvider>
|
||||||
</ThemeProvider>
|
<Router>{routes}</Router>
|
||||||
</IntlProvider>
|
</ThemeProvider>
|
||||||
|
</IntlProvider>
|
||||||
|
</AutomatischInfoProvider>
|
||||||
</ApolloProvider>
|
</ApolloProvider>
|
||||||
</AuthenticationProvider>
|
</AuthenticationProvider>
|
||||||
</SnackbarProvider>,
|
</SnackbarProvider>,
|
||||||
|
Reference in New Issue
Block a user