]> Untitled Git - lemmy-ui.git/commitdiff
Handle when logged out (#986)
authorSleeplessOne1917 <abias1122@gmail.com>
Wed, 3 May 2023 16:09:47 +0000 (16:09 +0000)
committerGitHub <noreply@github.com>
Wed, 3 May 2023 16:09:47 +0000 (12:09 -0400)
* Add logged out messages to profile and community

* Remove errors when not logged in

* Add logged out translations

lemmy-translations
src/shared/components/community/create-community.tsx
src/shared/components/community/sidebar.tsx
src/shared/components/person/profile.tsx
src/shared/components/post/create-post.tsx

index 5c50ce3ebaf058ad5d4e9bcd445653960cbc98b1..007e53683768aeba63e9e4c179c1d240217bcee2 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 5c50ce3ebaf058ad5d4e9bcd445653960cbc98b1
+Subproject commit 007e53683768aeba63e9e4c179c1d240217bcee2
index da8ef09d81d742139070d7cbddb96b3a95af8abd..81c62531a0d045339de094c7537840fb5779e02a 100644 (file)
@@ -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<any, CreateCommunityState> {
 
     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<any, CreateCommunityState> {
   render() {
     return (
       <div className="container-lg">
+        {!UserService.Instance.myUserInfo && <Redirect to="/login" />}
         <HtmlTags
           title={this.documentTitle}
           path={this.context.router.route.match.url}
index 003f529b72801bf39f3e6407fb71e431ab249012..8b235595f6ad086f03b91128e1c0ea8c9fa09a5f 100644 (file)
@@ -20,6 +20,7 @@ import {
   amMod,
   amTopMod,
   getUnixTime,
+  hostname,
   mdToHtml,
   myAuth,
   numToSI,
@@ -91,15 +92,25 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
   }
 
   sidebar() {
+    const myUSerInfo = UserService.Instance.myUserInfo;
+    const { name, actor_id } = this.props.community_view.community;
     return (
       <div>
         <div className="card border-secondary mb-3">
           <div className="card-body">
             {this.communityTitle()}
             {this.props.editable && this.adminButtons()}
-            {this.subscribe()}
+            {myUSerInfo && this.subscribe()}
             {this.canPost && this.createPost()}
-            {this.blockCommunity()}
+            {myUSerInfo && this.blockCommunity()}
+            {!myUSerInfo && (
+              <div className="alert alert-info" role="alert">
+                {i18n.t("community_not_logged_in_alert", {
+                  community: name,
+                  instance: hostname(actor_id),
+                })}
+              </div>
+            )}
           </div>
         </div>
         <div className="card border-secondary mb-3">
@@ -123,7 +134,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
             <BannerIconHeader icon={community.icon} banner={community.banner} />
           )}
           <span className="mr-2">{community.title}</span>
-          {subscribed == SubscribedType.Subscribed && (
+          {subscribed === SubscribedType.Subscribed && (
             <button
               className="btn btn-secondary btn-sm mr-2"
               onClick={linkEvent(this, this.handleUnsubscribe)}
@@ -132,7 +143,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
               {i18n.t("joined")}
             </button>
           )}
-          {subscribed == SubscribedType.Pending && (
+          {subscribed === SubscribedType.Pending && (
             <button
               className="btn btn-warning mr-2"
               onClick={linkEvent(this, this.handleUnsubscribe)}
index 4065df127cf8651027949074766338c677b67d57..9b98816353c88265015118c1458bc64c007ce53e 100644 (file)
@@ -530,6 +530,11 @@ export class Profile extends Component<
                     .format("MMM DD, YYYY")}
                 </span>
               </div>
+              {!UserService.Instance.myUserInfo && (
+                <div className="alert alert-info" role="alert">
+                  {i18n.t("profile_not_logged_in_alert")}
+                </div>
+              )}
             </div>
           </div>
         </div>
index e40ca48102f242b3fceecd4858cdf0ba56818d12..4fcca529d053ef88d71c01b44c9132b97eef8170 100644 (file)
@@ -1,4 +1,5 @@
 import { Component } from "inferno";
+import { Redirect } from "inferno-router";
 import { RouteComponentProps } from "inferno-router/dist/Route";
 import {
   GetCommunity,
@@ -69,11 +70,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) {
       const communityRes = this.isoData.routeData[0] as
@@ -149,6 +145,7 @@ export class CreatePost extends Component<
 
     return (
       <div className="container-lg">
+        {!UserService.Instance.myUserInfo && <Redirect to="/login" />}
         <HtmlTags
           title={this.documentTitle}
           path={this.context.router.route.match.url}
@@ -189,7 +186,7 @@ export class CreatePost extends Component<
       | PostFormParams
       | undefined;
 
-    this.props.history.push(
+    this.props.history.replace(
       `/create_post${getQueryString(queryParams)}`,
       locationState
     );