app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

inbox-setup-view.ts (1738B)


      1 import { mount, unmount } from 'svelte';
      2 import Panel from './inbox-setup-panel.svelte';
      3 import { makeSetupFixture, fixturePolicy, inbox } from './inbox-setup.ts';
      4 import {
      5   makePublisherFixture,
      6   closePublicPool,
      7   getPublicPool
      8 } from './inbox-preference-publisher.ts';
      9 import {
     10   createInboxSetupView,
     11   closeInboxSetupView,
     12   inboxSetupViewSnapshot
     13 } from '../../../src/lib/messaging/inbox-setup-view.ts';
     14 export { inboxSetupViewSnapshot };
     15 export { makeSetupFixture };
     16 export async function renderFixture(
     17   mode: 'incomplete' | 'compatible' | 'review' | 'publish' = 'review'
     18 ) {
     19   const f =
     20     mode === 'publish'
     21       ? await makePublisherFixture()
     22       : await makeSetupFixture(
     23           mode === 'compatible' ? [['relay', inbox]] : undefined
     24         );
     25   const controller = createInboxSetupView({
     26     identity: f.identity,
     27     policy: 'policy' in f ? f.policy : fixturePolicy(),
     28     lookup: () => {
     29       if ('own' in f)
     30         return Promise.resolve(
     31           f.resolve(undefined, mode !== 'incomplete').resolver
     32         );
     33       return Promise.resolve(f.resolve());
     34     },
     35     now: () => 101
     36   });
     37   if (!controller) throw new Error('genuine setup controller unavailable');
     38   const target = document.createElement('div');
     39   document.body.append(target);
     40   const mounted = mount(Panel, { target, props: { controller } });
     41   return {
     42     controller,
     43     beforeSign(callback: () => Promise<void>) {
     44       if ('beforeSign' in f) f.beforeSign(callback);
     45     },
     46     async close() {
     47       closeInboxSetupView(controller);
     48       await unmount(mounted);
     49       f.close();
     50       if ('policy' in f) {
     51         const pool = getPublicPool(f.policy);
     52         if (pool) closePublicPool(pool);
     53       }
     54       target.remove();
     55     }
     56   };
     57 }