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