@gphone/sdk
    Preparing search index...

    Function useAppAction

    • OS Service Hook for running one user-initiated action.

      Every app does the same four things around a write: mark itself busy so the button cannot be pressed twice, await it, say whether it worked, and clear the busy flag whatever happened. Admin was the only place that did all four. Contacts wrote the shape out four times and the fourth — deleting a contact — silently dropped both toasts, so a delete the server refused looked exactly like one that succeeded.

      busy is a store rather than component state so that one action can disable a whole form, and so this can live in a plain module.

      run resolves to whether the work succeeded, which is what callers actually branch on — close the editor, clear the draft — instead of putting that follow-up inside the try where a failure would skip it by accident.

      const { busy, run } = useAppAction('contacts');
      
      const save = async () => {
        if (await run(() => contacts.update(draft), { success: 'Contact updated' })) {
          isEditing = false;
        }
      };
      

      Parameters

      • OptionalappId: string

      Returns {
          busy: Writable<boolean>;
          notify: (
              n: { message: string; title?: string; type: "error" | "success" },
          ) => string;
          run: (work: () => unknown, options?: AppActionOptions) => Promise<boolean>;
      }

      • busy: Writable<boolean>
      • notify: (n: { message: string; title?: string; type: "error" | "success" }) => string

        The toast half of run, for a caller whose work cannot cross a process boundary (GPHONE-16 step 4).

      • run: (work: () => unknown, options?: AppActionOptions) => Promise<boolean>