diff --git a/src/client/index.tsx b/src/client/index.tsx index 36059f97..2bdd948f 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -2,7 +2,7 @@ import { initializeSite, setupDateFns } from "@utils/app"; import { hydrate } from "inferno-hydrate"; import { Router } from "inferno-router"; import { App } from "../shared/components/app/app"; -import { HistoryService } from "../shared/services"; +import { HistoryService, UserService } from "../shared/services"; import "bootstrap/js/dist/collapse"; import "bootstrap/js/dist/dropdown"; @@ -14,7 +14,7 @@ async function startClient() { const wrapper = ( - + ); diff --git a/src/server/handlers/catch-all-handler.tsx b/src/server/handlers/catch-all-handler.tsx index 6b214944..4b011045 100644 --- a/src/server/handlers/catch-all-handler.tsx +++ b/src/server/handlers/catch-all-handler.tsx @@ -114,7 +114,7 @@ export default async (req: Request, res: Response) => { const wrapper = ( - + ); diff --git a/src/shared/components/app/app.tsx b/src/shared/components/app/app.tsx index 3452f962..2000bec2 100644 --- a/src/shared/components/app/app.tsx +++ b/src/shared/components/app/app.tsx @@ -3,6 +3,7 @@ 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 { MyUserInfo } from "lemmy-js-client"; import { IsoDataOptionalSite } from "../../interfaces"; import { routes } from "../../routes"; import { FirstLoadService, I18NextService, UserService } from "../../services"; @@ -14,10 +15,14 @@ import { Navbar } from "./navbar"; import "./styles.scss"; import { Theme } from "./theme"; -export class App extends Component { +interface AppProps { + user?: MyUserInfo; +} + +export class App extends Component { private isoData: IsoDataOptionalSite = setIsoData(this.context); private readonly mainContentRef: RefObject; - constructor(props: any, context: any) { + constructor(props: AppProps, context: any) { super(props, context); this.mainContentRef = createRef(); } @@ -29,10 +34,6 @@ export class App extends Component { user = UserService.Instance.myUserInfo; - componentDidMount() { - this.setState({ bsTheme: dataBsTheme(this.user) }); - } - render() { const siteRes = this.isoData.site_res; const siteView = siteRes?.site_view; @@ -43,7 +44,7 @@ export class App extends Component {
{
-
{getRss(listingType)}
+
+ {getRss( + listingType ?? + this.state.siteRes.site_view.local_site.default_post_listing_type + )} +
); } diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index ffc372b3..e2986b57 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -175,7 +175,9 @@ export class Login extends Component { } case "success": { - UserService.Instance.login(loginRes.data); + UserService.Instance.login({ + res: loginRes.data, + }); const site = await HttpService.client.getSite({ auth: myAuth(), }); diff --git a/src/shared/components/home/setup.tsx b/src/shared/components/home/setup.tsx index 943fd5f8..f4bdb555 100644 --- a/src/shared/components/home/setup.tsx +++ b/src/shared/components/home/setup.tsx @@ -206,7 +206,7 @@ export class Setup extends Component { if (i.state.registerRes.state == "success") { const data = i.state.registerRes.data; - UserService.Instance.login(data); + UserService.Instance.login({ res: data }); i.setState({ doneRegisteringUser: true }); } } diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx index 1e1f636a..bb1e1f11 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -469,7 +469,9 @@ export class Signup extends Component { // Only log them in if a jwt was set if (data.jwt) { - UserService.Instance.login(data); + UserService.Instance.login({ + res: data, + }); const site = await HttpService.client.getSite({ auth: myAuth() }); diff --git a/src/shared/components/person/password-change.tsx b/src/shared/components/person/password-change.tsx index 68a22f62..565f55e6 100644 --- a/src/shared/components/person/password-change.tsx +++ b/src/shared/components/person/password-change.tsx @@ -135,7 +135,9 @@ export class PasswordChange extends Component { if (i.state.passwordChangeRes.state === "success") { const data = i.state.passwordChangeRes.data; - UserService.Instance.login(data); + UserService.Instance.login({ + res: data, + }); const site = await HttpService.client.getSite({ auth: myAuth() }); if (site.state === "success") { diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index dfdf79c4..4caef458 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -1175,8 +1175,12 @@ export class Settings extends Component { ...i.state.saveUserSettingsForm, auth: myAuthRequired(), }); + if (saveRes.state === "success") { - UserService.Instance.login(saveRes.data); + UserService.Instance.login({ + res: saveRes.data, + showToast: false, + }); toast(I18NextService.i18n.t("saved")); window.scrollTo(0, 0); } @@ -1198,7 +1202,10 @@ export class Settings extends Component { auth: myAuthRequired(), }); if (changePasswordRes.state === "success") { - UserService.Instance.login(changePasswordRes.data); + UserService.Instance.login({ + res: changePasswordRes.data, + showToast: false, + }); window.scrollTo(0, 0); toast(I18NextService.i18n.t("password_changed")); } diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index 0724f400..70e8e9ca 100644 --- a/src/shared/services/UserService.ts +++ b/src/shared/services/UserService.ts @@ -26,12 +26,18 @@ export class UserService { this.#setJwtInfo(); } - public login(res: LoginResponse) { + public login({ + res, + showToast = true, + }: { + res: LoginResponse; + showToast?: boolean; + }) { const expires = new Date(); expires.setDate(expires.getDate() + 365); if (isBrowser() && res.jwt) { - toast(I18NextService.i18n.t("logged_in")); + showToast && toast(I18NextService.i18n.t("logged_in")); setAuthCookie(res.jwt); this.#setJwtInfo(); } diff --git a/src/shared/utils/browser/data-bs-theme.ts b/src/shared/utils/browser/data-bs-theme.ts index 8d73f315..97433366 100644 --- a/src/shared/utils/browser/data-bs-theme.ts +++ b/src/shared/utils/browser/data-bs-theme.ts @@ -1,11 +1,17 @@ +import { MyUserInfo } from "lemmy-js-client"; import isDark from "./is-dark"; -export default function dataBsTheme(user) { +export default function dataBsTheme(user?: MyUserInfo) { return (isDark() && user?.local_user_view.local_user.theme === "browser") || (user && - ["darkly", "darkly-red", "darkly-pureblack"].includes( - user.local_user_view.local_user.theme - )) + [ + "darkly", + "darkly-red", + "darkly-pureblack", + "darkly-compact", + "i386", + "vaporwave-dark", + ].includes(user.local_user_view.local_user.theme)) ? "dark" : "light"; }