From afa47da694e86d7bbfb323aab74e8d775a0be383 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 24 Aug 2024 18:15:24 +0800 Subject: [PATCH] Check log-in state for Composer page --- src/compose.jsx | 69 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/src/compose.jsx b/src/compose.jsx index 47545066..296c74fc 100644 --- a/src/compose.jsx +++ b/src/compose.jsx @@ -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(() => { - initStates(); + const account = getCurrentAccount(); + setIsLoggedIn(!!account); + if (account) { + initStates(); + } }, []); useEffect(() => { @@ -69,24 +76,50 @@ function App() { console.debug('OPEN COMPOSE'); + if (isLoggedIn === false) { + return ( +
+

+ Error +

+

+ Login required. +

+

+ + Go home + +

+
+ ); + } + + if (isLoggedIn) { + return ( + { + const { newStatus, fn = () => {} } = results || {}; + try { + if (newStatus) { + window.opener.__STATES__.reloadStatusPage++; + } + fn(); + setUIState('closed'); + } catch (e) {} + }} + /> + ); + } + return ( - { - const { newStatus, fn = () => {} } = results || {}; - try { - if (newStatus) { - window.opener.__STATES__.reloadStatusPage++; - } - fn(); - setUIState('closed'); - } catch (e) {} - }} - /> +
+ +
); }