mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-31 21:53:42 +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(() => {
|
||||||
initStates();
|
const account = getCurrentAccount();
|
||||||
|
setIsLoggedIn(!!account);
|
||||||
|
if (account) {
|
||||||
|
initStates();
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -69,24 +76,50 @@ 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 (
|
||||||
|
<ComposeSuspense
|
||||||
|
editStatus={editStatus}
|
||||||
|
replyToStatus={replyToStatus}
|
||||||
|
draftStatus={draftStatus}
|
||||||
|
standalone
|
||||||
|
hasOpener={window.opener}
|
||||||
|
onClose={(results) => {
|
||||||
|
const { newStatus, fn = () => {} } = results || {};
|
||||||
|
try {
|
||||||
|
if (newStatus) {
|
||||||
|
window.opener.__STATES__.reloadStatusPage++;
|
||||||
|
}
|
||||||
|
fn();
|
||||||
|
setUIState('closed');
|
||||||
|
} catch (e) {}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ComposeSuspense
|
<div class="box">
|
||||||
editStatus={editStatus}
|
<Loader />
|
||||||
replyToStatus={replyToStatus}
|
</div>
|
||||||
draftStatus={draftStatus}
|
|
||||||
standalone
|
|
||||||
hasOpener={window.opener}
|
|
||||||
onClose={(results) => {
|
|
||||||
const { newStatus, fn = () => {} } = results || {};
|
|
||||||
try {
|
|
||||||
if (newStatus) {
|
|
||||||
window.opener.__STATES__.reloadStatusPage++;
|
|
||||||
}
|
|
||||||
fn();
|
|
||||||
setUIState('closed');
|
|
||||||
} catch (e) {}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue