From 32b3a0295cca9b8bf701f53b59a1c88ad4e34bcd Mon Sep 17 00:00:00 2001 From: Beef Date: Sat, 15 Apr 2023 02:57:03 +0100 Subject: [PATCH] [UI] Overall overhaul --- src/ui/settings/components/AddonPage.tsx | 38 ++++++++++++++++ src/ui/settings/components/AssetDisplay.tsx | 11 +---- src/ui/settings/components/Card.tsx | 9 ++-- src/ui/settings/components/PluginCard.tsx | 13 ++---- .../settings/components/SettingsSection.tsx | 2 +- src/ui/settings/components/ThemeCard.tsx | 9 +--- src/ui/settings/pages/AssetBrowser.tsx | 10 ++--- src/ui/settings/pages/Plugins.tsx | 23 +++------- src/ui/settings/pages/Themes.tsx | 44 ++++++++----------- 9 files changed, 81 insertions(+), 78 deletions(-) create mode 100644 src/ui/settings/components/AddonPage.tsx diff --git a/src/ui/settings/components/AddonPage.tsx b/src/ui/settings/components/AddonPage.tsx new file mode 100644 index 0000000..eb5e30a --- /dev/null +++ b/src/ui/settings/components/AddonPage.tsx @@ -0,0 +1,38 @@ +import { Indexable } from "@types"; +import { ReactNative as RN } from "@metro/common"; +import { useProxy } from "@lib/storage"; +import { HelpMessage, ErrorBoundary, Search } from "@ui/components"; +import { CardWrapper } from "@ui/settings/components/Card"; +import settings from "@lib/settings"; + +interface AddonPageProps { + items: Indexable; + safeModeMessage: string; + safeModeExtras?: JSX.Element | JSX.Element[]; + card: React.ComponentType>; +} + +export default function AddonPage({ items, safeModeMessage, safeModeExtras, card: CardComponent }: AddonPageProps) { + useProxy(settings) + useProxy(items); + const [search, setSearch] = React.useState(""); + + return ( + + + {settings.safeMode?.enabled && + {safeModeMessage} + {safeModeExtras} + } + setSearch(v.toLowerCase())} + placeholder="Search" + /> + {/* TODO: When I am more awake, implement better searching than just by ID */} + {/* TODO: Also when I am more awake, make the search bar not scroll with the cards */} + {Object.values(items).filter(i => i.id?.toLowerCase().includes(search)).map((i, id) => )} + + + ) +} \ No newline at end of file diff --git a/src/ui/settings/components/AssetDisplay.tsx b/src/ui/settings/components/AssetDisplay.tsx index 31f058e..242d737 100644 --- a/src/ui/settings/components/AssetDisplay.tsx +++ b/src/ui/settings/components/AssetDisplay.tsx @@ -1,5 +1,5 @@ import { Asset } from "@types"; -import { ReactNative as RN, stylesheet, clipboard } from "@metro/common"; +import { ReactNative as RN, clipboard } from "@metro/common"; import { showToast } from "@ui/toasts"; import { getAssetIDByName } from "@ui/assets"; import { Forms } from "@ui/components"; @@ -10,18 +10,11 @@ interface AssetDisplayProps { const { FormRow } = Forms; -const styles = stylesheet.createThemedStyleSheet({ - asset: { - width: 32, - height: 32, - } -}); - export default function AssetDisplay({ asset }: AssetDisplayProps) { return ( } + trailing={} onPress={() => { clipboard.setString(asset.name); showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link")); diff --git a/src/ui/settings/components/Card.tsx b/src/ui/settings/components/Card.tsx index ca1f14e..5b8bdc4 100644 --- a/src/ui/settings/components/Card.tsx +++ b/src/ui/settings/components/Card.tsx @@ -13,8 +13,6 @@ const styles = stylesheet.createThemedStyleSheet({ card: { backgroundColor: semanticColors?.BACKGROUND_SECONDARY, borderRadius: 5, - marginHorizontal: 10, - marginBottom: 10, }, header: { padding: 0, @@ -44,6 +42,11 @@ interface OverflowAction extends Action { isDestructive?: boolean; } +export interface CardWrapper { + item: T; + index: number; +} + interface CardProps { index?: number; headerLabel: string | React.ComponentType; @@ -61,7 +64,7 @@ export default function Card(props: CardProps) { let pressableState = props.toggleValue ?? false; return ( - + ) { const settings = getSettings(plugin.id); const navigation = NavigationNative.useNavigation(); const [removed, setRemoved] = React.useState(false); diff --git a/src/ui/settings/components/SettingsSection.tsx b/src/ui/settings/components/SettingsSection.tsx index 69d9f3b..842e271 100644 --- a/src/ui/settings/components/SettingsSection.tsx +++ b/src/ui/settings/components/SettingsSection.tsx @@ -12,7 +12,7 @@ export default function SettingsSection() { return ( - + } diff --git a/src/ui/settings/components/ThemeCard.tsx b/src/ui/settings/components/ThemeCard.tsx index 3d691cd..8747c50 100644 --- a/src/ui/settings/components/ThemeCard.tsx +++ b/src/ui/settings/components/ThemeCard.tsx @@ -7,19 +7,14 @@ import { getAssetIDByName } from "@ui/assets"; import { showConfirmationAlert } from "@ui/alerts"; import { showToast } from "@ui/toasts"; import settings from "@lib/settings"; -import Card from "@ui/settings/components/Card"; - -interface ThemeCardProps { - theme: Theme; - index: number; -} +import Card, { CardWrapper } from "@ui/settings/components/Card"; async function selectAndReload(value: boolean, id: string) { await selectTheme(value ? id : "default"); BundleUpdaterManager.reload(); } -export default function ThemeCard({ theme, index }: ThemeCardProps) { +export default function ThemeCard({ item: theme, index }: CardWrapper) { useProxy(settings); const [removed, setRemoved] = React.useState(false); diff --git a/src/ui/settings/pages/AssetBrowser.tsx b/src/ui/settings/pages/AssetBrowser.tsx index 119ba60..e1ab53b 100644 --- a/src/ui/settings/pages/AssetBrowser.tsx +++ b/src/ui/settings/pages/AssetBrowser.tsx @@ -6,7 +6,6 @@ import AssetDisplay from "@ui/settings/components/AssetDisplay"; const { FormDivider } = Forms; - export default function AssetBrowser() { const [search, setSearch] = React.useState(""); @@ -14,17 +13,14 @@ export default function AssetBrowser() { setSearch(v)} placeholder="Search" /> a.name.includes(search) || a.id.toString() === search)} - renderItem={({ item }) => ( - <> - - - - )} + renderItem={({ item }) => } + ItemSeparatorComponent={FormDivider} keyExtractor={item => item.name} /> diff --git a/src/ui/settings/pages/Plugins.tsx b/src/ui/settings/pages/Plugins.tsx index fc2e1cd..59bf8a0 100644 --- a/src/ui/settings/pages/Plugins.tsx +++ b/src/ui/settings/pages/Plugins.tsx @@ -1,27 +1,18 @@ -import { ReactNative as RN } from "@metro/common"; +import { Plugin } from "@types"; import { useProxy } from "@lib/storage"; import { plugins } from "@lib/plugins"; -import { HelpMessage } from "@ui/components"; import settings from "@lib/settings"; +import AddonPage from "@ui/settings/components/AddonPage"; import PluginCard from "@ui/settings/components/PluginCard"; -import ErrorBoundary from "@ui/components/ErrorBoundary"; export default function Plugins() { useProxy(settings) - useProxy(plugins); return ( - - - {settings.safeMode?.enabled && - You are in Safe Mode, so plugins cannot be loaded. Disable any misbehaving plugins, then return to Normal Mode from the General settings page. - } - } - keyExtractor={item => item.id} - /> - - + + items={plugins} + safeModeMessage="You are in Safe Mode, so plugins cannot be loaded. Disable any misbehaving plugins, then return to Normal Mode from the General settings page." + card={PluginCard} + /> ) } \ No newline at end of file diff --git a/src/ui/settings/pages/Themes.tsx b/src/ui/settings/pages/Themes.tsx index d479eab..a1b2489 100644 --- a/src/ui/settings/pages/Themes.tsx +++ b/src/ui/settings/pages/Themes.tsx @@ -1,36 +1,28 @@ -import { ButtonColors } from "@types"; -import { ReactNative as RN } from "@metro/common"; -import { themes } from "@lib/themes"; +import { Theme, ButtonColors } from "@types"; import { useProxy } from "@lib/storage"; -import { ErrorBoundary, Button, HelpMessage } from "@ui/components"; +import { themes } from "@lib/themes"; +import { Button } from "@ui/components"; import settings from "@lib/settings"; +import AddonPage from "@ui/settings/components/AddonPage"; import ThemeCard from "@ui/settings/components/ThemeCard"; export default function Themes() { useProxy(settings); - useProxy(themes); return ( - - - {settings.safeMode?.enabled && - You are in Safe Mode, meaning themes have been temporarily disabled.{settings.safeMode?.currentThemeId && " If a theme appears to be causing the issue, you can press below to disable it persistently."} - {settings.safeMode?.currentThemeId &&