phanpy/src/compose.jsx

65 lines
1.3 KiB
React
Raw Normal View History

import './index.css';
import './app.css';
import '@github/time-elements';
import { render } from 'preact';
import { useEffect, useState } from 'preact/hooks';
import Compose from './components/compose';
if (window.opener) {
console = window.opener.console;
}
function App() {
const [uiState, setUIState] = useState('default');
const { editStatus, replyToStatus, draftStatus } = window.__COMPOSE__ || {};
useEffect(() => {
if (uiState === 'closed') {
window.close();
}
}, [uiState]);
if (uiState === 'closed') {
return (
2022-12-14 16:48:17 +03:00
<div class="box">
<p>You may close this page now.</p>
<p>
<button
onClick={() => {
window.close();
}}
>
Close window
</button>
</p>
</div>
);
}
return (
<Compose
editStatus={editStatus}
replyToStatus={replyToStatus}
draftStatus={draftStatus}
standalone
2022-12-14 16:48:17 +03:00
hasOpener={window.opener}
onClose={(results) => {
const { newStatus, fn = () => {} } = results || {};
try {
if (newStatus) {
window.opener.__STATES__.reloadStatusPage++;
}
fn();
setUIState('closed');
} catch (e) {}
}}
/>
);
}
2022-12-14 16:48:17 +03:00
render(<App />, document.getElementById('app-standalone'));