From f8dfa8f7f777214e923430a7fb8431cfafc13a70 Mon Sep 17 00:00:00 2001 From: Donkie Date: Mon, 10 Jul 2023 12:11:03 +0200 Subject: [PATCH] Client: Added version text Resolves #32 --- client/package-lock.json | 1 + client/package.json | 1 + client/src/App.tsx | 7 ++++++ client/src/components/version.tsx | 37 +++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 client/src/components/version.tsx diff --git a/client/package-lock.json b/client/package-lock.json index faabeda..cee41f9 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -14,6 +14,7 @@ "@refinedev/kbar": "^1.1.2", "@refinedev/react-router-v6": "^4.3.2", "@refinedev/simple-rest": "^4.5.0", + "@tanstack/react-query": "^4.29.19", "antd": "^5.6.4", "i18next": "^23.2.8", "i18next-browser-languagedetector": "^7.1.0", diff --git a/client/package.json b/client/package.json index 135f86b..667030a 100644 --- a/client/package.json +++ b/client/package.json @@ -13,6 +13,7 @@ "@refinedev/kbar": "^1.1.2", "@refinedev/react-router-v6": "^4.3.2", "@refinedev/simple-rest": "^4.5.0", + "@tanstack/react-query": "^4.29.19", "antd": "^5.6.4", "i18next": "^23.2.8", "i18next-browser-languagedetector": "^7.1.0", diff --git a/client/src/App.tsx b/client/src/App.tsx index e76bca3..76b6ac8 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -39,6 +39,8 @@ import { UserOutlined, } from "@ant-design/icons"; import { ConfigProvider } from "antd"; +import { Footer } from "antd/es/layout/layout"; +import { Version } from "./components/version"; function App() { const { t, i18n } = useTranslation(); @@ -137,6 +139,11 @@ function App() { )} /> )} + Footer={() => ( + + )} > diff --git a/client/src/components/version.tsx b/client/src/components/version.tsx new file mode 100644 index 0000000..2749145 --- /dev/null +++ b/client/src/components/version.tsx @@ -0,0 +1,37 @@ +import { useQuery } from "@tanstack/react-query"; +import { Spin } from "antd"; + +interface IInfo { + version: string; + debug_mode: boolean; + automatic_backups: boolean; + data_dir: string; + backups_dir: string; + db_type: string; +} + +export const Version: React.FC = () => { + const apiEndpoint = import.meta.env.VITE_APIURL; + + const infoResult = useQuery({ + queryKey: ["info"], + queryFn: async () => { + const response = await fetch(apiEndpoint + "/info"); + if (!response.ok) { + throw new Error("Network response was not ok"); + } + return response.json(); + }, + }); + + if (infoResult.isLoading) { + return ; + } + + if (infoResult.isError) { + return Unknown; + } + + const info = infoResult.data; + return {info.version}; +};