diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 15d0140d..ad578d0e 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -121,13 +121,10 @@ function getDataTypeFromQuery(type?: string): DataType { } function getListingTypeFromQuery(type?: string): ListingType { - console.log(`Listing type: ${type}`); const myListingType = UserService.Instance.myUserInfo?.local_user_view?.local_user ?.default_listing_type; - console.log(`my listing type: ${myListingType}`); - return (type ? (type as ListingType) : myListingType) ?? "Local"; } diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index aa3b1a5c..87ef234e 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -3,7 +3,7 @@ import { GetSiteResponse, LoginResponse } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { UserService } from "../../services"; import { HttpService, RequestState } from "../../services/HttpService"; -import { isBrowser, setIsoData, toast, validEmail } from "../../utils"; +import { isBrowser, myAuth, setIsoData, toast, validEmail } from "../../utils"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; @@ -178,8 +178,16 @@ export class Login extends Component { case "success": { UserService.Instance.login(loginRes.data); - i.props.history.push("/"); - location.reload(); + const site = await HttpService.client.getSite({ + auth: myAuth(), + }); + + if (site.state === "success") { + UserService.Instance.myUserInfo = site.data.my_user; + } + + i.props.history.replace("/"); + break; } } diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx index 93f95b30..3efeac62 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -16,6 +16,7 @@ import { isBrowser, joinLemmyUrl, mdToHtml, + myAuth, setIsoData, toast, validEmail, @@ -471,8 +472,14 @@ export class Signup extends Component { // Only log them in if a jwt was set if (data.jwt) { UserService.Instance.login(data); - i.props.history.push("/communities"); - location.reload(); + + const site = await HttpService.client.getSite({ auth: myAuth() }); + + if (site.state === "success") { + UserService.Instance.myUserInfo = site.data.my_user; + } + + i.props.history.replace("/communities"); } else { if (data.verify_email_sent) { toast(i18n.t("verify_email_sent")); diff --git a/src/shared/components/person/password-change.tsx b/src/shared/components/person/password-change.tsx index cee45ad0..9f5bf927 100644 --- a/src/shared/components/person/password-change.tsx +++ b/src/shared/components/person/password-change.tsx @@ -3,7 +3,7 @@ import { GetSiteResponse, LoginResponse } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { HttpService, UserService } from "../../services"; import { RequestState } from "../../services/HttpService"; -import { capitalizeFirstLetter, setIsoData } from "../../utils"; +import { capitalizeFirstLetter, myAuth, setIsoData } from "../../utils"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; @@ -131,11 +131,16 @@ export class PasswordChange extends Component { }), }); - if (i.state.passwordChangeRes.state == "success") { + if (i.state.passwordChangeRes.state === "success") { const data = i.state.passwordChangeRes.data; UserService.Instance.login(data); - this.props.history.push("/"); - location.reload(); + + const site = await HttpService.client.getSite({ auth: myAuth() }); + if (site.state === "success") { + UserService.Instance.myUserInfo = site.data.my_user; + } + + this.props.history.replace("/"); } } } diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 14e4b1ca..c5e8cad3 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -273,16 +273,10 @@ export class Post extends Component { document.addEventListener("scroll", this.commentScrollDebounced); } - componentDidUpdate(_lastProps: any) { + async componentDidUpdate(_lastProps: any) { // Necessary if you are on a post and you click another post (same route) if (_lastProps.location.pathname !== _lastProps.history.location.pathname) { - // TODO Couldnt get a refresh working. This does for now. - location.reload(); - - // const currentId = this.props.match.params.id; - // WebSocketService.Instance.getPost(currentId); - // this.context.refresh(); - // this.context.router.history.push(_lastProps.location.pathname); + await this.fetchPost(); } } diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index 1437441f..57c8aecf 100644 --- a/src/shared/services/UserService.ts +++ b/src/shared/services/UserService.ts @@ -18,12 +18,12 @@ interface JwtInfo { } export class UserService { - private static _instance: UserService; + static #instance: UserService; public myUserInfo?: MyUserInfo; public jwtInfo?: JwtInfo; private constructor() { - this.setJwtInfo(); + this.#setJwtInfo(); } public login(res: LoginResponse) { @@ -32,7 +32,7 @@ export class UserService { if (res.jwt) { toast(i18n.t("logged_in")); IsomorphicCookie.save("jwt", res.jwt, { expires, secure: isHttps() }); - this.setJwtInfo(); + this.#setJwtInfo(); } } @@ -63,7 +63,7 @@ export class UserService { } } - private setJwtInfo() { + #setJwtInfo() { const jwt: string | undefined = IsomorphicCookie.load("jwt"); if (jwt) { @@ -72,6 +72,6 @@ export class UserService { } public static get Instance() { - return this._instance || (this._instance = new this()); + return this.#instance || (this.#instance = new this()); } }