import { CardWrapper } from "@core/ui/components/AddonCard"; import { findAssetId } from "@lib/api/assets"; import { settings } from "@lib/api/settings"; import { dismissAlert, openAlert } from "@lib/ui/alerts"; import { showSheet } from "@lib/ui/sheets"; import isValidHttpUrl from "@lib/utils/isValidHttpUrl"; import { lazyDestructure } from "@lib/utils/lazy"; import { findByProps } from "@metro"; import { clipboard, NavigationNative } from "@metro/common"; import { AlertActionButton, AlertModal, Button, FlashList, FloatingActionButton, HelpMessage, IconButton, Stack, Text, TextInput } from "@metro/common/components"; import { ErrorBoundary, Search } from "@ui/components"; import { isNotNil } from "es-toolkit"; import fuzzysort from "fuzzysort"; import { ComponentType, ReactNode, useCallback, useEffect, useMemo } from "react"; import { Image, ScrollView, View } from "react-native"; const { showSimpleActionSheet, hideActionSheet } = lazyDestructure(() => findByProps("showSimpleActionSheet")); type SearchKeywords = Array string)>; interface AddonPageProps { title: string; items: I[]; searchKeywords: SearchKeywords; sortOptions?: Record number>; resolveItem?: (value: I) => T | undefined; safeModeHint?: { message?: string; footer?: ReactNode; }; installAction?: { label?: string; // Ignored when onPress is defined! fetchFn?: (url: string) => Promise; onPress?: () => void; }; OptionsActionSheetComponent?: ComponentType; CardComponent: ComponentType>; ListHeaderComponent?: ComponentType; ListFooterComponent?: ComponentType; } function InputAlert(props: { label: string, fetchFn: (url: string) => Promise; }) { const [value, setValue] = React.useState(""); const [error, setError] = React.useState(""); const [isFetching, setIsFetching] = React.useState(false); function onConfirmWrapper() { setIsFetching(true); props.fetchFn(value) .then(() => dismissAlert("AddonInputAlert")) .catch((e: unknown) => e instanceof Error ? setError(e.message) : String(e)) .finally(() => setIsFetching(false)); } return { setValue(v); if (error) setError(""); }} returnKeyType="done" onSubmitEditing={onConfirmWrapper} state={error ? "error" : undefined} errorMessage={error || undefined} />