2022-12-13 13:42:09 +01:00
|
|
|
import './index.css';
|
|
|
|
import './app.css';
|
2024-06-14 02:34:50 +02:00
|
|
|
import './polyfills';
|
|
|
|
|
2024-08-13 09:26:23 +02:00
|
|
|
import { i18n } from '@lingui/core';
|
|
|
|
import { t, Trans } from '@lingui/macro';
|
|
|
|
import { I18nProvider } from '@lingui/react';
|
2022-12-13 13:42:09 +01:00
|
|
|
import { render } from 'preact';
|
|
|
|
import { useEffect, useState } from 'preact/hooks';
|
|
|
|
|
2024-05-25 14:43:15 +02:00
|
|
|
import ComposeSuspense from './components/compose-suspense';
|
2024-08-24 12:15:24 +02:00
|
|
|
import Loader from './components/loader';
|
2024-08-13 09:26:23 +02:00
|
|
|
import { initActivateLang } from './utils/lang';
|
2024-04-25 07:59:01 +02:00
|
|
|
import { initStates } from './utils/states';
|
2024-08-24 12:15:24 +02:00
|
|
|
import { getCurrentAccount, setCurrentAccountID } from './utils/store-utils';
|
2022-12-15 10:11:15 +01:00
|
|
|
import useTitle from './utils/useTitle';
|
2022-12-13 13:42:09 +01:00
|
|
|
|
2024-08-13 09:26:23 +02:00
|
|
|
initActivateLang();
|
|
|
|
|
2022-12-13 14:54:16 +01:00
|
|
|
if (window.opener) {
|
|
|
|
console = window.opener.console;
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:42:09 +01:00
|
|
|
function App() {
|
|
|
|
const [uiState, setUIState] = useState('default');
|
2024-08-24 12:15:24 +02:00
|
|
|
const [isLoggedIn, setIsLoggedIn] = useState(null);
|
2022-12-13 13:42:09 +01:00
|
|
|
|
|
|
|
const { editStatus, replyToStatus, draftStatus } = window.__COMPOSE__ || {};
|
|
|
|
|
2022-12-15 10:11:15 +01:00
|
|
|
useTitle(
|
|
|
|
editStatus
|
2024-08-13 09:26:23 +02:00
|
|
|
? t`Editing source status`
|
2022-12-15 10:11:15 +01:00
|
|
|
: replyToStatus
|
2024-08-13 09:26:23 +02:00
|
|
|
? t`Replying to @${
|
2022-12-15 10:11:15 +01:00
|
|
|
replyToStatus.account?.acct || replyToStatus.account?.username
|
|
|
|
}`
|
2024-08-13 09:26:23 +02:00
|
|
|
: t`Compose`,
|
2022-12-15 10:11:15 +01:00
|
|
|
);
|
2022-12-13 13:42:09 +01:00
|
|
|
|
2024-04-25 07:59:01 +02:00
|
|
|
useEffect(() => {
|
2024-08-24 12:15:24 +02:00
|
|
|
const account = getCurrentAccount();
|
|
|
|
setIsLoggedIn(!!account);
|
|
|
|
if (account) {
|
|
|
|
initStates();
|
|
|
|
}
|
2024-04-25 07:59:01 +02:00
|
|
|
}, []);
|
|
|
|
|
2022-12-16 06:54:17 +01:00
|
|
|
useEffect(() => {
|
|
|
|
if (uiState === 'closed') {
|
|
|
|
try {
|
|
|
|
// Focus parent window
|
|
|
|
window.opener.focus();
|
|
|
|
} catch (e) {}
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
}, [uiState]);
|
|
|
|
|
2022-12-13 13:42:09 +01:00
|
|
|
if (uiState === 'closed') {
|
|
|
|
return (
|
2022-12-14 14:48:17 +01:00
|
|
|
<div class="box">
|
2024-08-13 09:26:23 +02:00
|
|
|
<p>
|
|
|
|
<Trans>You may close this page now.</Trans>
|
|
|
|
</p>
|
2022-12-13 13:42:09 +01:00
|
|
|
<p>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
window.close();
|
|
|
|
}}
|
|
|
|
>
|
2024-08-13 09:26:23 +02:00
|
|
|
<Trans>Close window</Trans>
|
2022-12-13 13:42:09 +01:00
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-11 10:07:47 +01:00
|
|
|
console.debug('OPEN COMPOSE');
|
|
|
|
|
2024-08-24 12:15:24 +02:00
|
|
|
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) {}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:42:09 +01:00
|
|
|
return (
|
2024-08-24 12:15:24 +02:00
|
|
|
<div class="box">
|
|
|
|
<Loader />
|
|
|
|
</div>
|
2022-12-13 13:42:09 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-13 09:26:23 +02:00
|
|
|
render(
|
|
|
|
<I18nProvider i18n={i18n}>
|
|
|
|
<App />
|
|
|
|
</I18nProvider>,
|
|
|
|
document.getElementById('app-standalone'),
|
|
|
|
);
|