app

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

status-copy.ts (3781B)


      1 // Presentation facts supplied by an admitted controller, not domain receipts.
      2 export type OperationFact =
      3   | 'saved'
      4   | 'save-failed'
      5   | 'unsaved'
      6   | 'encrypted-saved'
      7   | 'preparing'
      8   | 'sending'
      9   | 'partial'
     10   | 'extension-pending'
     11   | 'needs-action'
     12   | 'stopped'
     13   | 'local-read'
     14   | 'unknown';
     15 export type StatusCopy = Readonly<{
     16   tone: 'info' | 'warning' | 'error';
     17   text: string;
     18 }>;
     19 export type TargetReceipt = Readonly<{
     20   eventId: string;
     21   destination: string;
     22   role: 'public' | 'recipient' | 'archive';
     23   outcome: 'pending' | 'accepted' | 'refused' | 'timed-out' | 'unknown';
     24   readback: 'confirmed' | 'not-observed' | 'unknown';
     25 }>;
     26 export function statusCopy(fact: OperationFact): StatusCopy {
     27   switch (fact) {
     28     case 'saved':
     29       return { tone: 'info', text: 'Saved in this browser.' };
     30     case 'save-failed':
     31       return {
     32         tone: 'error',
     33         text: 'Your latest changes were not saved. Keep this page open and try again.'
     34       };
     35     case 'unsaved':
     36       return {
     37         tone: 'warning',
     38         text: 'Not yet saved. Unsent text is lost when this page closes.'
     39       };
     40     case 'encrypted-saved':
     41       return { tone: 'info', text: 'Saved encrypted in this browser.' };
     42     case 'preparing':
     43       return { tone: 'info', text: 'Preparing encryption.' };
     44     case 'sending':
     45       return { tone: 'info', text: 'Sending.' };
     46     case 'partial':
     47       return {
     48         tone: 'warning',
     49         text: 'Delivery is partial. Check the individual target outcomes.'
     50       };
     51     case 'extension-pending':
     52       return {
     53         tone: 'info',
     54         text: 'Waiting for your extension. Another approval may be needed.'
     55       };
     56     case 'needs-action':
     57       return {
     58         tone: 'warning',
     59         text: 'Needs action. Keep the original operation for recovery.'
     60       };
     61     case 'stopped':
     62       return {
     63         tone: 'warning',
     64         text: 'Stopped scheduling further work. Accepted or uncertain effects are not reversed.'
     65       };
     66     case 'local-read':
     67       return {
     68         tone: 'info',
     69         text: 'Marked read in this browser only. The sender is not notified.'
     70       };
     71     default:
     72       return {
     73         tone: 'warning',
     74         text: 'The outcome is unknown. Keep the original operation for reconciliation.'
     75       };
     76   }
     77 }
     78 export function receiptCopy(
     79   receipt: TargetReceipt
     80 ): StatusCopy & Readonly<{ readback: string }> {
     81   const subject =
     82     receipt.role === 'recipient'
     83       ? "The recipient's inbox relay"
     84       : receipt.role === 'archive'
     85         ? 'The sender archive relay'
     86         : receipt.role === 'public'
     87           ? 'The public listing relay'
     88           : undefined;
     89   let text = 'The target outcome is unknown.';
     90   let tone: StatusCopy['tone'] = 'warning';
     91   if (subject)
     92     switch (receipt.outcome) {
     93       case 'accepted':
     94         text = subject + ' accepted the event.';
     95         tone = 'info';
     96         break;
     97       case 'refused':
     98         text = subject + ' refused the event. Needs action.';
     99         tone = 'error';
    100         break;
    101       case 'timed-out':
    102         text =
    103           subject +
    104           ' did not respond before the deadline. Acceptance is unknown.';
    105         break;
    106       case 'pending':
    107         text = subject + ' outcome is pending.';
    108         break;
    109       default:
    110         text =
    111           receipt.role === 'recipient'
    112             ? "We could not confirm whether the recipient's inbox accepted this message."
    113             : subject + ' acceptance is unknown.';
    114     }
    115   const readback =
    116     receipt.readback === 'confirmed'
    117       ? 'Exact read-back is confirmed for this event and target.'
    118       : receipt.readback === 'not-observed'
    119         ? 'Exact read-back was not observed for this event and target.'
    120         : 'Exact read-back is unknown.';
    121   return { tone, text, readback };
    122 }