mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-04-05 08:03:39 +03:00
Check log-in state for Composer page
This commit is contained in:
parent
714fcb4b17
commit
afa47da694
1 changed files with 51 additions and 18 deletions
|
@ -9,8 +9,10 @@ import { render } from 'preact';
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
|
|
||||||
import ComposeSuspense from './components/compose-suspense';
|
import ComposeSuspense from './components/compose-suspense';
|
||||||
|
import Loader from './components/loader';
|
||||||
import { initActivateLang } from './utils/lang';
|
import { initActivateLang } from './utils/lang';
|
||||||
import { initStates } from './utils/states';
|
import { initStates } from './utils/states';
|
||||||
|
import { getCurrentAccount, setCurrentAccountID } from './utils/store-utils';
|
||||||
import useTitle from './utils/useTitle';
|
import useTitle from './utils/useTitle';
|
||||||
|
|
||||||
initActivateLang();
|
initActivateLang();
|
||||||
|
@ -21,6 +23,7 @@ if (window.opener) {
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [uiState, setUIState] = useState('default');
|
const [uiState, setUIState] = useState('default');
|
||||||
|
const [isLoggedIn, setIsLoggedIn] = useState(null);
|
||||||
|
|
||||||
const { editStatus, replyToStatus, draftStatus } = window.__COMPOSE__ || {};
|
const { editStatus, replyToStatus, draftStatus } = window.__COMPOSE__ || {};
|
||||||
|
|
||||||
|
@ -35,7 +38,11 @@ function App() {
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const account = getCurrentAccount();
|
||||||
|
setIsLoggedIn(!!account);
|
||||||
|
if (account) {
|
||||||
initStates();
|
initStates();
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -69,6 +76,25 @@ function App() {
|
||||||
|
|
||||||
console.debug('OPEN COMPOSE');
|
console.debug('OPEN COMPOSE');
|
||||||
|
|
||||||
|
if (isLoggedIn === false) {
|
||||||
|
return (
|
||||||
|
<div class="box">
|
||||||
|
<h1>
|
||||||
|
<Trans>Error</Trans>
|
||||||
|
</h1>
|
||||||
|
<p>
|
||||||
|
<Trans>Login required.</Trans>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="/">
|
||||||
|
<Trans>Go home</Trans>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoggedIn) {
|
||||||
return (
|
return (
|
||||||
<ComposeSuspense
|
<ComposeSuspense
|
||||||
editStatus={editStatus}
|
editStatus={editStatus}
|
||||||
|
@ -90,6 +116,13 @@ function App() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class="box">
|
||||||
|
<Loader />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<I18nProvider i18n={i18n}>
|
<I18nProvider i18n={i18n}>
|
||||||
<App />
|
<App />
|
||||||
|
|
Loading…
Add table
Reference in a new issue