A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat: add server version display to mobile app settings (#2276)
Mohamed Bassembd969b34d76b
diff --git a/apps/mobile/app/dashboard/(tabs)/settings.tsx b/apps/mobile/app/dashboard/(tabs)/settings.tsxindex 7c1e00d6..db19b6fe 100644--- a/apps/mobile/app/dashboard/(tabs)/settings.tsx+++ b/apps/mobile/app/dashboard/(tabs)/settings.tsx@@ -2,6 +2,7 @@ import { useEffect } from "react";import { ActivityIndicator, Pressable, Switch, View } from "react-native";import { Slider } from "react-native-awesome-slider";import { useSharedValue } from "react-native-reanimated";+import Constants from "expo-constants";import { Link } from "expo-router";import { Button } from "@/components/ui/Button";import ChevronRight from "@/components/ui/ChevronRight";@@ -9,6 +10,7 @@ import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView";import { Divider } from "@/components/ui/Divider";import PageTitle from "@/components/ui/PageTitle";import { Text } from "@/components/ui/Text";+import { useServerVersion } from "@/lib/hooks";import { useSession } from "@/lib/session";import useAppSettings from "@/lib/settings";import { api } from "@/lib/trpc";@@ -30,6 +32,11 @@ export default function Dashboard() {}, [settings]);const { data, error, isLoading } = api.users.whoami.useQuery();+ const {+ data: serverVersion,+ isLoading: isServerVersionLoading,+ error: serverVersionError,+ } = useServerVersion();if (error?.data?.code === "UNAUTHORIZED") {logout();@@ -141,6 +148,19 @@ export default function Dashboard() {><Text>Log Out</Text></Button>+ <View className="mt-4 w-full gap-1">+ <Text className="text-center text-sm text-muted-foreground">+ App Version: {Constants.expoConfig?.version ?? "unknown"}+ </Text>+ <Text className="text-center text-sm text-muted-foreground">+ Server Version:{" "}+ {isServerVersionLoading+ ? "Loading..."+ : serverVersionError+ ? "unavailable"+ : (serverVersion ?? "unknown")}+ </Text>+ </View></View></CustomSafeAreaView>);diff --git a/apps/mobile/lib/hooks.ts b/apps/mobile/lib/hooks.tsindex 38ecebea..3540df23 100644--- a/apps/mobile/lib/hooks.ts+++ b/apps/mobile/lib/hooks.ts@@ -1,4 +1,5 @@import { ImageURISource } from "react-native";+import { useQuery } from "@tanstack/react-query";import useAppSettings from "./settings";import { buildApiHeaders } from "./utils";@@ -10,3 +11,25 @@ export function useAssetUrl(assetId: string): ImageURISource {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+ });+}