Skip to content

Commit

Permalink
Add copy code block for rule
Browse files Browse the repository at this point in the history
  • Loading branch information
FieryFlames committed Feb 5, 2023
1 parent f0ad3f2 commit 402cbe3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/ui/pages/EditRule.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { clipboard as Clipboard } from "@vendetta/metro/common";
import { storage } from "@vendetta/plugin";
import { useProxy } from "@vendetta/storage";
import { getAssetIDByName } from "@vendetta/ui/assets";
import { Forms, General } from "@vendetta/ui/components";
import { showToast } from "@vendetta/ui/toasts";
import { Rule } from "../../def";

// Components
const { ScrollView } = General;
const { FormSection, FormInput, FormDivider, FormSwitchRow } = Forms;
const { FormSection, FormInput, FormDivider, FormSwitchRow, FormRow } = Forms;

const MessageCopy = getAssetIDByName("ic_message_copy");

export default function EditRule({ ruleIndex }) {
let rule = storage.rules[ruleIndex] as Rule;
useProxy(storage);

const copyCodeBlockCallback = () => {
const ruleJson = JSON.stringify(rule, null, 4);
const ruleCodeBlock = `\`\`\`json\n${ruleJson}\n\`\`\``;
Clipboard.setString(ruleCodeBlock);
showToast(`Copied ${rule.name} to Clipboard`, MessageCopy);
};

return (
<ScrollView>
<FormSection>
Expand Down Expand Up @@ -53,6 +65,9 @@ export default function EditRule({ ruleIndex }) {
onValueChange={(v: boolean) => rule.regex = v}
/>
</FormSection>
<FormSection>
<FormRow label="Copy code block to Clipboard" onPress={copyCodeBlockCallback} />
</FormSection>
</ScrollView>
);
};

0 comments on commit 402cbe3

Please sign in to comment.