1
0
Fork 0
mirror of https://github.com/cheeaun/phanpy.git synced 2025-04-05 16:13:47 +03:00

Check log-in state for Composer page

This commit is contained in:
Lim Chee Aun 2024-08-24 18:15:24 +08:00
parent 714fcb4b17
commit afa47da694

View file

@ -9,8 +9,10 @@ import { render } from 'preact';
import { useEffect, useState } from 'preact/hooks';
import ComposeSuspense from './components/compose-suspense';
import Loader from './components/loader';
import { initActivateLang } from './utils/lang';
import { initStates } from './utils/states';
import { getCurrentAccount, setCurrentAccountID } from './utils/store-utils';
import useTitle from './utils/useTitle';
initActivateLang();
@ -21,6 +23,7 @@ if (window.opener) {
function App() {
const [uiState, setUIState] = useState('default');
const [isLoggedIn, setIsLoggedIn] = useState(null);
const { editStatus, replyToStatus, draftStatus } = window.__COMPOSE__ || {};
@ -35,7 +38,11 @@ function App() {
);
useEffect(() => {
const account = getCurrentAccount();
setIsLoggedIn(!!account);
if (account) {
initStates();
}
}, []);
useEffect(() => {
@ -69,6 +76,25 @@ function App() {
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}
@ -88,6 +114,13 @@ function App() {
}}
/>
);
}
return (
<div class="box">
<Loader />
</div>
);
}
render(