Skip to content

Commit

Permalink
fix links page theme with trigger change theme event
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanjam committed Aug 22, 2024
1 parent a38858f commit ab130bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/components/ThemeScript.astro
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ const defaultThemes = getDefaultThemes();
darkModePreference.addEventListener('change', (event) => {
const newMode = event.matches ? MODES.dark : MODES.light;
const newTheme = getThemeFromMode(newMode);
setTheme(newTheme);

// trigger event instead of setTheme(newTheme), for Links page
const payload = { detail: { theme: newTheme } };
const themeChangeEvent = new CustomEvent(CHANGE_EVENT, payload);

document.dispatchEvent(themeChangeEvent);
});
</script>
3 changes: 1 addition & 2 deletions src/pages/links.astro
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ const { GITHUB_MARKDOWN_BODY_ID } = SELECTORS;
const { CHANGE_EVENT } = THEME_CONFIG;
const { GITHUB_MARKDOWN_BODY_SELECTOR } = SELECTORS;

const markdownBodyElement = document.querySelector(GITHUB_MARKDOWN_BODY_SELECTOR);

const loadGithubTheme = (mode: Mode) => {
const markdownBodyElement = document.querySelector(GITHUB_MARKDOWN_BODY_SELECTOR);
if (!markdownBodyElement) return;

if (markdownBodyElement && mode === MODES.dark)
Expand Down

0 comments on commit ab130bf

Please sign in to comment.