mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 06:11:15 +00:00
Fix/ws error messages (#334)
* Updating translations. * Translation updates * Adding websocket error and reconnect toasts. Fixes #129
This commit is contained in:
parent
efa4a639f4
commit
a0d9e5c672
3 changed files with 18 additions and 3 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 6dd3968a5e2da60884fe783a90e366bae7a96cc2
|
Subproject commit 4c122b5bed79e291957b9d913dd361a75b583271
|
|
@ -81,6 +81,8 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// Subscribe to jwt changes
|
// Subscribe to jwt changes
|
||||||
if (isBrowser()) {
|
if (isBrowser()) {
|
||||||
|
this.websocketEvents();
|
||||||
|
|
||||||
this.searchTextField = createRef();
|
this.searchTextField = createRef();
|
||||||
console.log(`isLoggedIn = ${this.state.isLoggedIn}`);
|
console.log(`isLoggedIn = ${this.state.isLoggedIn}`);
|
||||||
|
|
||||||
|
@ -393,6 +395,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (msg.reconnect) {
|
} else if (msg.reconnect) {
|
||||||
|
toast(i18n.t("websocket_reconnected"), "success");
|
||||||
WebSocketService.Instance.send(
|
WebSocketService.Instance.send(
|
||||||
wsClient.userJoin({
|
wsClient.userJoin({
|
||||||
auth: authField(),
|
auth: authField(),
|
||||||
|
@ -530,11 +533,19 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
get canCreateCommunity(): boolean {
|
get canCreateCommunity(): boolean {
|
||||||
let adminOnly = this.props.site_res.site_view?.site
|
let adminOnly =
|
||||||
.community_creation_admin_only;
|
this.props.site_res.site_view?.site.community_creation_admin_only;
|
||||||
return !adminOnly || this.canAdmin;
|
return !adminOnly || this.canAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Listens for some websocket errors
|
||||||
|
websocketEvents() {
|
||||||
|
let msg = i18n.t("websocket_disconnected");
|
||||||
|
WebSocketService.Instance.closeEventListener(() => {
|
||||||
|
toast(msg, "danger");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
requestNotificationPermission() {
|
requestNotificationPermission() {
|
||||||
if (UserService.Instance.localUserView) {
|
if (UserService.Instance.localUserView) {
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
|
|
@ -56,6 +56,10 @@ export class WebSocketService {
|
||||||
this.ws.send(data);
|
this.ws.send(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public closeEventListener(listener: (event: CloseEvent) => void) {
|
||||||
|
this.ws.addEventListener("close", listener);
|
||||||
|
}
|
||||||
|
|
||||||
public static get Instance() {
|
public static get Instance() {
|
||||||
return this._instance || (this._instance = new this());
|
return this._instance || (this._instance = new this());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue