diff --git a/plugins/all-in-one/settings.tsx b/plugins/all-in-one/settings.tsx index 9b498b2..d70dae4 100644 --- a/plugins/all-in-one/settings.tsx +++ b/plugins/all-in-one/settings.tsx @@ -1,7 +1,10 @@ import { plugin } from "@vendetta"; +import { storage } from "@vendetta/plugin"; +import { useProxy } from "@vendetta/storage"; import { getAssetIDByName } from "@vendetta/ui/assets"; import { React } from "@vendetta/metro/common"; import { findByProps } from "@vendetta/metro"; +import { View } from "react-native"; const { ScrollView } = findByProps("ScrollView"); const { TableRowGroup, TableSwitchRow, Stack } = findByProps( @@ -10,144 +13,146 @@ const { TableRowGroup, TableSwitchRow, Stack } = findByProps( "Stack", ); -const get = (k: string, fallback: any = "") => plugin.storage[k] ?? fallback; -const set = (k: string, v: any) => (plugin.storage[k] = v); +// Initialize default settings if not exist +if (!storage.factSettings) { + storage.factSettings = { + sendAsReply: true, + includeCitation: false, + }; +} + +if (!storage.listSettings) { + storage.listSettings = { + pluginListAlwaysDetailed: false, + themeListAlwaysDetailed: false, + }; +} export default function Settings() { - const [_, forceUpdate] = React.useReducer((x) => ~x, 0); - const update = () => forceUpdate(); + useProxy(storage); + const [rerender, forceRerender] = React.useReducer((x) => x + 1, 0); return ( - - - {/* Facts Commands Settings */} - - { - set("factSettings", { - ...get("factSettings", {}), - sendAsReply: value, - }); - update(); - }} - /> - { - set("factSettings", { - ...get("factSettings", {}), - includeCitation: value, - }); - update(); - }} - /> - + + + + {/* Facts Commands Settings */} + + { + storage.factSettings.sendAsReply = v; + forceRerender(); + }} + /> + { + storage.factSettings.includeCitation = v; + forceRerender(); + }} + /> + - {/* Plugin List Settings */} - - { - set("listSettings", { - ...get("listSettings", {}), - pluginListAlwaysDetailed: value, - }); - update(); - }} - /> - + {/* Plugin List Settings */} + + { + storage.listSettings.pluginListAlwaysDetailed = v; + forceRerender(); + }} + /> + - {/* Theme List Settings */} - - { - set("listSettings", { - ...get("listSettings", {}), - themeListAlwaysDetailed: value, - }); - update(); - }} - /> - + {/* Theme List Settings */} + + { + storage.listSettings.themeListAlwaysDetailed = v; + forceRerender(); + }} + /> + - {/* Commands Overview */} - - - - - - - - - + {/* Commands Overview */} + + + + + + + + + - {/* About Section */} - - - - - + {/* About Section */} + + + + + + ); }