diff options
author | Justice Almanzar <superdash993@gmail.com> | 2023-01-13 17:15:45 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 23:15:45 +0100 |
commit | ea748dfb605386b80a4919183ad6fa9249a82e21 (patch) | |
tree | 8660c5d192ac553e7574d6b510e18f99c7ac5ddd /src/plugins/shikiCodeblocks/hooks | |
parent | 6c5fcc4119d05389bbc71bd3e52090f6fd29b10c (diff) | |
download | Vencord-ea748dfb605386b80a4919183ad6fa9249a82e21.tar.gz Vencord-ea748dfb605386b80a4919183ad6fa9249a82e21.tar.bz2 Vencord-ea748dfb605386b80a4919183ad6fa9249a82e21.zip |
feat: Typesafe Settings Definitions (#403)
Co-authored-by: Ven <vendicated@riseup.net>
Diffstat (limited to 'src/plugins/shikiCodeblocks/hooks')
-rw-r--r-- | src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts | 14 |
1 files changed, 7 insertions, 7 deletions
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 <https://www.gnu.org/licenses/>. */ -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<string, any>) { - const settings = useSettings(settingKeys.map(key => `plugins.ShikiCodeblocks.${key}`)).plugins.ShikiCodeblocks as ShikiSettings; +export function useShikiSettings<F extends keyof ShikiSettings>(settingKeys: F[], overrides?: Partial<ShikiSettings>) { + const settings: Partial<ShikiSettings> = pluginSettings.use(settingKeys); const [isLoading, setLoading] = React.useState(false); - const withOverrides = { ...settings, ...overrides }; + const withOverrides = { ...settings, ...overrides } as PartialExcept<ShikiSettings, F>; 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); } |