aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/lib/hooks.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/mobile/lib/hooks.ts')
-rw-r--r--apps/mobile/lib/hooks.ts31
1 files changed, 29 insertions, 2 deletions
diff --git a/apps/mobile/lib/hooks.ts b/apps/mobile/lib/hooks.ts
index 38ecebea..c3cb9d22 100644
--- a/apps/mobile/lib/hooks.ts
+++ b/apps/mobile/lib/hooks.ts
@@ -1,12 +1,39 @@
-import { ImageURISource } from "react-native";
+import { useQuery } from "@tanstack/react-query";
import useAppSettings from "./settings";
import { buildApiHeaders } from "./utils";
-export function useAssetUrl(assetId: string): ImageURISource {
+interface AssetSource {
+ uri: string;
+ headers: Record<string, string>;
+}
+
+export function useAssetUrl(assetId: string): AssetSource {
const { settings } = useAppSettings();
return {
uri: `${settings.address}/api/assets/${assetId}`,
headers: buildApiHeaders(settings.apiKey, settings.customHeaders),
};
}
+
+export function useServerVersion() {
+ const { settings } = useAppSettings();
+
+ return useQuery({
+ queryKey: ["serverVersion", settings.address],
+ queryFn: async () => {
+ const response = await fetch(`${settings.address}/api/version`, {
+ headers: buildApiHeaders(settings.apiKey, settings.customHeaders),
+ });
+
+ if (!response.ok) {
+ throw new Error(`Failed to fetch server version: ${response.status}`);
+ }
+
+ const data = await response.json();
+ return data.version as string;
+ },
+ enabled: !!settings.address,
+ staleTime: 1000 * 60 * 5, // Cache for 5 minutes
+ });
+}