From a2bcc37008b78cef14f00841a54337135fc77ccb Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Wed, 3 May 2023 16:09:47 +0000 Subject: [PATCH] Handle when logged out (#986) * Add logged out messages to profile and community * Remove errors when not logged in * Add logged out translations --- lemmy-translations | 2 +- .../components/community/create-community.tsx | 9 +++------ src/shared/components/community/sidebar.tsx | 19 +++++++++++++++---- src/shared/components/person/profile.tsx | 5 +++++ src/shared/components/post/create-post.tsx | 18 ++++++++++++------ 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lemmy-translations b/lemmy-translations index 73797162..3ad48e2c 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 7379716231b9f7e67f710751c839398b7ab5d65e +Subproject commit 3ad48e2c3cb444c76399aa31d50a13f7571e4aab diff --git a/src/shared/components/community/create-community.tsx b/src/shared/components/community/create-community.tsx index da8ef09d..81c62531 100644 --- a/src/shared/components/community/create-community.tsx +++ b/src/shared/components/community/create-community.tsx @@ -1,8 +1,9 @@ import { Component } from "inferno"; +import { Redirect } from "inferno-router"; import { CommunityView, GetSiteResponse } from "lemmy-js-client"; import { Subscription } from "rxjs"; import { i18n } from "../../i18next"; -import { UserService } from "../../services"; +import { UserService } from "../../services/UserService"; import { enableNsfw, isBrowser, @@ -32,11 +33,6 @@ export class CreateCommunity extends Component { this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); - - if (!UserService.Instance.myUserInfo && isBrowser()) { - toast(i18n.t("not_logged_in"), "danger"); - this.context.router.history.push(`/login`); - } } componentWillUnmount() { @@ -54,6 +50,7 @@ export class CreateCommunity extends Component { render() { return (
+ {!UserService.Instance.myUserInfo && } { } sidebar() { + const myUSerInfo = UserService.Instance.myUserInfo; + const { name, actor_id } = this.props.community_view.community; return (
{this.communityTitle()} {this.props.editable && this.adminButtons()} - {this.subscribe()} + {myUSerInfo && this.subscribe()} {this.canPost && this.createPost()} - {this.blockCommunity()} + {myUSerInfo && this.blockCommunity()} + {!myUSerInfo && ( +
+ {i18n.t("community_not_logged_in_alert", { + community: name, + instance: hostname(actor_id), + })} +
+ )}
@@ -123,7 +134,7 @@ export class Sidebar extends Component { )} {community.title} - {subscribed == SubscribedType.Subscribed && ( + {subscribed === SubscribedType.Subscribed && ( )} - {subscribed == SubscribedType.Pending && ( + {subscribed === SubscribedType.Pending && (
+ {!UserService.Instance.myUserInfo && ( +
+ {i18n.t("profile_not_logged_in_alert")} +
+ )}
diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx index c1d282e9..b5b391e4 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -1,4 +1,5 @@ import { Component } from "inferno"; +import { Redirect } from "inferno-router"; import { GetCommunity, GetCommunityResponse, @@ -53,11 +54,6 @@ export class CreatePost extends Component { this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); - if (!UserService.Instance.myUserInfo && isBrowser()) { - toast(i18n.t("not_logged_in"), "danger"); - this.context.router.history.push(`/login`); - } - // Only fetch the data if coming from another route if (this.isoData.path == this.context.router.route.match.url) { this.state = { @@ -117,6 +113,7 @@ export class CreatePost extends Component { let res = this.state.listCommunitiesResponse; return (
+ {!UserService.Instance.myUserInfo && } { url: urlParams.get("url") ?? undefined, }; - return params; + const locationState = this.props.history.location.state as + | PostFormParams + | undefined; + + this.props.history.replace( + `/create_post${getQueryString(queryParams)}`, + locationState + ); + + this.fetchCommunity(); } get prevCommunityName(): string | undefined {