Skip to content

Commit

Permalink
inject sample database if not running on test server
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Tilsch committed Jan 18, 2024
1 parent 1a230d6 commit f66d4f3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
10 changes: 10 additions & 0 deletions apps/exhibition-live/components/provider/adbContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createContext } from "react";
import { useOptionalLiveDemoEndpoint } from "../state/useOptionalLiveDemoEndpoint";

type AdbContextValue = {};
export const AdbContext = createContext<AdbContextValue>({});

export const AdbProvider = ({ children }: { children: React.ReactNode }) => {
useOptionalLiveDemoEndpoint();
return <AdbContext.Provider value={{}}>{children}</AdbContext.Provider>;
};
7 changes: 2 additions & 5 deletions apps/exhibition-live/components/state/useLocalSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,13 @@ const defaultSparqlEndpoints: SparqlEndpoint[] = [
label: "Production",
endpoint: "https://sdv-ahn-adbtest.slub-dresden.de/query",
active: true,
},
{
label: "Test",
endpoint: "http://sdvahndmgtest.slub-dresden.de:7878/query",
active: false,
provider: "oxigraph",
},
{
label: "Local",
endpoint: "http://localhost:7878/query",
active: false,
provider: "oxigraph",
},
{
label: "QLever local",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useEffect } from "react";
import { SparqlEndpoint, useSettings } from "./useLocalSettings";

/**
* This hook adds a demo endpoint to the list of endpoints if the app is not running on the test server.
* It is used to provide an open database connection for the live demo.
*/
export const useOptionalLiveDemoEndpoint = () => {
const { sparqlEndpoints, setSparqlEndpoints } = useSettings();
useEffect(() => {
const demoEndpointURI = "https://ausstellungsdatenbank.kuenste.live/query";
if (
window.location.hostname !== "sdv-ahn-adbtest.slub-dresden.de" &&
sparqlEndpoints.find((ep) => ep.endpoint === demoEndpointURI) ===
undefined
) {
console.log("useOptionalLiveDemoEndpoint: add demo endpoint");
const otherEndpoints = sparqlEndpoints.filter(
(endpoint) =>
endpoint.endpoint !== "https://sdv-ahn-adbtest.slub-dresden.de/query",
);
const liveDemoTestDatabase: SparqlEndpoint = {
label: "Live Demo Testdatabase",
endpoint: demoEndpointURI,
active: !Boolean(otherEndpoints.find((ep) => ep.active)),
provider: "oxigraph",
};
setSparqlEndpoints([liveDemoTestDatabase, ...otherEndpoints]);
}
}, [sparqlEndpoints, setSparqlEndpoints]);
};
3 changes: 2 additions & 1 deletion apps/exhibition-live/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { appWithTranslation, UserConfig } from "next-i18next";
import nextI18NextConfig from "../next-i18next.config";
import { GoogleOAuthProvider } from "@react-oauth/google";
import { AdbProvider } from "../components/provider/adbContext";

export const queryClient = new QueryClient();
const QueryClientProviderWrapper = ({
Expand All @@ -39,7 +40,7 @@ function App({ Component, pageProps }: AppProps) {
<GoogleOAuthProvider
clientId={process.env.NEXT_PUBLIC_GAPI_OAUTH_CLIENT_ID}
>
{<Component {...pageProps} />}
<AdbProvider>{<Component {...pageProps} />}</AdbProvider>
</GoogleOAuthProvider>
</NiceModal.Provider>
</SnackbarProvider>
Expand Down

0 comments on commit f66d4f3

Please sign in to comment.