angular-challenges icon indicating copy to clipboard operation
angular-challenges copied to clipboard

giscus dark mode

Open tomalaforge opened this issue 2 years ago • 7 comments

I'm starting a new issue, this will be easier to follow.

From @jdegand I think the dark mode problems may stem from the binding of the theme. See this giscus issue. On my computer the comment section is still white on the dark mode as well. You are binding in the comment section.astro file with data-theme="preferred_color_scheme". I noticed inspecting source code both light and dark in some classes.

Giscus doesn't really seem to support / advertise Angular support (Giscus component has no version for Angular) and I think the binding issue is probably why.

It is just a minor issue.

Originally posted by @jdegand in https://github.com/tomalaforge/angular-challenges/issues/377#issuecomment-1835200992

tomalaforge avatar Dec 01 '23 08:12 tomalaforge

export class L extends HTMLElement {
    #e = "starlight-theme";
    constructor() {
        super(), this.#n(this.#o());
        const e = this.querySelector("select");
        e && e.addEventListener("change", n => {
            n.currentTarget instanceof HTMLSelectElement && this.#n(this.#t(n.currentTarget.value))
        })
    }
    #t(e) {
        return e === "auto" || e === "dark" || e === "light" ? e : "auto"
    }
    #s() {
        return matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark"
    }
    #n(e) {
        StarlightThemeProvider.updatePickers(e), document.documentElement.dataset.theme = e === "auto" ? this.#s() : e, this.#r(e)
    }
    #r(e) {
        typeof localStorage < "u" && (e === "light" || e === "dark" ? localStorage.setItem(this.#e, e) : localStorage.removeItem(this.#e))
    }
    #o() {
        const e = typeof localStorage < "u" && localStorage.getItem(this.#e);
        return this.#t(e)
    }
}

I used the web components extension and this nested ternary is used for the select.

document.documentElement.dataset.theme = e === "auto" ? this.#s() : e, this.#r(e)

Does this look right to you?

jdegand avatar Dec 02 '23 04:12 jdegand

I've never used web component, but if it does the job, it's right for me.

tomalaforge avatar Dec 06 '23 17:12 tomalaforge

I'm thinking now that there maybe a conditional logic error. The issue mentioned attribute binding but the error still occurs when both attributes are correct.

This issue is worth looking at as well.

jdegand avatar Dec 06 '23 18:12 jdegand

yes indeed, the change is not done automatically. I need to look at it more closely when I have more time. Or if you want to do it, don't hesitate 😅

tomalaforge avatar Dec 07 '23 09:12 tomalaforge

This issue is stale because it has been open for 20 days with no activity.

github-actions[bot] avatar Dec 28 '23 02:12 github-actions[bot]

Giscus has a bug and is down for next few days.

jdegand avatar Dec 31 '23 23:12 jdegand

This issue is stale because it has been open for 20 days with no activity.

github-actions[bot] avatar Jan 22 '24 02:01 github-actions[bot]