From ea748dfb605386b80a4919183ad6fa9249a82e21 Mon Sep 17 00:00:00 2001 From: Justice Almanzar Date: Fri, 13 Jan 2023 17:15:45 -0500 Subject: feat: Typesafe Settings Definitions (#403) Co-authored-by: Ven --- src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts') diff --git a/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts b/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts index 50b0fc9..22954ce 100644 --- a/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts +++ b/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts @@ -16,25 +16,25 @@ * along with this program. If not, see . */ -import { useSettings } from "@api/settings"; +import { PartialExcept } from "@utils/types"; import { React } from "@webpack/common"; import { shiki } from "../api/shiki"; -import { ShikiSettings } from "../types"; +import { settings as pluginSettings, ShikiSettings } from "../settings"; -export function useShikiSettings(settingKeys: (keyof ShikiSettings)[], overrides?: Record) { - const settings = useSettings(settingKeys.map(key => `plugins.ShikiCodeblocks.${key}`)).plugins.ShikiCodeblocks as ShikiSettings; +export function useShikiSettings(settingKeys: F[], overrides?: Partial) { + const settings: Partial = pluginSettings.use(settingKeys); const [isLoading, setLoading] = React.useState(false); - const withOverrides = { ...settings, ...overrides }; + const withOverrides = { ...settings, ...overrides } as PartialExcept; const themeUrl = withOverrides.customTheme || withOverrides.theme; if (overrides) { - const willChangeTheme = shiki.currentThemeUrl && themeUrl !== shiki.currentThemeUrl; + const willChangeTheme = shiki.currentThemeUrl && themeUrl && themeUrl !== shiki.currentThemeUrl; const noOverrides = Object.keys(overrides).length === 0; if (isLoading && (!willChangeTheme || noOverrides)) setLoading(false); - if ((!isLoading && willChangeTheme)) { + if (!isLoading && willChangeTheme) { setLoading(true); shiki.setTheme(themeUrl); } -- cgit