slightly better early page

Changed files
+50 -19
atproto-notifications
src
+4
atproto-notifications/src/App.css
··· 41 padding: 0.5rem 1rem; 42 } 43 44 .detail { 45 font-style: italic; 46 font-size: 0.8rem;
··· 41 padding: 0.5rem 1rem; 42 } 43 44 + h3 { 45 + margin-top: 2rem; 46 + } 47 + 48 .detail { 49 font-style: italic; 50 font-size: 0.8rem;
+46 -19
atproto-notifications/src/pages/Early.tsx
··· 1 import { useCallback, useState } from 'react'; 2 import { postJson } from '../components/Fetch'; 3 import './Early.css'; 4 5 export function Early({ }) { 6 - const [pushCount, setPushCount] = useState(0); 7 const [pushStatus, setPushStatus] = useState(null); 8 9 const localTest = useCallback(() => { 10 - new Notification("Hello world!", { body: "This notification never left your browser" }); 11 }); 12 13 const pushTest = useCallback(async () => { 14 - setPushStatus(n => n + 1); 15 setPushStatus('pending'); 16 const host = import.meta.env.VITE_NOTIFICATIONS_HOST; 17 const url = new URL('/push-test', host); ··· 22 console.error('failed push test request', e); 23 setPushStatus('failed'); 24 } 25 }); 26 27 return ( ··· 30 <p>Welcome to the early preview for the spacedust notifications demo, and since you're here early: thanks so much for supporting microcosm!</p> 31 <p>A few things to keep in mind:</p> 32 <ol> 33 - <li>This is a demo, not a polished product</li> 34 - <li>It has a lot of moving pieces, so things not always work</li> 35 - <li>Many features can easily be added! Some others can't! Make a request and let's see :)</li> 36 <li>It's not a long-term committed part of microcosm <em>(yet)</em></li> 37 </ol> 38 - <p>Sadly, it doesn't really work on mobile. iOS will stop delivering notifications after some minutes. Android people might have better luck?</p> 39 <p>With that out of the way, let's cover some basics!</p> 40 - <h3>Hello hello</h3> 41 <p> 42 To see a test notification, <button onClick={localTest}>click on this</button>. This is a local-only test. 43 </p> 44 - <p> 45 - <button 46 - disabled={pushStatus === 'pending'} 47 - onClick={pushTest} 48 - > 49 - Click here {pushCount > 0 && <>({pushCount})</>} 50 - </button> 51 - {' '} 52 - to see another. This one goes over Web Push. 53 - </p> 54 - {pushStatus === 'failed' && <p>uh oh, something went wrong requesting a web push</p>} 55 </div> 56 ); 57 }
··· 1 import { useCallback, useState } from 'react'; 2 + import { Link } from 'react-router'; 3 import { postJson } from '../components/Fetch'; 4 import './Early.css'; 5 6 export function Early({ }) { 7 + const [notified, setNotified] = useState(false); 8 const [pushStatus, setPushStatus] = useState(null); 9 + const [pushed, setPushed] = useState(false); 10 11 const localTest = useCallback(() => { 12 + try { 13 + new Notification("Hello world!", { body: "This notification never left your browser" }); 14 + } catch (e) { 15 + console.error('failed to create local notification', e); 16 + alert('Failed to create local notification. If you\'re up for helping debug, get in touch.'); 17 + } 18 + setNotified(true); 19 }); 20 21 const pushTest = useCallback(async () => { 22 setPushStatus('pending'); 23 const host = import.meta.env.VITE_NOTIFICATIONS_HOST; 24 const url = new URL('/push-test', host); ··· 29 console.error('failed push test request', e); 30 setPushStatus('failed'); 31 } 32 + setPushed(true); 33 }); 34 35 return ( ··· 38 <p>Welcome to the early preview for the spacedust notifications demo, and since you're here early: thanks so much for supporting microcosm!</p> 39 <p>A few things to keep in mind:</p> 40 <ol> 41 + <li>This is a <a href="https://spacedust.microcosm.blue" target="_blank">spacedust</a> demo, not a polished product</li> 42 <li>It's not a long-term committed part of microcosm <em>(yet)</em></li> 43 + <li>Mobile browsers are unreliable at delivering Web Push notifications</li> 44 + <li>Many features are easy to add! Some are surprisingly hard! Make a request and let's see :)</li> 45 </ol> 46 <p>With that out of the way, let's cover some basics!</p> 47 + 48 + <h3>Testing 1, 2, 3&hellip;</h3> 49 <p> 50 To see a test notification, <button onClick={localTest}>click on this</button>. This is a local-only test. 51 </p> 52 + {notified && ( 53 + <> 54 + <p> 55 + Then 56 + {' '} 57 + <button 58 + disabled={pushStatus === 'pending'} 59 + onClick={pushTest} 60 + > 61 + click here {pushed > 0 && '✅'} 62 + </button> 63 + {' '} 64 + for another. This one uses Web Push! 65 + </p> 66 + {pushStatus === 'failed' && <p>uh oh, something went wrong requesting a web push</p>} 67 + </> 68 + )} 69 + {(pushed && pushStatus !== 'failed') && ( 70 + <> 71 + <h3>Great!</h3> 72 + <p> 73 + You can get back to this page by clicking the early 74 + <span className="chrome-role-tag">early</span> 75 + {' '} 76 + tag by your handle. 77 + </p> 78 + <p><Link to="/">Go to Notifications</Link></p> 79 + </> 80 + )} 81 + 82 </div> 83 ); 84 }