Handle when logged out (#986)

* Add logged out messages to profile and community

* Remove errors when not logged in

* Add logged out translations
This commit is contained in:
SleeplessOne1917 2023-05-03 16:09:47 +00:00 committed by GitHub
parent 3526baf465
commit 2e78191dae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 17 deletions

@ -1 +1 @@
Subproject commit 5c50ce3ebaf058ad5d4e9bcd445653960cbc98b1 Subproject commit 007e53683768aeba63e9e4c179c1d240217bcee2

View file

@ -1,8 +1,9 @@
import { Component } from "inferno"; import { Component } from "inferno";
import { Redirect } from "inferno-router";
import { CommunityView, GetSiteResponse } from "lemmy-js-client"; import { CommunityView, GetSiteResponse } from "lemmy-js-client";
import { Subscription } from "rxjs"; import { Subscription } from "rxjs";
import { i18n } from "../../i18next"; import { i18n } from "../../i18next";
import { UserService } from "../../services"; import { UserService } from "../../services/UserService";
import { import {
enableNsfw, enableNsfw,
isBrowser, isBrowser,
@ -32,11 +33,6 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
this.parseMessage = this.parseMessage.bind(this); this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage); this.subscription = wsSubscribe(this.parseMessage);
if (!UserService.Instance.myUserInfo && isBrowser()) {
toast(i18n.t("not_logged_in"), "danger");
this.context.router.history.push(`/login`);
}
} }
componentWillUnmount() { componentWillUnmount() {
@ -54,6 +50,7 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
render() { render() {
return ( return (
<div className="container-lg"> <div className="container-lg">
{!UserService.Instance.myUserInfo && <Redirect to="/login" />}
<HtmlTags <HtmlTags
title={this.documentTitle} title={this.documentTitle}
path={this.context.router.route.match.url} path={this.context.router.route.match.url}

View file

@ -20,6 +20,7 @@ import {
amMod, amMod,
amTopMod, amTopMod,
getUnixTime, getUnixTime,
hostname,
mdToHtml, mdToHtml,
myAuth, myAuth,
numToSI, numToSI,
@ -91,15 +92,25 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
} }
sidebar() { sidebar() {
const myUSerInfo = UserService.Instance.myUserInfo;
const { name, actor_id } = this.props.community_view.community;
return ( return (
<div> <div>
<div className="card border-secondary mb-3"> <div className="card border-secondary mb-3">
<div className="card-body"> <div className="card-body">
{this.communityTitle()} {this.communityTitle()}
{this.props.editable && this.adminButtons()} {this.props.editable && this.adminButtons()}
{this.subscribe()} {myUSerInfo && this.subscribe()}
{this.canPost && this.createPost()} {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> </div>
<div className="card border-secondary mb-3"> <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} /> <BannerIconHeader icon={community.icon} banner={community.banner} />
)} )}
<span className="mr-2">{community.title}</span> <span className="mr-2">{community.title}</span>
{subscribed == SubscribedType.Subscribed && ( {subscribed === SubscribedType.Subscribed && (
<button <button
className="btn btn-secondary btn-sm mr-2" className="btn btn-secondary btn-sm mr-2"
onClick={linkEvent(this, this.handleUnsubscribe)} onClick={linkEvent(this, this.handleUnsubscribe)}
@ -132,7 +143,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
{i18n.t("joined")} {i18n.t("joined")}
</button> </button>
)} )}
{subscribed == SubscribedType.Pending && ( {subscribed === SubscribedType.Pending && (
<button <button
className="btn btn-warning mr-2" className="btn btn-warning mr-2"
onClick={linkEvent(this, this.handleUnsubscribe)} onClick={linkEvent(this, this.handleUnsubscribe)}

View file

@ -530,6 +530,11 @@ export class Profile extends Component<
.format("MMM DD, YYYY")} .format("MMM DD, YYYY")}
</span> </span>
</div> </div>
{!UserService.Instance.myUserInfo && (
<div className="alert alert-info" role="alert">
{i18n.t("profile_not_logged_in_alert")}
</div>
)}
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,4 +1,5 @@
import { Component } from "inferno"; import { Component } from "inferno";
import { Redirect } from "inferno-router";
import { RouteComponentProps } from "inferno-router/dist/Route"; import { RouteComponentProps } from "inferno-router/dist/Route";
import { import {
GetCommunity, GetCommunity,
@ -69,11 +70,6 @@ export class CreatePost extends Component<
this.parseMessage = this.parseMessage.bind(this); this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage); 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 // Only fetch the data if coming from another route
if (this.isoData.path === this.context.router.route.match.url) { if (this.isoData.path === this.context.router.route.match.url) {
const communityRes = this.isoData.routeData[0] as const communityRes = this.isoData.routeData[0] as
@ -149,6 +145,7 @@ export class CreatePost extends Component<
return ( return (
<div className="container-lg"> <div className="container-lg">
{!UserService.Instance.myUserInfo && <Redirect to="/login" />}
<HtmlTags <HtmlTags
title={this.documentTitle} title={this.documentTitle}
path={this.context.router.route.match.url} path={this.context.router.route.match.url}
@ -189,7 +186,7 @@ export class CreatePost extends Component<
| PostFormParams | PostFormParams
| undefined; | undefined;
this.props.history.push( this.props.history.replace(
`/create_post${getQueryString(queryParams)}`, `/create_post${getQueryString(queryParams)}`,
locationState locationState
); );