From 8dc0b826cadf519ddb1b5722a344797bba81c711 Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Wed, 28 Aug 2024 22:42:39 +0800 Subject: [PATCH] feat+refactor: Add empty list component and readd unproxied plugin warning --- src/core/i18n/default.json | 1 + src/core/ui/components/AddonPage.tsx | 73 +++++++++++++++----- src/core/ui/components/InstallButton.tsx | 41 ----------- src/core/ui/settings/pages/Fonts/index.tsx | 16 +++-- src/core/ui/settings/pages/Plugins/index.tsx | 26 ++++++- src/core/ui/settings/pages/Themes/index.tsx | 5 +- 6 files changed, 93 insertions(+), 69 deletions(-) delete mode 100644 src/core/ui/components/InstallButton.tsx diff --git a/src/core/i18n/default.json b/src/core/i18n/default.json index 7c4b078..83a9ccc 100644 --- a/src/core/i18n/default.json +++ b/src/core/i18n/default.json @@ -26,6 +26,7 @@ "CONFIRMATION_LINK_IS_A_TYPE": "This link is a **{urlType, select, plugin {Plugin} theme {Theme} other {Add-on}}**, would you like to install it?", "CONNECT_TO_DEBUG_WEBSOCKET": "Connect to debug websocket", "CONNECT_TO_REACT_DEVTOOLS": "Connect to React DevTools", + "CONTINUE": "Continue", "COPIED_TO_CLIPBOARD": "Copied to clipboard", "COPY_URL": "Copy URL", "DEBUG": "Debug", diff --git a/src/core/ui/components/AddonPage.tsx b/src/core/ui/components/AddonPage.tsx index 335fa78..b5dec66 100644 --- a/src/core/ui/components/AddonPage.tsx +++ b/src/core/ui/components/AddonPage.tsx @@ -7,12 +7,12 @@ import { HTTP_REGEX_MULTI } from "@lib/utils/constants"; import { lazyDestructure } from "@lib/utils/lazy"; import { findByProps } from "@metro"; import { clipboard } from "@metro/common"; -import { FlashList, FloatingActionButton, HelpMessage, IconButton } from "@metro/common/components"; +import { Button, FlashList, FloatingActionButton, HelpMessage, IconButton, Text } from "@metro/common/components"; import { showInputAlert } from "@ui/alerts"; import { ErrorBoundary, Search } from "@ui/components"; import fuzzysort from "fuzzysort"; -import { ComponentType, ReactNode, useMemo } from "react"; -import { View } from "react-native"; +import { ComponentType, ReactNode, useCallback, useMemo } from "react"; +import { Image, View } from "react-native"; const { showSimpleActionSheet, hideActionSheet } = lazyDestructure(() => findByProps("showSimpleActionSheet")); @@ -21,15 +21,19 @@ type SearchKeywords = Array string)>; interface AddonPageProps { title: string; items: I[]; + searchKeywords: SearchKeywords; sortOptions?: Record number>; - fetchFunction?: (url: string) => Promise; resolveItem?: (value: I) => T | undefined; safeModeHint?: { message?: string; footer?: ReactNode; } - searchKeywords: SearchKeywords; - onFabPress?: () => void; + installAction?: { + label?: string; + // Ignored when onPress is defined! + fetchFn?: (url: string) => Promise; + onPress?: () => void; + } CardComponent: ComponentType>; ListHeaderComponent?: ComponentType; ListFooterComponent?: ComponentType; @@ -50,6 +54,42 @@ export default function AddonPage({ CardComponent, ...props }: return fuzzysort.go(search, items, { keys: props.searchKeywords, all: true }); }, [props.items, sortFn, search]); + const onInstallPress = useCallback(() => { + if (!props.installAction) return () => {}; + const { onPress, fetchFn } = props.installAction; + if (fetchFn) { + clipboard.getString().then((content: string) => + showInputAlert({ + title: props.installAction?.label, + initialValue: content.match(HTTP_REGEX_MULTI)?.[0] ?? "", + placeholder: Strings.URL_PLACEHOLDER, + onConfirm: (input: string) => fetchFn(input), + confirmText: Strings.INSTALL, + cancelText: Strings.CANCEL, + }) + ); + } else { + onPress?.(); + } + }, []); + + if (results.length === 0 && !search) { + return + + + + Oops! Nothing to see here… yet! + + +