|
1 | 1 | import { Link, Meta, MetaProvider, Style } from "@solidjs/meta"; |
2 | | -import { createEffect, createMemo, JSXElement } from "solid-js"; |
| 2 | +import { createEffect, createMemo, JSXElement, Show } from "solid-js"; |
3 | 3 |
|
4 | 4 | import { themes } from "../../constants/themes"; |
5 | 5 | import { createDebouncedEffectOn } from "../../hooks/effects"; |
@@ -52,27 +52,39 @@ export function Theme(): JSXElement { |
52 | 52 | }`); |
53 | 53 | }); |
54 | 54 |
|
| 55 | + const isThemeWithCss = () => { |
| 56 | + const name = getThemeName(); |
| 57 | + return name !== "custom" && (themes[name]?.hasCss ?? false); |
| 58 | + }; |
| 59 | + |
55 | 60 | createEffect(() => { |
56 | 61 | const name = getThemeName(); |
57 | | - const hasCss = name !== "custom" && (themes[name].hasCss ?? false); |
| 62 | + const hasCss = isThemeWithCss(); |
| 63 | + |
58 | 64 | console.debug( |
59 | 65 | `Theme component ${hasCss ? "loading style" : "removing style"} for theme ${name}`, |
60 | 66 | ); |
61 | | - if (hasCss) showLoaderBar(); |
| 67 | + if (hasCss) { |
| 68 | + showLoaderBar(); |
| 69 | + } else { |
| 70 | + hideLoaderBar(); |
| 71 | + } |
62 | 72 | linkEl()?.setAttribute("href", hasCss ? `/themes/${name}.css` : ""); |
63 | 73 | }); |
64 | 74 |
|
65 | 75 | return ( |
66 | 76 | <MetaProvider> |
67 | 77 | <Style id="theme" ref={styleRef} /> |
68 | | - <Link |
69 | | - ref={linkRef} |
70 | | - rel="stylesheet" |
71 | | - id="currentTheme" |
72 | | - data-name={getTheme().name} |
73 | | - onError={onError} |
74 | | - onLoad={onLoad} |
75 | | - /> |
| 78 | + <Show when={isThemeWithCss()}> |
| 79 | + <Link |
| 80 | + ref={linkRef} |
| 81 | + rel="stylesheet" |
| 82 | + id="currentTheme" |
| 83 | + data-name={getTheme().name} |
| 84 | + onError={onError} |
| 85 | + onLoad={onLoad} |
| 86 | + /> |
| 87 | + </Show> |
76 | 88 | <Meta id="metaThemeColor" name="theme-color" content={getTheme().bg} /> |
77 | 89 | <FavIcon theme={getTheme()} /> |
78 | 90 | </MetaProvider> |
|
0 commit comments