Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions configs/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
window.__APP_CONFIG__ = {
backendBaseUrl: "http://leda.kraysent.dev",
adminBaseUrl: "http://leda.kraysent.dev"
};
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://aladin.cds.unistra.fr/AladinLite/api/v3/latest/aladin.js"></script>
<script src="/configs/config.js"></script>
<title>HyperLEDA</title>
</head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ fix:
yarn eslint --fix src

gen:
yarn run openapi-ts -i http://dm2.sao.ru:81/api/openapi.json -o ./src/clients/backend
yarn run openapi-ts -i http://dm2.sao.ru:81/admin/api/openapi.json -o ./src/clients/admin
yarn run openapi-ts -i http://leda.sao.ru/api/openapi.json -o ./src/clients/backend
yarn run openapi-ts -i http://leda.sao.ru/admin/api/openapi.json -o ./src/clients/admin

image-build:
docker build . -t ghcr.io/hyperleda/hyperleda-webapp:$(GIT_VERSION)
Expand Down
11 changes: 11 additions & 0 deletions src/clients/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createClient as createBackendClient } from "./backend/client";
import { createClient as createAdminClient } from "./admin/client";
import { config } from "../config";

export const backendClient = createBackendClient({
baseUrl: config.backendBaseUrl,
});

export const adminClient = createAdminClient({
baseUrl: config.adminBaseUrl,
});
22 changes: 22 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
interface AppConfig {
backendBaseUrl: string;
adminBaseUrl: string;
}

declare global {
interface Window {
__APP_CONFIG__?: AppConfig;
}
}

function getConfig(): AppConfig {
if (typeof window === "undefined" || !window.__APP_CONFIG__) {
throw new Error(
"App configuration is required. Please set window.__APP_CONFIG__",
);
}

return window.__APP_CONFIG__;
}

export const config = getConfig();
2 changes: 2 additions & 0 deletions src/pages/CrossmatchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ErrorPage } from "../components/ui/error-page";
import { Link } from "../components/ui/link";
import { useDataFetching } from "../hooks/useDataFetching";
import { Pagination } from "../components/ui/pagination";
import { adminClient } from "../clients/config";

interface CrossmatchFiltersProps {
tableName: string | null;
Expand Down Expand Up @@ -171,6 +172,7 @@ async function fetcher(
}

const response = await getCrossmatchRecordsAdminApiV1RecordsCrossmatchGet({
client: adminClient,
query: {
table_name: tableName,
status: status,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/ObjectDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Link } from "../components/ui/link";
import { querySimpleApiV1QuerySimpleGet } from "../clients/backend/sdk.gen";
import { PgcObject, Schema } from "../clients/backend/types.gen";
import { useDataFetching } from "../hooks/useDataFetching";
import { backendClient } from "../clients/config";

interface ObjectDetailsProps {
object: PgcObject;
Expand Down Expand Up @@ -55,6 +56,7 @@ async function fetcher(
}

const response = await querySimpleApiV1QuerySimpleGet({
client: backendClient,
query: {
pgcs: [Number(pgcId)],
},
Expand Down
2 changes: 2 additions & 0 deletions src/pages/RecordCrossmatchDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Schema as BackendSchema } from "../clients/backend/types.gen";
import { getResource } from "../resources/resources";
import { Link } from "../components/ui/link";
import { useDataFetching } from "../hooks/useDataFetching";
import { adminClient } from "../clients/config";

// TODO: remove when admin api uses the same structures as data api
function convertAdminSchemaToBackendSchema(
Expand Down Expand Up @@ -188,6 +189,7 @@ async function fetcher(
}

const response = await getRecordCrossmatchAdminApiV1RecordCrossmatchGet({
client: adminClient,
query: {
record_id: recordId,
},
Expand Down
2 changes: 2 additions & 0 deletions src/pages/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { QuerySimpleResponse } from "../clients/backend/types.gen";
import { Link } from "../components/ui/link";
import { Declination, RightAscension } from "../components/ui/astronomy";
import { Pagination } from "../components/ui/pagination";
import { backendClient } from "../clients/config";

function searchHandler(navigate: NavigateFunction) {
return function f(query: string) {
Expand Down Expand Up @@ -125,6 +126,7 @@ async function fetcher(
}

const response = await querySimpleApiV1QuerySimpleGet({
client: backendClient,
query: {
name: query,
page: page,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/TableDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Loading } from "../components/ui/loading";
import { ErrorPage } from "../components/ui/error-page";
import { getResource } from "../resources/resources";
import { useDataFetching } from "../hooks/useDataFetching";
import { backendClient } from "../clients/config";

function renderBibliography(bib: Bibliography): ReactElement {
let authors = "";
Expand Down Expand Up @@ -267,6 +268,7 @@ async function fetcher(
}

const response = await getTableAdminApiV1TableGet({
client: backendClient,
query: { table_name: tableName },
});
if (response.error) {
Expand Down