From e1e8012e6087374dd528fdbf6eea84f25776ed70 Mon Sep 17 00:00:00 2001 From: Beef Date: Sun, 19 Mar 2023 18:52:17 +0000 Subject: [PATCH] [UI > ThemeCard] Allow manually refetching theme --- src/ui/settings/components/ThemeCard.tsx | 33 +++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/ui/settings/components/ThemeCard.tsx b/src/ui/settings/components/ThemeCard.tsx index c90c23b..827e374 100644 --- a/src/ui/settings/components/ThemeCard.tsx +++ b/src/ui/settings/components/ThemeCard.tsx @@ -1,6 +1,6 @@ import { ButtonColors, Theme } from "@types"; -import { clipboard } from "@metro/common"; -import { removeTheme, selectTheme } from "@lib/themes"; +import { ReactNative as RN, clipboard } from "@metro/common"; +import { fetchTheme, removeTheme, selectTheme } from "@lib/themes"; import { getAssetIDByName } from "@ui/assets"; import { showConfirmationAlert } from "@ui/alerts"; import { showToast } from "@ui/toasts"; @@ -13,7 +13,7 @@ interface ThemeCardProps { async function selectAndReload(value: boolean, id: string) { await selectTheme(value ? id : "default"); - window.nativeModuleProxy.BundleUpdaterManager.reload(); + RN.NativeModules.BundleUpdaterManager.reload(); } export default function ThemeCard({ theme, index }: ThemeCardProps) { @@ -47,9 +47,9 @@ export default function ThemeCard({ theme, index }: ThemeCardProps) { removeTheme(theme.id).then((wasSelected) => { setRemoved(true); if (wasSelected) selectAndReload(false, theme.id); - }).catch((e) => { - showToast((e as Error).message, getAssetIDByName("Small")); - }) + }).catch((e: Error) => { + showToast(e.message, getAssetIDByName("Small")); + }); } }), }, @@ -60,6 +60,27 @@ export default function ThemeCard({ theme, index }: ThemeCardProps) { showToast("Copied theme URL to clipboard.", getAssetIDByName("toast_copy_link")); }, }, + { + icon: "ic_sync_24px", + onPress: () => { + fetchTheme(theme.id).then(() => { + if (theme.selected) { + showConfirmationAlert({ + title: "Theme refetched", + content: "A reload is required to see the changes. Do you want to reload now?", + confirmText: "Reload", + cancelText: "Cancel", + confirmColor: ButtonColors.RED, + onConfirm: () => RN.NativeModules.BundleUpdaterManager.reload(), + }) + } else { + showToast("Successfully refetched theme.", getAssetIDByName("toast_image_saved")); + } + }).catch(() => { + showToast("Failed to refetch theme!", getAssetIDByName("Small")); + }); + }, + }, ]} /> )