this repo has no description
at hotfix/infinite-loop-intersection-observer 80 lines 1.7 kB view raw
1import './index.css'; 2 3import './app.css'; 4 5import { render } from 'preact'; 6import { useEffect, useState } from 'preact/hooks'; 7 8import Compose from './components/compose'; 9import useTitle from './utils/useTitle'; 10 11if (window.opener) { 12 console = window.opener.console; 13} 14 15function App() { 16 const [uiState, setUIState] = useState('default'); 17 18 const { editStatus, replyToStatus, draftStatus } = window.__COMPOSE__ || {}; 19 20 useTitle( 21 editStatus 22 ? 'Editing source status' 23 : replyToStatus 24 ? `Replying to @${ 25 replyToStatus.account?.acct || replyToStatus.account?.username 26 }` 27 : 'Compose', 28 ); 29 30 useEffect(() => { 31 if (uiState === 'closed') { 32 try { 33 // Focus parent window 34 window.opener.focus(); 35 } catch (e) {} 36 window.close(); 37 } 38 }, [uiState]); 39 40 if (uiState === 'closed') { 41 return ( 42 <div class="box"> 43 <p>You may close this page now.</p> 44 <p> 45 <button 46 onClick={() => { 47 window.close(); 48 }} 49 > 50 Close window 51 </button> 52 </p> 53 </div> 54 ); 55 } 56 57 console.debug('OPEN COMPOSE'); 58 59 return ( 60 <Compose 61 editStatus={editStatus} 62 replyToStatus={replyToStatus} 63 draftStatus={draftStatus} 64 standalone 65 hasOpener={window.opener} 66 onClose={(results) => { 67 const { newStatus, fn = () => {} } = results || {}; 68 try { 69 if (newStatus) { 70 window.opener.__STATES__.reloadStatusPage++; 71 } 72 fn(); 73 setUIState('closed'); 74 } catch (e) {} 75 }} 76 /> 77 ); 78} 79 80render(<App />, document.getElementById('app-standalone'));