Files
spoolman2/client/src/components/version.tsx
Donkie bc32f1e890 Now supports running under a sub path
Just set the SPOOLMAN_BASE_PATH environment variable and it should work.

Resolves #95
2024-05-10 11:37:09 +02:00

47 lines
1.0 KiB
TypeScript

import { useQuery } from "@tanstack/react-query";
import { Spin, Typography } from "antd";
import { getAPIURL } from "../utils/url";
const { Text } = Typography;
interface IInfo {
version: string;
debug_mode: boolean;
automatic_backups: boolean;
data_dir: string;
backups_dir: string;
db_type: string;
git_commit?: string;
build_date?: string;
}
export const Version: React.FC = () => {
const infoResult = useQuery<IInfo>({
queryKey: ["info"],
queryFn: async () => {
const response = await fetch(getAPIURL() + "/info");
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
},
});
if (infoResult.isLoading) {
return <Spin />;
}
if (infoResult.isError) {
return <span>Unknown</span>;
}
const info = infoResult.data;
const commit_suffix = info.git_commit ? <Text type="secondary">{` (${info.git_commit})`}</Text> : <></>;
return (
<span title={info.build_date}>
{info.version}
{commit_suffix}
</span>
);
};