mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-01 16:51:13 +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 { 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}
|
||||
|
|
|
@ -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)}
|
||||
|
|
|
@ -540,6 +540,11 @@ export class Profile extends Component<any, ProfileState> {
|
|||
.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>
|
||||
|
|
|
@ -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<any, CreatePostState> {
|
|||
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<any, CreatePostState> {
|
|||
let res = this.state.listCommunitiesResponse;
|
||||
return (
|
||||
<div className="container-lg">
|
||||
{!UserService.Instance.myUserInfo && <Redirect to="/login" />}
|
||||
<HtmlTags
|
||||
title={this.documentTitle}
|
||||
path={this.context.router.route.match.url}
|
||||
|
@ -166,7 +163,16 @@ export class CreatePost extends Component<any, CreatePostState> {
|
|||
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 {
|
||||
|
|
Loading…
Reference in a new issue