Skip to content

Commit

Permalink
fix: remove themePlaceholder
Browse files Browse the repository at this point in the history
  • Loading branch information
asabotovich committed Feb 12, 2024
1 parent 41cc75c commit 402948d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
14 changes: 4 additions & 10 deletions src/components/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TextStyle, nullable } from '@taskany/bricks';
import { pageContext, PageContext } from '../../utils/pageContext';
import { useHotkeys } from '../../hooks/useHotkeys';
import { ModalEvent } from '../../utils/dispatchModal';
import { trpc } from '../../utils/trpcClient';
import { createProjectKeys, inviteUserKeys, createGoalKeys } from '../../utils/hotkeys';
import { Theme } from '../Theme';
import { PageHeader } from '../PageHeader/PageHeader';
Expand Down Expand Up @@ -42,12 +43,13 @@ const mapThemeOnId = { light: 0, dark: 1 } as const;

export const Page: React.FC<PageProps> = ({ user, ssrTime, title = 'Untitled', children, ...attrs }) => {
const { setPreview } = useGoalPreview();
const { data: userSettings } = trpc.user.settings.useQuery();

useHotkeys();

const { resolvedTheme } = useTheme();
const theme = (
user?.settings?.theme === 'system' ? resolvedTheme || 'dark' : user?.settings?.theme || 'light'
userSettings?.theme === 'system' ? resolvedTheme || 'dark' : userSettings?.theme || 'light'
) as PageContext['theme'];

const router = useRouter();
Expand All @@ -56,19 +58,11 @@ export const Page: React.FC<PageProps> = ({ user, ssrTime, title = 'Untitled', c
setPreview(null);
}, [router.asPath, setPreview]);

useEffect(() => {
const currentHref = document?.getElementById('themeVariables')?.getAttribute('href') || '';
const newHref = currentHref?.replace(/(.*)\/[^/]+$/, `$1/${theme}.css`);

if (newHref) {
document?.getElementById('themeVariables')?.setAttribute('href', newHref);
}
}, [theme]);

return (
<pageContext.Provider value={{ user, theme, themeId: mapThemeOnId[theme], ssrTime }}>
<Head>
<title>{title}</title>
<link rel="stylesheet" id="themeVariables" href={`/theme/${theme}.css`} />
</Head>

<TextStyle />
Expand Down
2 changes: 0 additions & 2 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export default class MyDocument extends Document {
<Html>
<Head>
<ExternalScripts />
{/* eslint-disable-next-line @next/next/no-css-tags */}
<link rel="stylesheet" id="themeVariables" href="/theme/themePlaceholder.css" />
</Head>
<body>
<Main />
Expand Down

0 comments on commit 402948d

Please sign in to comment.