aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/shikiCodeblocks/hooks
diff options
context:
space:
mode:
authorJustice Almanzar <superdash993@gmail.com>2022-12-08 09:54:19 -0500
committerGitHub <noreply@github.com>2022-12-08 15:54:19 +0100
commit2de461985dadadbaae1b2b0a83cf291dd8d3a972 (patch)
tree349f7b635cf6e0ce93da2789509e510a163b2c7f /src/plugins/shikiCodeblocks/hooks
parent2d08dd8a9c289bcdb6395e8bdf28b6b729946ab1 (diff)
downloadVencord-2de461985dadadbaae1b2b0a83cf291dd8d3a972.tar.gz
Vencord-2de461985dadadbaae1b2b0a83cf291dd8d3a972.tar.bz2
Vencord-2de461985dadadbaae1b2b0a83cf291dd8d3a972.zip
fix(ShikiCodeblocks): spoilers (#298)
* fix(ShikiCodeblocks): spoilers * fix a settings bug i thikn
Diffstat (limited to 'src/plugins/shikiCodeblocks/hooks')
-rw-r--r--src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts b/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts
index 0d92f80..50b0fc9 100644
--- a/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts
+++ b/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts
@@ -17,17 +17,28 @@
*/
import { useSettings } from "@api/settings";
+import { React } from "@webpack/common";
import { shiki } from "../api/shiki";
import { ShikiSettings } from "../types";
export function useShikiSettings(settingKeys: (keyof ShikiSettings)[], overrides?: Record<string, any>) {
const settings = useSettings(settingKeys.map(key => `plugins.ShikiCodeblocks.${key}`)).plugins.ShikiCodeblocks as ShikiSettings;
+ const [isLoading, setLoading] = React.useState(false);
const withOverrides = { ...settings, ...overrides };
-
const themeUrl = withOverrides.customTheme || withOverrides.theme;
- if (themeUrl !== shiki.currentThemeUrl) shiki.setTheme(themeUrl);
+
+ if (overrides) {
+ const willChangeTheme = shiki.currentThemeUrl && themeUrl !== shiki.currentThemeUrl;
+ const noOverrides = Object.keys(overrides).length === 0;
+
+ if (isLoading && (!willChangeTheme || noOverrides)) setLoading(false);
+ if ((!isLoading && willChangeTheme)) {
+ setLoading(true);
+ shiki.setTheme(themeUrl);
+ }
+ }
return {
...withOverrides,