mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-02 01:01:14 +00:00
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:
parent
70f285fa20
commit
a2bcc37008
5 changed files with 36 additions and 17 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 7379716231b9f7e67f710751c839398b7ab5d65e
|
Subproject commit 3ad48e2c3cb444c76399aa31d50a13f7571e4aab
|
|
@ -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}
|
||||||
|
|
|
@ -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)}
|
||||||
|
|
|
@ -540,6 +540,11 @@ export class Profile extends Component<any, ProfileState> {
|
||||||
.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>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Component } from "inferno";
|
import { Component } from "inferno";
|
||||||
|
import { Redirect } from "inferno-router";
|
||||||
import {
|
import {
|
||||||
GetCommunity,
|
GetCommunity,
|
||||||
GetCommunityResponse,
|
GetCommunityResponse,
|
||||||
|
@ -53,11 +54,6 @@ export class CreatePost extends Component<any, CreatePostState> {
|
||||||
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) {
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -117,6 +113,7 @@ export class CreatePost extends Component<any, CreatePostState> {
|
||||||
let res = this.state.listCommunitiesResponse;
|
let res = this.state.listCommunitiesResponse;
|
||||||
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}
|
||||||
|
@ -166,7 +163,16 @@ export class CreatePost extends Component<any, CreatePostState> {
|
||||||
url: urlParams.get("url") ?? undefined,
|
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 {
|
get prevCommunityName(): string | undefined {
|
||||||
|
|
Loading…
Reference in a new issue