From 1f2831e47ac2c2ec3c2f4d627784d082c989992e Mon Sep 17 00:00:00 2001 From: srgooglo Date: Fri, 13 May 2022 21:47:57 +0200 Subject: [PATCH] added `app.createLogin` & `app.logout` handlers --- packages/app/src/App.jsx | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/app/src/App.jsx b/packages/app/src/App.jsx index 8528afcf..82f08f22 100644 --- a/packages/app/src/App.jsx +++ b/packages/app/src/App.jsx @@ -53,7 +53,7 @@ import { Translation } from "react-i18next" import { Session, User } from "models" import config from "config" -import { NotFound, RenderError, Crash, Settings, Navigation } from "components" +import { NotFound, RenderError, Crash, Settings, Navigation, Login } from "components" import { Icons } from "components/Icons" import Layout from "./layout" @@ -62,7 +62,16 @@ import * as Render from "extensions/render.extension.jsx" import "theme/index.less" class App extends React.Component { - //static debugMode = true + //static debugMode = true // this will enable debug mode of evite app (dah...) + + sessionController = new Session() + + userController = new User() + + state = { + session: null, + user: null, + } loadingMessage = false @@ -71,6 +80,16 @@ class App extends React.Component { } static eventsHandlers = { + "app.createLogin": async function () { + app.DrawerController.open("login", Login, { + componentProps: { + sessionController: this.sessionController + } + }) + }, + "session.logout": async function () { + await this.sessionController.logout() + }, "new_session": async function () { await this.flushState() await this.initialization() @@ -85,11 +104,12 @@ class App extends React.Component { this.eventBus.emit("forceToLogin") }, "forceToLogin": function () { - if (window.location.pathname !== "/login") { - this.beforeLoginLocation = window.location.pathname - } + // if (window.location.pathname !== "/login") { + // this.beforeLoginLocation = window.location.pathname + // } - window.app.setLocation("/login") + // window.app.setLocation("/login") + app.eventBus.emit("app.createLogin") }, "invalid_session": async function (error) { await this.sessionController.forgetLocalSession() @@ -246,13 +266,6 @@ class App extends React.Component { } } - sessionController = new Session() - userController = new User() - state = { - session: null, - user: null, - } - flushState = async () => { await this.setState({ session: null, user: null }) }