mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2025-01-11 12:35:49 +00:00
parent
9b8377760a
commit
130748a0c3
8 changed files with 28 additions and 55 deletions
|
@ -22,12 +22,10 @@ import {
|
||||||
amAdmin,
|
amAdmin,
|
||||||
auth,
|
auth,
|
||||||
donateLemmyUrl,
|
donateLemmyUrl,
|
||||||
getLanguages,
|
|
||||||
isBrowser,
|
isBrowser,
|
||||||
notifyComment,
|
notifyComment,
|
||||||
notifyPrivateMessage,
|
notifyPrivateMessage,
|
||||||
numToSI,
|
numToSI,
|
||||||
setTheme,
|
|
||||||
showAvatars,
|
showAvatars,
|
||||||
toast,
|
toast,
|
||||||
wsClient,
|
wsClient,
|
||||||
|
@ -90,18 +88,13 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
auth: auth().unwrap(),
|
auth: auth().unwrap(),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.props.siteRes.site_view.isSome()) {
|
||||||
this.fetchUnreads();
|
this.fetchUnreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userSub = UserService.Instance.jwtSub.subscribe(res => {
|
|
||||||
// A login
|
|
||||||
if (res.isSome()) {
|
|
||||||
this.requestNotificationPermission();
|
|
||||||
WebSocketService.Instance.send(
|
|
||||||
wsClient.getSite({ auth: res.map(r => r.jwt) })
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
this.requestNotificationPermission();
|
||||||
|
|
||||||
// Subscribe to unread count changes
|
// Subscribe to unread count changes
|
||||||
this.unreadInboxCountSub =
|
this.unreadInboxCountSub =
|
||||||
|
@ -628,18 +621,6 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
this.state.unreadApplicationCount = data.registration_applications;
|
this.state.unreadApplicationCount = data.registration_applications;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
this.sendApplicationUnread();
|
this.sendApplicationUnread();
|
||||||
} else if (op == UserOperation.GetSite) {
|
|
||||||
// This is only called on a successful login
|
|
||||||
let data = wsJsonToRes<GetSiteResponse>(msg, GetSiteResponse);
|
|
||||||
UserService.Instance.myUserInfo = data.my_user;
|
|
||||||
UserService.Instance.myUserInfo.match({
|
|
||||||
some: mui => {
|
|
||||||
setTheme(mui.local_user_view.local_user.theme);
|
|
||||||
i18n.changeLanguage(getLanguages()[0]);
|
|
||||||
this.setState(this.state);
|
|
||||||
},
|
|
||||||
none: void 0,
|
|
||||||
});
|
|
||||||
} else if (op == UserOperation.CreateComment) {
|
} else if (op == UserOperation.CreateComment) {
|
||||||
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ export class CommunityForm extends Component<
|
||||||
posting_restricted_to_mods: Some(
|
posting_restricted_to_mods: Some(
|
||||||
cv.community.posting_restricted_to_mods
|
cv.community.posting_restricted_to_mods
|
||||||
),
|
),
|
||||||
auth: auth().unwrap(),
|
auth: undefined,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
none: void 0,
|
none: void 0,
|
||||||
|
@ -293,6 +293,7 @@ export class CommunityForm extends Component<
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.state.loading = true;
|
i.state.loading = true;
|
||||||
let cForm = i.state.communityForm;
|
let cForm = i.state.communityForm;
|
||||||
|
cForm.auth = auth().unwrap();
|
||||||
|
|
||||||
i.props.community_view.match({
|
i.props.community_view.match({
|
||||||
some: cv => {
|
some: cv => {
|
||||||
|
@ -304,7 +305,7 @@ export class CommunityForm extends Component<
|
||||||
banner: cForm.banner,
|
banner: cForm.banner,
|
||||||
nsfw: cForm.nsfw,
|
nsfw: cForm.nsfw,
|
||||||
posting_restricted_to_mods: cForm.posting_restricted_to_mods,
|
posting_restricted_to_mods: cForm.posting_restricted_to_mods,
|
||||||
auth: auth().unwrap(),
|
auth: cForm.auth,
|
||||||
});
|
});
|
||||||
|
|
||||||
WebSocketService.Instance.send(wsClient.editCommunity(form));
|
WebSocketService.Instance.send(wsClient.editCommunity(form));
|
||||||
|
|
|
@ -123,7 +123,10 @@ export class Home extends Component<any, HomeState> {
|
||||||
listingType: getListingTypeFromProps(
|
listingType: getListingTypeFromProps(
|
||||||
this.props,
|
this.props,
|
||||||
ListingType[
|
ListingType[
|
||||||
this.isoData.site_res.site_view.unwrap().site.default_post_listing_type
|
this.isoData.site_res.site_view.match({
|
||||||
|
some: type_ => type_.site.default_post_listing_type,
|
||||||
|
none: ListingType.Local,
|
||||||
|
})
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
dataType: getDataTypeFromProps(this.props),
|
dataType: getDataTypeFromProps(this.props),
|
||||||
|
@ -186,7 +189,7 @@ export class Home extends Component<any, HomeState> {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// This means it hasn't been set up yet
|
// This means it hasn't been set up yet
|
||||||
if (!this.state.siteRes.site_view) {
|
if (this.state.siteRes.site_view.isNone()) {
|
||||||
this.context.router.history.push("/setup");
|
this.context.router.history.push("/setup");
|
||||||
}
|
}
|
||||||
setupTippy();
|
setupTippy();
|
||||||
|
|
|
@ -13,7 +13,6 @@ import { Subscription } from "rxjs";
|
||||||
import { i18n } from "../../i18next";
|
import { i18n } from "../../i18next";
|
||||||
import { UserService, WebSocketService } from "../../services";
|
import { UserService, WebSocketService } from "../../services";
|
||||||
import {
|
import {
|
||||||
auth,
|
|
||||||
isBrowser,
|
isBrowser,
|
||||||
setIsoData,
|
setIsoData,
|
||||||
toast,
|
toast,
|
||||||
|
@ -198,13 +197,6 @@ export class Login extends Component<any, State> {
|
||||||
this.state = this.emptyState;
|
this.state = this.emptyState;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
UserService.Instance.login(data);
|
UserService.Instance.login(data);
|
||||||
WebSocketService.Instance.send(
|
|
||||||
wsClient.userJoin({
|
|
||||||
auth: auth().unwrap(),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
toast(i18n.t("logged_in"));
|
|
||||||
this.props.history.push("/");
|
|
||||||
} else if (op == UserOperation.PasswordReset) {
|
} else if (op == UserOperation.PasswordReset) {
|
||||||
toast(i18n.t("reset_password_mail_sent"));
|
toast(i18n.t("reset_password_mail_sent"));
|
||||||
} else if (op == UserOperation.GetSite) {
|
} else if (op == UserOperation.GetSite) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ export class Setup extends Component<any, State> {
|
||||||
honeypot: None,
|
honeypot: None,
|
||||||
answer: None,
|
answer: None,
|
||||||
}),
|
}),
|
||||||
doneRegisteringUser: false,
|
doneRegisteringUser: UserService.Instance.myUserInfo.isSome(),
|
||||||
userLoading: false,
|
userLoading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -206,7 +206,6 @@ export class Setup extends Component<any, State> {
|
||||||
} else if (op == UserOperation.Register) {
|
} else if (op == UserOperation.Register) {
|
||||||
let data = wsJsonToRes<LoginResponse>(msg, LoginResponse);
|
let data = wsJsonToRes<LoginResponse>(msg, LoginResponse);
|
||||||
this.state.userLoading = false;
|
this.state.userLoading = false;
|
||||||
this.state.doneRegisteringUser = true;
|
|
||||||
UserService.Instance.login(data);
|
UserService.Instance.login(data);
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
} else if (op == UserOperation.CreateSite) {
|
} else if (op == UserOperation.CreateSite) {
|
||||||
|
|
|
@ -19,7 +19,6 @@ import { Subscription } from "rxjs";
|
||||||
import { i18n } from "../../i18next";
|
import { i18n } from "../../i18next";
|
||||||
import { UserService, WebSocketService } from "../../services";
|
import { UserService, WebSocketService } from "../../services";
|
||||||
import {
|
import {
|
||||||
auth,
|
|
||||||
isBrowser,
|
isBrowser,
|
||||||
joinLemmyUrl,
|
joinLemmyUrl,
|
||||||
mdToHtml,
|
mdToHtml,
|
||||||
|
@ -537,13 +536,8 @@ export class Signup extends Component<any, State> {
|
||||||
this.state = this.emptyState;
|
this.state = this.emptyState;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
// Only log them in if a jwt was set
|
// Only log them in if a jwt was set
|
||||||
if (data.jwt) {
|
if (data.jwt.isSome()) {
|
||||||
UserService.Instance.login(data);
|
UserService.Instance.login(data);
|
||||||
WebSocketService.Instance.send(
|
|
||||||
wsClient.userJoin({
|
|
||||||
auth: auth().unwrap(),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
this.props.history.push("/communities");
|
this.props.history.push("/communities");
|
||||||
} else {
|
} else {
|
||||||
if (data.verify_email_sent) {
|
if (data.verify_email_sent) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Err, None, Ok, Option, Result, Some } from "@sniptt/monads";
|
||||||
import IsomorphicCookie from "isomorphic-cookie";
|
import IsomorphicCookie from "isomorphic-cookie";
|
||||||
import jwt_decode from "jwt-decode";
|
import jwt_decode from "jwt-decode";
|
||||||
import { LoginResponse, MyUserInfo } from "lemmy-js-client";
|
import { LoginResponse, MyUserInfo } from "lemmy-js-client";
|
||||||
import { BehaviorSubject, Subject } from "rxjs";
|
import { BehaviorSubject } from "rxjs";
|
||||||
import { isHttps } from "../env";
|
import { isHttps } from "../env";
|
||||||
import { i18n } from "../i18next";
|
import { i18n } from "../i18next";
|
||||||
import { isBrowser, toast } from "../utils";
|
import { isBrowser, toast } from "../utils";
|
||||||
|
@ -23,7 +23,6 @@ export class UserService {
|
||||||
private static _instance: UserService;
|
private static _instance: UserService;
|
||||||
public myUserInfo: Option<MyUserInfo> = None;
|
public myUserInfo: Option<MyUserInfo> = None;
|
||||||
public jwtInfo: Option<JwtInfo> = None;
|
public jwtInfo: Option<JwtInfo> = None;
|
||||||
public jwtSub: Subject<Option<JwtInfo>> = new Subject<Option<JwtInfo>>();
|
|
||||||
public unreadInboxCountSub: BehaviorSubject<number> =
|
public unreadInboxCountSub: BehaviorSubject<number> =
|
||||||
new BehaviorSubject<number>(0);
|
new BehaviorSubject<number>(0);
|
||||||
public unreadReportCountSub: BehaviorSubject<number> =
|
public unreadReportCountSub: BehaviorSubject<number> =
|
||||||
|
@ -38,19 +37,23 @@ export class UserService {
|
||||||
public login(res: LoginResponse) {
|
public login(res: LoginResponse) {
|
||||||
let expires = new Date();
|
let expires = new Date();
|
||||||
expires.setDate(expires.getDate() + 365);
|
expires.setDate(expires.getDate() + 365);
|
||||||
IsomorphicCookie.save("jwt", res.jwt, { expires, secure: isHttps });
|
res.jwt.match({
|
||||||
console.log("jwt cookie set");
|
some: jwt => {
|
||||||
|
toast(i18n.t("logged_in"));
|
||||||
|
IsomorphicCookie.save("jwt", jwt, { expires, secure: isHttps });
|
||||||
this.setJwtInfo();
|
this.setJwtInfo();
|
||||||
|
location.reload();
|
||||||
|
},
|
||||||
|
none: void 0,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public logout() {
|
public logout() {
|
||||||
this.jwtInfo = None;
|
this.jwtInfo = None;
|
||||||
this.myUserInfo = None;
|
this.myUserInfo = None;
|
||||||
this.jwtSub.next(this.jwtInfo);
|
|
||||||
IsomorphicCookie.remove("jwt"); // TODO is sometimes unreliable for some reason
|
IsomorphicCookie.remove("jwt"); // TODO is sometimes unreliable for some reason
|
||||||
document.cookie = "jwt=; Max-Age=0; path=/; domain=" + location.host;
|
document.cookie = "jwt=; Max-Age=0; path=/; domain=" + location.host;
|
||||||
location.reload(); // TODO may not be necessary anymore
|
location.reload();
|
||||||
console.log("Logged out.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public auth(throwErr = true): Result<string, string> {
|
public auth(throwErr = true): Result<string, string> {
|
||||||
|
@ -74,7 +77,6 @@ export class UserService {
|
||||||
if (jwt) {
|
if (jwt) {
|
||||||
let jwtInfo: JwtInfo = { jwt, claims: jwt_decode(jwt) };
|
let jwtInfo: JwtInfo = { jwt, claims: jwt_decode(jwt) };
|
||||||
this.jwtInfo = Some(jwtInfo);
|
this.jwtInfo = Some(jwtInfo);
|
||||||
this.jwtSub.next(this.jwtInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1221,10 +1221,11 @@ export function setIsoData<Type1, Type2, Type3, Type4, Type5>(
|
||||||
if (routeData[4]) {
|
if (routeData[4]) {
|
||||||
routeDataOut[4] = convertWindowJson(cls5, routeData[4]);
|
routeDataOut[4] = convertWindowJson(cls5, routeData[4]);
|
||||||
}
|
}
|
||||||
|
let site_res = convertWindowJson(GetSiteResponse, json.site_res);
|
||||||
|
|
||||||
let isoData: IsoData = {
|
let isoData: IsoData = {
|
||||||
path: json.path,
|
path: json.path,
|
||||||
site_res: convertWindowJson(GetSiteResponse, json.site_res),
|
site_res,
|
||||||
routeData: routeDataOut,
|
routeData: routeDataOut,
|
||||||
};
|
};
|
||||||
return isoData;
|
return isoData;
|
||||||
|
|
Loading…
Reference in a new issue