Skip to content

Commit

Permalink
fix: 🐛 force dark mode on marketing pages
Browse files Browse the repository at this point in the history
  • Loading branch information
bbuilds committed Apr 30, 2024
1 parent 4c279c3 commit 5ccbcfb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/components/HomepageHero/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,10 @@ import HeroDesktopBg from "@site/static/img/hero-desktop.svg";
import HeroMobileBg from "@site/static/img/hero-mobile.svg";
import styles from "./styles.module.scss";
import { useIsJapanese } from "@site/src/utils/isJapanese";
import { useColorMode } from "@docusaurus/theme-common";
import { useForcedDarkTheme } from "@site/src/utils/useForcedDarkTheme";
export default function HomepageHero(): JSX.Element {
const isJapanese = useIsJapanese();
const { setColorMode, colorMode } = useColorMode();

//quick fix for updating color mode on page load breaking after theme upgrade
React.useEffect(() => {
const originalTheme = colorMode;

// The second parameter exists, it's just not on the type :(
setColorMode("dark", { persist: false });

return () => {
setColorMode(originalTheme);
};
}, []);
useForcedDarkTheme();

return (
<header className={clsx("bg-11-o-clock text-white", styles.homepageHero)}>
Expand Down
3 changes: 3 additions & 0 deletions src/components/PageHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from "react";
import clsx from "clsx";
import styles from "./styles.module.scss";
import { useForcedDarkTheme } from "@site/src/utils/useForcedDarkTheme";

type PageHeaderProps = {
heading: string;
Expand All @@ -12,6 +13,8 @@ export default function PageHeader({
heading,
subheading,
}: PageHeaderProps): JSX.Element {
useForcedDarkTheme();

return (
<header className={clsx("bg-11-o-clock text-white", styles.pageHeader)}>
<div className="container">
Expand Down
17 changes: 17 additions & 0 deletions src/utils/useForcedDarkTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from "react";
import { useColorMode } from "@docusaurus/theme-common";

export function useForcedDarkTheme() {
const { setColorMode, colorMode } = useColorMode();
//quick fix for updating color mode on page load breaking after theme upgrade
React.useEffect(() => {
const originalTheme = colorMode;

// The second parameter exists, it's just not on the type :(
setColorMode("dark", { persist: false });

return () => {
setColorMode(originalTheme);
};
}, []);
}

0 comments on commit 5ccbcfb

Please sign in to comment.