fix publicEvents and eventHandlers

This commit is contained in:
srgooglo 2022-05-31 01:53:03 +02:00
parent ade7db35dc
commit 36262132f3

View File

@ -76,18 +76,24 @@ class App extends React.Component {
window.app.version = config.package.version
}
static eventsHandlers = {
"app.createLogin": async function () {
publicEvents = {
"clearAllOverlays": function () {
window.app.DrawerController.closeAll()
},
}
eventsHandlers = {
"app.createLogin": async () => {
app.DrawerController.open("login", Login, {
componentProps: {
sessionController: this.sessionController
}
})
},
"session.logout": async function () {
"session.logout": async () => {
await this.sessionController.logout()
},
"new_session": async function () {
"new_session": async () => {
await this.flushState()
await this.initialization()
@ -96,23 +102,22 @@ class App extends React.Component {
this.beforeLoginLocation = null
}
},
"destroyed_session": async function () {
"destroyed_session": async () => {
await this.flushState()
app.eventBus.emit("forceToLogin")
},
"forceToLogin": function () {
// if (window.location.pathname !== "/login") {
// this.beforeLoginLocation = window.location.pathname
// }
// window.app.setLocation("/login")
"forceToLogin": () => {
app.setLocation("/main")
app.eventBus.emit("app.createLogin")
},
"invalid_session": async function (error) {
"invalid_session": async (error) => {
if (!this.state.session) {
return false
}
await this.sessionController.forgetLocalSession()
await this.flushState()
if (window.location.pathname !== "/login") {
app.eventBus.emit("forceToLogin")
antd.notification.open({
@ -124,15 +129,12 @@ class App extends React.Component {
</Translation>,
icon: <Icons.MdOutlineAccessTimeFilled />,
})
}
},
"clearAllOverlays": function () {
window.app.DrawerController.closeAll()
},
"websocket_connected": function () {
"websocket_connected": () => {
if (this.wsReconnecting) {
this.wsReconnectingTry = 0
this.wsReconnecting = false
this.initialization()
setTimeout(() => {
@ -143,7 +145,7 @@ class App extends React.Component {
}, 500)
}
},
"websocket_connection_error": function () {
"websocket_connection_error": () => {
if (!this.wsReconnecting) {
this.latencyWarning = null
this.wsReconnectingTry = 0
@ -162,7 +164,7 @@ class App extends React.Component {
window.location.reload()
}
},
"websocket_latency_too_high": function () {
"websocket_latency_too_high": () => {
if (!this.latencyWarning) {
this.latencyWarning = true
@ -173,7 +175,7 @@ class App extends React.Component {
})
}
},
"websocket_latency_normal": function () {
"websocket_latency_normal": () => {
if (this.latencyWarning) {
this.latencyWarning = null
@ -251,6 +253,14 @@ class App extends React.Component {
},
}
constructor(props) {
super(props)
Object.keys(this.eventsHandlers).forEach((event) => {
app.eventBus.on(event, this.eventsHandlers[event])
})
}
flushState = async () => {
await this.setState({ session: null, user: null })
}