-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove react hook and use javascript to detect theme state #15
base: master
Are you sure you want to change the base?
Changes from all commits
5470057
494753a
5034968
b3ae997
7c401e7
1c34de9
7bd1de7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @license | ||
* Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
|
||
import { isBrowser } from "./utils"; | ||
import { colorSchemeMedia } from "./utils"; | ||
|
||
const configureDarkMode = () => { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra space. |
||
if (isBrowser()) { | ||
if (window.matchMedia(colorSchemeMedia).matches) { | ||
document.documentElement.classList.add('dark') | ||
} else { | ||
document.documentElement.classList.add('light') | ||
} | ||
} | ||
|
||
}; | ||
|
||
export default configureDarkMode; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @license | ||
* Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
export const colorSchemeMedia = "(prefers-color-scheme: dark)"; | ||
export const isBrowser = () => typeof window !== "undefined" | ||
export const getPathName = () => { | ||
|
||
if (isBrowser()) { | ||
return window.location.pathname; | ||
} else { | ||
return ""; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,12 @@ import Landing from "../sections/Landing"; | |
import About from "../sections/About"; | ||
import Team from "../sections/Team"; | ||
import Layout from "../components/Layout"; | ||
import configureDarkMode from "../libs/configureDarkMode"; | ||
|
||
const IndexPage = () => { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra space. |
||
configureDarkMode(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just thinking not tried but is it working when we go to another page? It looks like it is working on index page but what happens if we go to download page? Is it still works because it looks like you are just adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I didn't even think about that. It seems to maintain state when navigating to the download page, which makes sense, but then upon reload defaults to light. I added the method to all pages and now it works fine, no flash and respects system theme, for all of them (even upon changing in system settings and navigating to the page.) |
||
|
||
return ( | ||
<Layout title="Skyline - Nintendo Switch Emulator"> | ||
<Landing /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space.