Skip to content
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

fix: Add data-bs-theme attribute for user dark/light modes #1782

Merged
merged 3 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/shared/components/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { isAuthPath, setIsoData } from "@utils/app";
import { dataBsTheme } from "@utils/browser";
import { Component, RefObject, createRef, linkEvent } from "inferno";
import { Provider } from "inferno-i18next-dess";
import { Route, Switch } from "inferno-router";
import { IsoDataOptionalSite } from "../../interfaces";
import { routes } from "../../routes";
import { FirstLoadService, I18NextService } from "../../services";
import { FirstLoadService, I18NextService, UserService } from "../../services";
import AuthGuard from "../common/auth-guard";
import ErrorGuard from "../common/error-guard";
import { ErrorPage } from "./error-page";
Expand All @@ -25,14 +26,25 @@ export class App extends Component<any, any> {
event.preventDefault();
this.mainContentRef.current?.focus();
}

user = UserService.Instance.myUserInfo;

componentDidMount() {
this.setState({ bsTheme: dataBsTheme(this.user) });
}

render() {
const siteRes = this.isoData.site_res;
const siteView = siteRes?.site_view;

return (
<>
<Provider i18next={I18NextService.i18n}>
<div id="app" className="lemmy-site">
<div
id="app"
className="lemmy-site"
data-bs-theme={this.state?.bsTheme}
>
<button
type="button"
className="btn skip-link bg-light position-absolute start-0 z-3"
Expand Down
4 changes: 4 additions & 0 deletions src/shared/utils/browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import canShare from "./can-share";
import dataBsTheme from "./data-bs-theme";
import isBrowser from "./is-browser";
import isDark from "./is-dark";
import loadCss from "./load-css";
import restoreScrollPosition from "./restore-scroll-position";
import saveScrollPosition from "./save-scroll-position";
import share from "./share";

export {
canShare,
dataBsTheme,
isBrowser,
isDark,
loadCss,
restoreScrollPosition,
saveScrollPosition,
Expand Down