From 9f3014a430c6cbe84a2008deb75d489888b64517 Mon Sep 17 00:00:00 2001 From: Gauvain Date: Thu, 4 Jun 2026 11:40:40 +0200 Subject: [PATCH] fix(settings): address CodeRabbit review (guard clipboard copy, reuse getUserImageUrl, hoist search title) --- .../(tabs)/(home)/settings/account/page.tsx | 10 +++++++--- components/settings/index/SettingsHero.tsx | 15 ++++++++++----- components/settings/index/useSettingsSearch.ts | 17 ++++++----------- translations/en.json | 3 ++- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/(auth)/(tabs)/(home)/settings/account/page.tsx b/app/(auth)/(tabs)/(home)/settings/account/page.tsx index f4a7c16d3..d3f39a9ee 100644 --- a/app/(auth)/(tabs)/(home)/settings/account/page.tsx +++ b/app/(auth)/(tabs)/(home)/settings/account/page.tsx @@ -20,9 +20,13 @@ export default function AccountPage() { const copyToken = async () => { if (!token) return; - await setStringAsync(token); - success(); - Alert.alert(t("home.settings.account.copied")); + try { + await setStringAsync(token); + success(); + Alert.alert(t("home.settings.account.copied")); + } catch { + Alert.alert(t("home.settings.account.copy_failed")); + } }; return ( diff --git a/components/settings/index/SettingsHero.tsx b/components/settings/index/SettingsHero.tsx index 9e0dfc3d9..dbae52eef 100644 --- a/components/settings/index/SettingsHero.tsx +++ b/components/settings/index/SettingsHero.tsx @@ -1,21 +1,26 @@ import { Ionicons } from "@expo/vector-icons"; import { Image } from "expo-image"; import { LinearGradient } from "expo-linear-gradient"; -import { useAtom } from "jotai"; +import { useAtomValue } from "jotai"; import type React from "react"; import { TouchableOpacity, View } from "react-native"; import { Text } from "@/components/common/Text"; import { apiAtom, userAtom } from "@/providers/JellyfinProvider"; +import { getUserImageUrl } from "@/utils/jellyfin/image/getUserImageUrl"; export const SettingsHero: React.FC<{ onPress: () => void }> = ({ onPress, }) => { - const [api] = useAtom(apiAtom); - const [user] = useAtom(userAtom); + const api = useAtomValue(apiAtom); + const user = useAtomValue(userAtom); const connected = Boolean(api && user); const imageUrl = - api && user?.Id && user.PrimaryImageTag - ? `${api.basePath}/Users/${user.Id}/Images/Primary?tag=${user.PrimaryImageTag}&quality=90` + api && user?.Id + ? (getUserImageUrl({ + serverAddress: api.basePath, + userId: user.Id, + primaryImageTag: user.PrimaryImageTag, + }) ?? undefined) : undefined; const host = api?.basePath?.replace(/^https?:\/\//, ""); diff --git a/components/settings/index/useSettingsSearch.ts b/components/settings/index/useSettingsSearch.ts index ad042f58a..ebbb14823 100644 --- a/components/settings/index/useSettingsSearch.ts +++ b/components/settings/index/useSettingsSearch.ts @@ -22,24 +22,19 @@ export const useSettingsSearch = (query: string): SearchResult[] => { for (const section of SETTINGS_CATALOG) { for (const e of section.entries) { if (e.platforms && !e.platforms.includes(os)) continue; - if ( - matchesQuery({ title: t(e.titleKey), keywords: e.keywords }, query) - ) { - results.push({ - id: e.id, - title: t(e.titleKey), - icon: e.icon, - target: e.target, - }); + const title = t(e.titleKey); + if (matchesQuery({ title, keywords: e.keywords }, query)) { + results.push({ id: e.id, title, icon: e.icon, target: e.target }); } } } for (const o of SETTINGS_SEARCH_INDEX) { if (o.platforms && !o.platforms.includes(os)) continue; - if (matchesQuery({ title: t(o.titleKey), keywords: o.keywords }, query)) { + const title = t(o.titleKey); + if (matchesQuery({ title, keywords: o.keywords }, query)) { results.push({ id: `${o.parentRoute}#${o.titleKey}`, - title: t(o.titleKey), + title, icon: "search", subtitle: t(o.parentTitleKey), target: { type: "route", route: o.parentRoute }, diff --git a/translations/en.json b/translations/en.json index 091121182..0e0691f6b 100644 --- a/translations/en.json +++ b/translations/en.json @@ -146,7 +146,8 @@ "account": { "title": "Account", "copy_token": "Copy token", - "copied": "Copied to clipboard" + "copied": "Copied to clipboard", + "copy_failed": "Couldn't copy to clipboard" }, "playback_controls": { "title": "Playback & Controls"