···11+import { useCallback, useState } from 'react';
22+import { postJson } from '../components/Fetch';
33+import './Early.css';
44+55+export function Early({ }) {
66+ const [pushCount, setPushCount] = useState(0);
77+ const [pushStatus, setPushStatus] = useState(null);
88+99+ const localTest = useCallback(() => {
1010+ new Notification("Hello world!", { body: "This notification never left your browser" });
1111+ });
1212+1313+ const pushTest = useCallback(async () => {
1414+ setPushStatus(n => n + 1);
1515+ setPushStatus('pending');
1616+ const host = import.meta.env.VITE_NOTIFICATIONS_HOST;
1717+ const url = new URL('/push-test', host);
1818+ try {
1919+ await postJson(url, JSON.stringify(null), true);
2020+ setPushStatus(null);
2121+ } catch (e) {
2222+ console.error('failed push test request', e);
2323+ setPushStatus('failed');
2424+ }
2525+ });
2626+2727+ return (
2828+ <div className="early">
2929+ <h2>Hello!</h2>
3030+ <p>Welcome to the early preview for the spacedust notifications demo, and since you're here early: thanks so much for supporting microcosm!</p>
3131+ <p>A few things to keep in mind:</p>
3232+ <ol>
3333+ <li>This is a demo, not a polished product</li>
3434+ <li>It has a lot of moving pieces, so things not always work</li>
3535+ <li>Many features can easily be added! Some others can't! Make a request and let's see :)</li>
3636+ <li>It's not a long-term committed part of microcosm <em>(yet)</em></li>
3737+ </ol>
3838+ <p>Sadly, it doesn't really work on mobile. On iOS you can hit "share" and "add to home screen" to get things eventually mostly set up, but push delivery will stop after a few minutes. Android people might have better luck?</p>
3939+ <h3>Hello hello</h3>
4040+ <p>With that out of the way, let's cover some basics.</p>
4141+ <p>
4242+ To see a test notification, <button onClick={localTest}>click on this</button>. This is a local-only test.
4343+ </p>
4444+ <p>
4545+ <button
4646+ disabled={pushStatus === 'pending'}
4747+ onClick={pushTest}
4848+ >
4949+ Click here {pushCount > 0 && <>({pushCount})</>}
5050+ </button>
5151+ {' '}
5252+ to see another. This one goes over Web Push.
5353+ </p>
5454+ {pushStatus === 'failed' && <p>uh oh, something went wrong requesting a web push</p>}
5555+ </div>
5656+ );
5757+}