Web: Common/Doceditor: fixed user request when initializing auth state

This commit is contained in:
Artem Tarasov 2022-07-25 16:14:24 +03:00
parent 9dcff71504
commit ba40abd43e
4 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,6 @@
export const LANGUAGE = "language";
export const ARTICLE_PINNED_KEY = "asc_article_pinned_key";
export const EDITOR_INITIAL_STATE = "__ASC_INITIAL_EDITOR_STATE__";
/**
* Enum for employee activation status.
* @readonly

View File

@ -1,5 +1,6 @@
import { makeAutoObservable } from "mobx";
import api from "../api";
import { EDITOR_INITIAL_STATE } from "../constants";
class UserStore {
user = null;
@ -12,7 +13,11 @@ class UserStore {
}
loadCurrentUser = async () => {
const user = await api.people.getUser();
let user = null;
if (window[`${EDITOR_INITIAL_STATE}`]?.user)
user = window[`${EDITOR_INITIAL_STATE}`].user;
else user = await api.people.getUser();
this.setUser(user);
};

View File

@ -4,8 +4,9 @@ import { registerSW } from "@appserver/common/sw/helper";
import App from "./App.js";
import pkg from "../../package.json";
import { initI18n } from "./helpers/utils.js";
import { EDITOR_INITIAL_STATE } from "@appserver/common/constants";
const propsObj = window.__ASC_INITIAL_EDITOR_STATE__;
const propsObj = window[`${EDITOR_INITIAL_STATE}`];
const initialI18nStoreASC = window.initialI18nStoreASC;
const initialLanguage = window.initialLanguage;

View File

@ -1,5 +1,6 @@
import { getFavicon, getScripts } from "./helpers";
import pkg from "../../../package.json";
import { EDITOR_INITIAL_STATE } from "@appserver/common/constants";
export default function template(
initialEditorState = {},
@ -33,10 +34,8 @@ export default function template(
}
const scripts = `
<script id="__ASC_INITIAL_EDITOR_STATE__">
window.__ASC_INITIAL_EDITOR_STATE__ = ${JSON.stringify(
initialEditorState
)}
<script id="${EDITOR_INITIAL_STATE}">
window.${EDITOR_INITIAL_STATE} = ${JSON.stringify(initialEditorState)}
</script>
<script id="__ASC_INITIAL_EDITOR_I18N__">
window.initialI18nStoreASC = ${JSON.stringify(initialI18nStoreASC)}