From 9511f174498dfa5758ad60a2e918220a685849e0 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Mon, 21 Oct 2024 19:34:39 +0700 Subject: [PATCH] feat: show error when failing to import font entries --- .../ui/settings/pages/Fonts/FontEditor.tsx | 22 ++++++++++++++++--- src/lib/addons/fonts/index.ts | 18 +++++++-------- src/lib/api/native/fs.ts | 2 +- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/core/ui/settings/pages/Fonts/FontEditor.tsx b/src/core/ui/settings/pages/Fonts/FontEditor.tsx index 0f65caac..a971f810 100644 --- a/src/core/ui/settings/pages/Fonts/FontEditor.tsx +++ b/src/core/ui/settings/pages/Fonts/FontEditor.tsx @@ -3,6 +3,8 @@ import { createProxy, useProxy } from "@core/vendetta/storage"; import { FontDefinition, fonts, removeFont, saveFont, validateFont } from "@lib/addons/fonts"; import { getCurrentTheme } from "@lib/addons/themes"; import { findAssetId } from "@lib/api/assets"; +import { semanticColors } from "@lib/ui/color"; +import { createStyles, TextStyleSheet } from "@lib/ui/styles"; import { safeFetch } from "@lib/utils"; import { NavigationNative } from "@metro/common"; import { ActionSheet, BottomSheetTitleHeader, Button, IconButton, Stack, TableRow, TableRowGroup, Text, TextInput } from "@metro/common/components"; @@ -11,6 +13,13 @@ import { ErrorBoundary } from "@ui/components"; import { useMemo, useRef, useState } from "react"; import { ScrollView, View } from "react-native"; +const useStyles = createStyles({ + errorText: { + ...TextStyleSheet["text-xs/medium"], + color: semanticColors.TEXT_DANGER, + }, +}) + const actionSheet = findByPropsLazy("hideActionSheet"); function guessFontName(urls: string[]) { @@ -245,6 +254,9 @@ export default function FontEditor(props: { const [name, setName] = useState(props.name); const [source, setSource] = useState(); const [importing, setIsImporting] = useState(false); + const [errors, setErrors] = useState>(); + + const styles = useStyles(); const memoEntry = useMemo(() => { return createProxy(props.name ? { ...fonts[props.name].main } : {}).proxy; @@ -297,11 +309,13 @@ export default function FontEditor(props: { onChange={setName} /> - {Object.entries(fontEntries).map(([name, url]) => { + {Object.entries(fontEntries).map(([name, url], index) => { + const error = errors?.[index]; + return + subLabel={error ? {error.message} : url} + trailing={ } /> + {errors && Some font entries cannot be imported. Please modify the entries and try again.}