Update settings.tsx
This commit is contained in:
parent
7c3a5bf31c
commit
276d526d8c
1 changed files with 136 additions and 131 deletions
|
|
@ -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 (
|
||||
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ padding: 10 }}>
|
||||
<Stack spacing={8}>
|
||||
{/* Facts Commands Settings */}
|
||||
<TableRowGroup title="Facts Settings">
|
||||
<TableSwitchRow
|
||||
label="Send as Reply"
|
||||
subLabel="Send facts as a reply to the command message"
|
||||
icon={getAssetIDByName("ic_reply_24px")}
|
||||
value={get("factSettings.sendAsReply", true)}
|
||||
onValueChange={(value: boolean) => {
|
||||
set("factSettings", {
|
||||
...get("factSettings", {}),
|
||||
sendAsReply: value,
|
||||
});
|
||||
update();
|
||||
}}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="Include Source Citation"
|
||||
subLabel="Include the source of facts when available"
|
||||
icon={getAssetIDByName("ic_info")}
|
||||
value={get("factSettings.includeCitation", false)}
|
||||
onValueChange={(value: boolean) => {
|
||||
set("factSettings", {
|
||||
...get("factSettings", {}),
|
||||
includeCitation: value,
|
||||
});
|
||||
update();
|
||||
}}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
<View style={{ flex: 1 }}>
|
||||
<ScrollView style={{ flex: 1 }}>
|
||||
<Stack spacing={8}>
|
||||
{/* Facts Commands Settings */}
|
||||
<TableRowGroup title="Facts Settings">
|
||||
<TableSwitchRow
|
||||
label="Send as Reply"
|
||||
subLabel="Send facts as a reply to the command message"
|
||||
icon={getAssetIDByName("ic_reply_24px")}
|
||||
value={storage.factSettings.sendAsReply}
|
||||
onValueChange={(v: boolean) => {
|
||||
storage.factSettings.sendAsReply = v;
|
||||
forceRerender();
|
||||
}}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="Include Source Citation"
|
||||
subLabel="Include the source of facts when available"
|
||||
icon={getAssetIDByName("ic_info")}
|
||||
value={storage.factSettings.includeCitation}
|
||||
onValueChange={(v: boolean) => {
|
||||
storage.factSettings.includeCitation = v;
|
||||
forceRerender();
|
||||
}}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
|
||||
{/* Plugin List Settings */}
|
||||
<TableRowGroup title="Plugin List Settings">
|
||||
<TableSwitchRow
|
||||
label="Always Send Detailed List"
|
||||
subLabel="Always use detailed mode when listing plugins"
|
||||
icon={getAssetIDByName("ic_message_copy")}
|
||||
value={get("listSettings.pluginListAlwaysDetailed", false)}
|
||||
onValueChange={(value: boolean) => {
|
||||
set("listSettings", {
|
||||
...get("listSettings", {}),
|
||||
pluginListAlwaysDetailed: value,
|
||||
});
|
||||
update();
|
||||
}}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
{/* Plugin List Settings */}
|
||||
<TableRowGroup title="Plugin List Settings">
|
||||
<TableSwitchRow
|
||||
label="Always Send Detailed List"
|
||||
subLabel="Always use detailed mode when listing plugins"
|
||||
icon={getAssetIDByName("ic_message_copy")}
|
||||
value={storage.listSettings.pluginListAlwaysDetailed}
|
||||
onValueChange={(v: boolean) => {
|
||||
storage.listSettings.pluginListAlwaysDetailed = v;
|
||||
forceRerender();
|
||||
}}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
|
||||
{/* Theme List Settings */}
|
||||
<TableRowGroup title="Theme List Settings">
|
||||
<TableSwitchRow
|
||||
label="Always Send Detailed List"
|
||||
subLabel="Always use detailed mode when listing themes"
|
||||
icon={getAssetIDByName("ic_theme")}
|
||||
value={get("listSettings.themeListAlwaysDetailed", false)}
|
||||
onValueChange={(value: boolean) => {
|
||||
set("listSettings", {
|
||||
...get("listSettings", {}),
|
||||
themeListAlwaysDetailed: value,
|
||||
});
|
||||
update();
|
||||
}}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
{/* Theme List Settings */}
|
||||
<TableRowGroup title="Theme List Settings">
|
||||
<TableSwitchRow
|
||||
label="Always Send Detailed List"
|
||||
subLabel="Always use detailed mode when listing themes"
|
||||
icon={getAssetIDByName("ic_theme")}
|
||||
value={storage.listSettings.themeListAlwaysDetailed}
|
||||
onValueChange={(v: boolean) => {
|
||||
storage.listSettings.themeListAlwaysDetailed = v;
|
||||
forceRerender();
|
||||
}}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
|
||||
{/* Commands Overview */}
|
||||
<TableRowGroup title="Available Commands">
|
||||
<TableSwitchRow
|
||||
label="/catfact"
|
||||
subLabel="Get random cat facts"
|
||||
icon={getAssetIDByName("ic_info")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/dogfact"
|
||||
subLabel="Get random dog facts"
|
||||
icon={getAssetIDByName("ic_info")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/useless"
|
||||
subLabel="Get random useless facts"
|
||||
icon={getAssetIDByName("ic_info")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/petpet"
|
||||
subLabel="Create pet-pet GIF of a user"
|
||||
icon={getAssetIDByName("ic_image")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/plugin-list"
|
||||
subLabel="List all installed plugins"
|
||||
icon={getAssetIDByName("ic_plugins")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/theme-list"
|
||||
subLabel="List all installed themes"
|
||||
icon={getAssetIDByName("ic_theme")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/konoself, /konosend"
|
||||
subLabel="Get random images from KonoChan"
|
||||
icon={getAssetIDByName("ic_image")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
{/* Commands Overview */}
|
||||
<TableRowGroup title="Available Commands">
|
||||
<TableSwitchRow
|
||||
label="/catfact"
|
||||
subLabel="Get random cat facts"
|
||||
icon={getAssetIDByName("ic_info")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/dogfact"
|
||||
subLabel="Get random dog facts"
|
||||
icon={getAssetIDByName("ic_info")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/useless"
|
||||
subLabel="Get random useless facts"
|
||||
icon={getAssetIDByName("ic_info")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/petpet"
|
||||
subLabel="Create pet-pet GIF of a user"
|
||||
icon={getAssetIDByName("ic_image")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/plugin-list"
|
||||
subLabel="List all installed plugins"
|
||||
icon={getAssetIDByName("ic_plugins")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/theme-list"
|
||||
subLabel="List all installed themes"
|
||||
icon={getAssetIDByName("ic_theme")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/konoself, /konosend"
|
||||
subLabel="Get random images from KonoChan"
|
||||
icon={getAssetIDByName("ic_image")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
|
||||
{/* About Section */}
|
||||
<TableRowGroup title="About">
|
||||
<TableSwitchRow
|
||||
label="All-In-One Commands"
|
||||
subLabel="A collection of useful commands"
|
||||
icon={getAssetIDByName("ic_badge_staff")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
</Stack>
|
||||
</ScrollView>
|
||||
{/* About Section */}
|
||||
<TableRowGroup title="About">
|
||||
<TableSwitchRow
|
||||
label="All-In-One Commands"
|
||||
subLabel="A collection of useful commands"
|
||||
icon={getAssetIDByName("ic_badge_staff")}
|
||||
value={true}
|
||||
disabled={true}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
</Stack>
|
||||
</ScrollView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue