-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inject sample database if not running on test server
- Loading branch information
Sebastian Tilsch
committed
Jan 18, 2024
1 parent
1a230d6
commit f66d4f3
Showing
4 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
apps/exhibition-live/components/state/useOptionalLiveDemoEndpoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters