[UI > (Plugin/Theme)Card] Action sheet upgrades
This commit is contained in:
parent
cfdee54d8e
commit
a6cb2d0be3
2 changed files with 56 additions and 14 deletions
|
@ -1,9 +1,10 @@
|
||||||
import { ButtonColors, Plugin } from "@types";
|
import { ButtonColors, Plugin } from "@types";
|
||||||
import { NavigationNative, clipboard } from "@metro/common";
|
import { NavigationNative, clipboard } from "@metro/common";
|
||||||
|
import { MMKVManager } from "@lib/native";
|
||||||
import { getAssetIDByName } from "@ui/assets";
|
import { getAssetIDByName } from "@ui/assets";
|
||||||
import { showToast } from "@ui/toasts";
|
import { showToast } from "@ui/toasts";
|
||||||
import { showConfirmationAlert } from "@ui/alerts";
|
import { showConfirmationAlert } from "@ui/alerts";
|
||||||
import { removePlugin, startPlugin, stopPlugin, getSettings } from "@lib/plugins";
|
import { removePlugin, startPlugin, stopPlugin, getSettings, fetchPlugin } from "@lib/plugins";
|
||||||
import Card from "@ui/settings/components/Card";
|
import Card from "@ui/settings/components/Card";
|
||||||
|
|
||||||
interface PluginCardProps {
|
interface PluginCardProps {
|
||||||
|
@ -11,6 +12,12 @@ interface PluginCardProps {
|
||||||
index: number;
|
index: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function stopThenStart(plugin: Plugin, func: Function) {
|
||||||
|
if (plugin.enabled) stopPlugin(plugin.id, false);
|
||||||
|
func();
|
||||||
|
if (plugin.enabled) await startPlugin(plugin.id);
|
||||||
|
}
|
||||||
|
|
||||||
export default function PluginCard({ plugin, index }: PluginCardProps) {
|
export default function PluginCard({ plugin, index }: PluginCardProps) {
|
||||||
const settings = getSettings(plugin.id);
|
const settings = getSettings(plugin.id);
|
||||||
const navigation = NavigationNative.useNavigation();
|
const navigation = NavigationNative.useNavigation();
|
||||||
|
@ -37,6 +44,27 @@ export default function PluginCard({ plugin, index }: PluginCardProps) {
|
||||||
descriptionLabel={plugin.manifest.description}
|
descriptionLabel={plugin.manifest.description}
|
||||||
overflowTitle={plugin.manifest.name}
|
overflowTitle={plugin.manifest.name}
|
||||||
overflowActions={[
|
overflowActions={[
|
||||||
|
{
|
||||||
|
icon: "ic_sync_24px",
|
||||||
|
label: "Refetch",
|
||||||
|
onPress: async () => {
|
||||||
|
stopThenStart(plugin, () => {
|
||||||
|
fetchPlugin(plugin.id).then(async () => {
|
||||||
|
showToast("Successfully refetched plugin.", getAssetIDByName("toast_image_saved"));
|
||||||
|
}).catch(() => {
|
||||||
|
showToast("Failed to refetch plugin!", getAssetIDByName("Small"));
|
||||||
|
})
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "copy",
|
||||||
|
label: "Copy URL",
|
||||||
|
onPress: () => {
|
||||||
|
clipboard.setString(plugin.id);
|
||||||
|
showToast("Copied plugin URL to clipboard.", getAssetIDByName("toast_copy_link"));
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
icon: "ic_download_24px",
|
icon: "ic_download_24px",
|
||||||
label: plugin.update ? "Disable updates" : "Enable updates",
|
label: plugin.update ? "Disable updates" : "Enable updates",
|
||||||
|
@ -46,20 +74,34 @@ export default function PluginCard({ plugin, index }: PluginCardProps) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "copy",
|
icon: "ic_duplicate",
|
||||||
label: "Copy plugin URL",
|
label: "Clear data",
|
||||||
onPress: () => {
|
|
||||||
clipboard.setString(plugin.id);
|
|
||||||
showToast("Copied plugin URL to clipboard.", getAssetIDByName("toast_copy_link"));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: "ic_message_delete",
|
|
||||||
label: "Delete plugin",
|
|
||||||
isDestructive: true,
|
isDestructive: true,
|
||||||
onPress: () => showConfirmationAlert({
|
onPress: () => showConfirmationAlert({
|
||||||
title: "Wait!",
|
title: "Wait!",
|
||||||
content: `Are you sure you wish to delete ${plugin.manifest.name}? This will remove all of the plugin's data.`,
|
content: `Are you sure you wish to clear the data of ${plugin.manifest.name}?`,
|
||||||
|
confirmText: "Clear",
|
||||||
|
cancelText: "Cancel",
|
||||||
|
confirmColor: ButtonColors.RED,
|
||||||
|
onConfirm: () => {
|
||||||
|
stopThenStart(plugin, () => {
|
||||||
|
try {
|
||||||
|
MMKVManager.removeItem(plugin.id);
|
||||||
|
showToast(`Cleared data for ${plugin.manifest.name}.`, getAssetIDByName("trash"));
|
||||||
|
} catch {
|
||||||
|
showToast(`Failed to clear data for ${plugin.manifest.name}!`, getAssetIDByName("Small"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "ic_message_delete",
|
||||||
|
label: "Delete",
|
||||||
|
isDestructive: true,
|
||||||
|
onPress: () => showConfirmationAlert({
|
||||||
|
title: "Wait!",
|
||||||
|
content: `Are you sure you wish to delete ${plugin.manifest.name}? This will clear all of the plugin's data.`,
|
||||||
confirmText: "Delete",
|
confirmText: "Delete",
|
||||||
cancelText: "Cancel",
|
cancelText: "Cancel",
|
||||||
confirmColor: ButtonColors.RED,
|
confirmColor: ButtonColors.RED,
|
||||||
|
|
|
@ -61,7 +61,7 @@ export default function ThemeCard({ theme, index }: ThemeCardProps) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "copy",
|
icon: "copy",
|
||||||
label: "Copy theme URL",
|
label: "Copy URL",
|
||||||
onPress: () => {
|
onPress: () => {
|
||||||
clipboard.setString(theme.id);
|
clipboard.setString(theme.id);
|
||||||
showToast("Copied theme URL to clipboard.", getAssetIDByName("toast_copy_link"));
|
showToast("Copied theme URL to clipboard.", getAssetIDByName("toast_copy_link"));
|
||||||
|
@ -69,7 +69,7 @@ export default function ThemeCard({ theme, index }: ThemeCardProps) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "ic_message_delete",
|
icon: "ic_message_delete",
|
||||||
label: "Delete theme",
|
label: "Delete",
|
||||||
isDestructive: true,
|
isDestructive: true,
|
||||||
onPress: () => showConfirmationAlert({
|
onPress: () => showConfirmationAlert({
|
||||||
title: "Wait!",
|
title: "Wait!",
|
||||||
|
|
Loading…
Reference in a new issue