Update settings.tsx

This commit is contained in:
kmmiio99o 2025-09-27 20:15:20 +02:00
parent 7c3a5bf31c
commit 276d526d8c

View file

@ -1,7 +1,10 @@
import { plugin } from "@vendetta"; import { plugin } from "@vendetta";
import { storage } from "@vendetta/plugin";
import { useProxy } from "@vendetta/storage";
import { getAssetIDByName } from "@vendetta/ui/assets"; import { getAssetIDByName } from "@vendetta/ui/assets";
import { React } from "@vendetta/metro/common"; import { React } from "@vendetta/metro/common";
import { findByProps } from "@vendetta/metro"; import { findByProps } from "@vendetta/metro";
import { View } from "react-native";
const { ScrollView } = findByProps("ScrollView"); const { ScrollView } = findByProps("ScrollView");
const { TableRowGroup, TableSwitchRow, Stack } = findByProps( const { TableRowGroup, TableSwitchRow, Stack } = findByProps(
@ -10,144 +13,146 @@ const { TableRowGroup, TableSwitchRow, Stack } = findByProps(
"Stack", "Stack",
); );
const get = (k: string, fallback: any = "") => plugin.storage[k] ?? fallback; // Initialize default settings if not exist
const set = (k: string, v: any) => (plugin.storage[k] = v); if (!storage.factSettings) {
storage.factSettings = {
sendAsReply: true,
includeCitation: false,
};
}
if (!storage.listSettings) {
storage.listSettings = {
pluginListAlwaysDetailed: false,
themeListAlwaysDetailed: false,
};
}
export default function Settings() { export default function Settings() {
const [_, forceUpdate] = React.useReducer((x) => ~x, 0); useProxy(storage);
const update = () => forceUpdate(); const [rerender, forceRerender] = React.useReducer((x) => x + 1, 0);
return ( return (
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ padding: 10 }}> <View style={{ flex: 1 }}>
<Stack spacing={8}> <ScrollView style={{ flex: 1 }}>
{/* Facts Commands Settings */} <Stack spacing={8}>
<TableRowGroup title="Facts Settings"> {/* Facts Commands Settings */}
<TableSwitchRow <TableRowGroup title="Facts Settings">
label="Send as Reply" <TableSwitchRow
subLabel="Send facts as a reply to the command message" label="Send as Reply"
icon={getAssetIDByName("ic_reply_24px")} subLabel="Send facts as a reply to the command message"
value={get("factSettings.sendAsReply", true)} icon={getAssetIDByName("ic_reply_24px")}
onValueChange={(value: boolean) => { value={storage.factSettings.sendAsReply}
set("factSettings", { onValueChange={(v: boolean) => {
...get("factSettings", {}), storage.factSettings.sendAsReply = v;
sendAsReply: value, forceRerender();
}); }}
update(); />
}} <TableSwitchRow
/> label="Include Source Citation"
<TableSwitchRow subLabel="Include the source of facts when available"
label="Include Source Citation" icon={getAssetIDByName("ic_info")}
subLabel="Include the source of facts when available" value={storage.factSettings.includeCitation}
icon={getAssetIDByName("ic_info")} onValueChange={(v: boolean) => {
value={get("factSettings.includeCitation", false)} storage.factSettings.includeCitation = v;
onValueChange={(value: boolean) => { forceRerender();
set("factSettings", { }}
...get("factSettings", {}), />
includeCitation: value, </TableRowGroup>
});
update();
}}
/>
</TableRowGroup>
{/* Plugin List Settings */} {/* Plugin List Settings */}
<TableRowGroup title="Plugin List Settings"> <TableRowGroup title="Plugin List Settings">
<TableSwitchRow <TableSwitchRow
label="Always Send Detailed List" label="Always Send Detailed List"
subLabel="Always use detailed mode when listing plugins" subLabel="Always use detailed mode when listing plugins"
icon={getAssetIDByName("ic_message_copy")} icon={getAssetIDByName("ic_message_copy")}
value={get("listSettings.pluginListAlwaysDetailed", false)} value={storage.listSettings.pluginListAlwaysDetailed}
onValueChange={(value: boolean) => { onValueChange={(v: boolean) => {
set("listSettings", { storage.listSettings.pluginListAlwaysDetailed = v;
...get("listSettings", {}), forceRerender();
pluginListAlwaysDetailed: value, }}
}); />
update(); </TableRowGroup>
}}
/>
</TableRowGroup>
{/* Theme List Settings */} {/* Theme List Settings */}
<TableRowGroup title="Theme List Settings"> <TableRowGroup title="Theme List Settings">
<TableSwitchRow <TableSwitchRow
label="Always Send Detailed List" label="Always Send Detailed List"
subLabel="Always use detailed mode when listing themes" subLabel="Always use detailed mode when listing themes"
icon={getAssetIDByName("ic_theme")} icon={getAssetIDByName("ic_theme")}
value={get("listSettings.themeListAlwaysDetailed", false)} value={storage.listSettings.themeListAlwaysDetailed}
onValueChange={(value: boolean) => { onValueChange={(v: boolean) => {
set("listSettings", { storage.listSettings.themeListAlwaysDetailed = v;
...get("listSettings", {}), forceRerender();
themeListAlwaysDetailed: value, }}
}); />
update(); </TableRowGroup>
}}
/>
</TableRowGroup>
{/* Commands Overview */} {/* Commands Overview */}
<TableRowGroup title="Available Commands"> <TableRowGroup title="Available Commands">
<TableSwitchRow <TableSwitchRow
label="/catfact" label="/catfact"
subLabel="Get random cat facts" subLabel="Get random cat facts"
icon={getAssetIDByName("ic_info")} icon={getAssetIDByName("ic_info")}
value={true} value={true}
disabled={true} disabled={true}
/> />
<TableSwitchRow <TableSwitchRow
label="/dogfact" label="/dogfact"
subLabel="Get random dog facts" subLabel="Get random dog facts"
icon={getAssetIDByName("ic_info")} icon={getAssetIDByName("ic_info")}
value={true} value={true}
disabled={true} disabled={true}
/> />
<TableSwitchRow <TableSwitchRow
label="/useless" label="/useless"
subLabel="Get random useless facts" subLabel="Get random useless facts"
icon={getAssetIDByName("ic_info")} icon={getAssetIDByName("ic_info")}
value={true} value={true}
disabled={true} disabled={true}
/> />
<TableSwitchRow <TableSwitchRow
label="/petpet" label="/petpet"
subLabel="Create pet-pet GIF of a user" subLabel="Create pet-pet GIF of a user"
icon={getAssetIDByName("ic_image")} icon={getAssetIDByName("ic_image")}
value={true} value={true}
disabled={true} disabled={true}
/> />
<TableSwitchRow <TableSwitchRow
label="/plugin-list" label="/plugin-list"
subLabel="List all installed plugins" subLabel="List all installed plugins"
icon={getAssetIDByName("ic_plugins")} icon={getAssetIDByName("ic_plugins")}
value={true} value={true}
disabled={true} disabled={true}
/> />
<TableSwitchRow <TableSwitchRow
label="/theme-list" label="/theme-list"
subLabel="List all installed themes" subLabel="List all installed themes"
icon={getAssetIDByName("ic_theme")} icon={getAssetIDByName("ic_theme")}
value={true} value={true}
disabled={true} disabled={true}
/> />
<TableSwitchRow <TableSwitchRow
label="/konoself, /konosend" label="/konoself, /konosend"
subLabel="Get random images from KonoChan" subLabel="Get random images from KonoChan"
icon={getAssetIDByName("ic_image")} icon={getAssetIDByName("ic_image")}
value={true} value={true}
disabled={true} disabled={true}
/> />
</TableRowGroup> </TableRowGroup>
{/* About Section */} {/* About Section */}
<TableRowGroup title="About"> <TableRowGroup title="About">
<TableSwitchRow <TableSwitchRow
label="All-In-One Commands" label="All-In-One Commands"
subLabel="A collection of useful commands" subLabel="A collection of useful commands"
icon={getAssetIDByName("ic_badge_staff")} icon={getAssetIDByName("ic_badge_staff")}
value={true} value={true}
disabled={true} disabled={true}
/> />
</TableRowGroup> </TableRowGroup>
</Stack> </Stack>
</ScrollView> </ScrollView>
</View>
); );
} }