From b1bffebfd9ea0a95f2c59b3bb53859d7b33d63c2 Mon Sep 17 00:00:00 2001 From: kmmiio99o Date: Wed, 1 Oct 2025 16:18:11 +0200 Subject: [PATCH] Refactor settings page --- plugins/Commands/settings.tsx | 232 +++++++++++++++++++++++++++------- 1 file changed, 189 insertions(+), 43 deletions(-) diff --git a/plugins/Commands/settings.tsx b/plugins/Commands/settings.tsx index 0762b69..0a8e5ec 100644 --- a/plugins/Commands/settings.tsx +++ b/plugins/Commands/settings.tsx @@ -1,9 +1,11 @@ import { plugin } from "@vendetta"; import { storage } from "@vendetta/plugin"; import { useProxy } from "@vendetta/storage"; -import { React } from "@vendetta/metro/common"; +import { React, ReactNative as RN, stylesheet } from "@vendetta/metro/common"; import { findByProps } from "@vendetta/metro"; -import { View } from "react-native"; +import { semanticColors } from "@vendetta/ui"; +import { getAssetIDByName } from "@vendetta/ui/assets"; +import { Forms } from "@vendetta/ui/components"; import { alerts } from "@vendetta/ui"; const { ScrollView } = findByProps("ScrollView"); @@ -14,6 +16,166 @@ const { TableRowGroup, TableSwitchRow, Stack, TableRow } = findByProps( "TableRow", ); +// Header Component +function Header() { + const styles = stylesheet.createThemedStyleSheet({ + container: { + flexDirection: "column", + alignItems: "center", + paddingVertical: 24, + paddingHorizontal: 16, + }, + title: { + fontSize: 28, + fontWeight: "700", + color: semanticColors.TEXT_NORMAL, + marginBottom: 4, + }, + subtitle: { + fontSize: 16, + fontWeight: "500", + color: semanticColors.TEXT_MUTED, + }, + iconContainer: { + backgroundColor: semanticColors.BACKGROUND_SECONDARY, + borderRadius: 16, + padding: 12, + marginBottom: 16, + }, + icon: { + width: 32, + height: 32, + tintColor: semanticColors.TEXT_NORMAL, + }, + }); + + return ( + + + + + Commands + A collection of useful commands + + ); +} + +// Gary API Selection Component +function GaryAPISelection({ forceRerender }: { forceRerender: () => void }) { + const styles = stylesheet.createThemedStyleSheet({ + container: { + backgroundColor: semanticColors.BACKGROUND_SECONDARY, + borderRadius: 12, + marginHorizontal: 16, + marginVertical: 8, + padding: 16, + }, + title: { + fontSize: 18, + fontWeight: "600", + color: semanticColors.TEXT_NORMAL, + marginBottom: 12, + }, + optionContainer: { + flexDirection: "row", + alignItems: "center", + paddingVertical: 12, + paddingHorizontal: 8, + borderRadius: 8, + marginVertical: 2, + }, + selectedOption: { + backgroundColor: semanticColors.BACKGROUND_MODIFIER_SELECTED, + }, + optionText: { + fontSize: 16, + fontWeight: "500", + marginLeft: 12, + flex: 1, + }, + selectedText: { + color: semanticColors.TEXT_BRAND, + }, + normalText: { + color: semanticColors.TEXT_NORMAL, + }, + radioButton: { + width: 20, + height: 20, + borderRadius: 10, + borderWidth: 2, + borderColor: semanticColors.TEXT_MUTED, + alignItems: "center", + justifyContent: "center", + }, + selectedRadio: { + borderColor: semanticColors.TEXT_BRAND, + }, + radioInner: { + width: 10, + height: 10, + borderRadius: 5, + backgroundColor: semanticColors.TEXT_BRAND, + }, + }); + + const options = [ + { value: "gary", label: "Gary API", desc: "Original Gary cat images" }, + { value: "catapi", label: "Cat API", desc: "Random cat pictures" }, + { value: "minker", label: "Minker API", desc: "Minky images" }, + { value: "goober", label: "Goober API", desc: "Goober images" }, + ]; + + const currentSource = storage.garySettings?.imageSource || "gary"; + + return ( + + Gary Image Source + {options.map((option) => { + const isSelected = currentSource === option.value; + return ( + { + storage.garySettings.imageSource = option.value; + forceRerender(); + }} + > + + {isSelected && } + + + + {option.label} + + + {option.desc} + + + + ); + })} + + ); +} + // Initialize storage with default values if (!storage.factSettings) { storage.factSettings = { @@ -31,10 +193,7 @@ if (!storage.listSettings) { if (!storage.garySettings) { storage.garySettings = { - useGaryAPI: true, - useCatAPI: false, - useMinkerAPI: false, - useGooberAPI: false, + imageSource: "gary", }; } @@ -66,6 +225,16 @@ export default function Settings() { useProxy(storage); const [rerender, forceRerender] = React.useReducer((x) => x + 1, 0); + const styles = stylesheet.createThemedStyleSheet({ + container: { + flex: 1, + backgroundColor: semanticColors.BACKGROUND_PRIMARY, + }, + spacing: { + height: 16, + }, + }); + // Check for pending restart when unmounting React.useEffect(() => { return () => { @@ -88,23 +257,15 @@ export default function Settings() { forceRerender(); }; - const handleGaryAPIToggle = (apiName: string, value: boolean) => { - // Only allow one API to be selected at a time - if (value) { - storage.garySettings.useGaryAPI = apiName === "gary"; - storage.garySettings.useCatAPI = apiName === "catapi"; - storage.garySettings.useMinkerAPI = apiName === "minker"; - storage.garySettings.useGooberAPI = apiName === "goober"; - } - forceRerender(); - }; - return ( - + +
+ {/* Facts Commands */} @@ -262,32 +423,15 @@ export default function Settings() { value={storage.enabledCommands?.gary ?? true} onValueChange={(v) => handleCommandToggle("gary", v)} /> - handleGaryAPIToggle("gary", v)} - /> - handleGaryAPIToggle("catapi", v)} - /> - handleGaryAPIToggle("minker", v)} - /> - handleGaryAPIToggle("goober", v)} - /> + + {/* Custom Gary API Selection */} + + + + + {/* Credits */} @@ -311,7 +455,9 @@ export default function Settings() { /> + + - + ); }